Guest User

Untitled

a guest
Aug 14th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. How to use NSubstitute to mock a lazy class
  2. //Assert
  3. Lazy<INotificationService> notificationService = Substitute.For<Lazy<INotificationService>>();
  4. Service target = new Service(repository, notificationService);
  5.  
  6. //Act
  7. target.SendNotify("Message");
  8.  
  9. //Arrange
  10. notificationService.Received().Value.sendNotification(null, null, null, null);
  11.  
  12. var notificationService = Substitute.For<INotificationService>();
  13. var target = new Service(repository, new Lazy<INotificationService>(() => notificationService));
  14.  
  15. target.SendNotify("Message");
  16.  
  17. notificationService.ReceivedWithAnyArgs().sendNotification(null, null, null, null);
Add Comment
Please, Sign In to add comment