2
NSubsituteのReceived()
メソッドに問題があります。NS substituteとAutoFixtureの問題が受信しました
私のテストクラス:
private readonly IFixture _fixture;
public NotificationsCenterTests()
{
_fixture = new Fixture();
_fixture.Behaviors.Add(new OmitOnRecursionBehavior());
_fixture.Customize(new AutoNSubstituteCustomization());
}
この方法は、良い作品:
[Theory, AutoNSubstituteData]
public void Send_NotificationIsNotNull_NotificationShouldBeSendAndSaved(
IDocumentDbRepository<NotificationDocument> repository,
Notification notification
)
{
// Arrange
var sender = Substitute.For<INotificationSender>();
var notificationsCenter = new NotificationsCenter(
sender, repository);
// Act
Func<Task> action = async() => await notificationsCenter.SendAsync(notification);
// Assert
action.Invoke();
sender.Received(1).Send(Arg.Any<Notification>());
}
そして、これはエラーを送信します。
[Theory, AutoNSubstituteData]
public void Send_NotificationIsNotNull_NotificationShouldBeSendAndSaved2(
INotificationSender sender,
IDocumentDbRepository<NotificationDocument> repository,
NotificationsCenter notificationsCenter,
Notification notification
)
{
// Act
Func<Task> action = async() => await notificationsCenter.SendAsync(notification);
// Assert
action.Invoke();
sender.Received(1).Send(Arg.Any<Notification>());
}
は、それは私のautonsubsisute属性:
internal class AutoNSubstituteDataAttribute : AutoDataAttribute
{
public AutoNSubstituteDataAttribute()
: base(new Fixture()
.Customize(new AutoNSubstituteCustomization()))
{
}
}
そして、方法2に誤りがある:
NSubstitute.Exceptions.ReceivedCallsException : Expected to receive exactly 1 call matching:
Send(any Notification)
Actually received no matching calls.
何が起こっていますか?私はTDDでいくつかのコードをしたいが、私はこの小さな問題で止まった。そして、私は2番目のコードに何が間違っているのか分からない。
あなたは考えがありますか?第2の例で