8
//Assert
Lazy<INotificationService> notificationService = Substitute.For<Lazy<INotificationService>>();
Service target = new Service(repository, notificationService);
//Act
target.SendNotify("Message");
//Arrange
notificationService.Received().Value.sendNotification(null, null, null, null);
上記のコードは例外をスローします。NSubstituteを使用して遅延クラスをモックする方法
いい加減に初期化タイプは、私が使用することをお勧めします、@ sanosdoleさんのコメントを1として、私はC#4.0とを使用しています公共、パラメータなしのコンストラクタ
NSubstitute 1.2.1
本当にLazyを代用したいのですか?私はちょうどLazy <>がValue Factoryのコンストラクタを使用し、Substitute.For ()をValue Factoryとして使用していると仮定します。 –
sanosdole
+1 to @ sanosdoleのコメント。その答えをコミュニティのwikiとして投稿しました。 –