0
私はイベントを検証することはできないのですがNServiceBus.Testing(NServiceBus、V6のベータ版)を使用して公開検証NServiceBusイベントのプロパティ(インターフェイスを使用)
私のAPIコントローラで私はで
await _messageSession.Publish<IStrategyCreated>(stgy =>
{
stgy.StrategyId = strategyToAdd.Id;
stgy.InvestmentObjective = strategyToAdd.InvestmentObjective;
stgy.PrincipalInvestmentStrategy = strategyToAdd.PrincipalInvestmentStrategy;
stgy.PortfolioConsultant = strategyToAdd.PortfolioConsultant;
stgy.StrategyName = strategyToAdd.Name;
stgy.StrategyCode = strategyToAdd.Code;
});
イベントを公開私のテスト私が持っている:
Assert.That(messageSession.PublishedMessages.Length, Is.EqualTo(1), "Messages published");
Assert.IsInstanceOf<IStrategyCreated>(messageSession.PublishedMessages[0],"Message published was of type IStrategyCreated");
2行目は失敗し、メッセージタイプがIStrategyCreated_impl
エラーですので:
Message published was of type IStrategyCreated
Expected: instance of <Strategy.Contracts.Events.IStrategyCreated>
But was: <NServiceBus.Testing.PublishedMessage`1[System.Object]>
完全なテスト方法:
public async Task TestCreateStrategy()
{
var messageSession = new TestableMessageSession();
var dbContent = _container.Resolve<IStrategyDbContext>();
var apiContext = new StrategyController(messageSession, dbContent);
var result =
await apiContext.Create(new StrategyModel {Code = "NEW"}) as
OkNegotiatedContentResult<StrategyModel>;
Assert.That(messageSession.PublishedMessages.Length, Is.EqualTo(1), "Messages published");
Assert.IsInstanceOf<IStrategyCreated>(messageSession.PublishedMessages[0],"Message published was of type IStrategyCreated");
var stgyCreated =(IStrategyCreated) messageSession.PublishedMessages[0];
Assert.That(result, Is.Not.Null, "Result Is Null");
Assert.That(stgyCreated.StrategyCode, Is.EqualTo("NEW"));
Assert.That(result?.Content.Code, Is.EqualTo("NEW"), "Returning Strategy");
Assert.That(dbContent.Strategies.Count(), Is.EqualTo(1), "Exactly 1 item was added to strategy list");
}