public async void SaveTest() { // Arrange var mockLogManager = new Mock <ILogManager>(); var mockAuditTaskRepository = new Mock <IAuditTaskRepository>(); var mockAuditTask = new Mock <IAuditTask>(); // Setup mock methods/properties mockAuditTaskRepository.Setup(x => x.SaveAsync(It.IsNotNull <IAuditTask>())) .Returns(Task.FromResult(new SaveResponse <IAuditTask> { Message = "Successful." })); // Act var sut = new AuditTaskApplicationService( mockLogManager.Object, mockAuditTaskRepository.Object); var response = await sut.SaveAsync(mockAuditTask.Object); // Assert response.IsSuccessful.Should().BeTrue(); response.Errors.Count.Should().Be(0); response.Message.Should().NotBeNullOrEmpty(); // Verify the application service is calling the correct repository method. mockAuditTaskRepository.Verify(x => x.SaveAsync(It.IsAny <IAuditTask>())); }
public async void SaveErrorTest() { // Arrange var mockLogManager = new Mock <ILogManager>(); var mockAuditTaskRepository = new Mock <IAuditTaskRepository>(); var mockAuditTask = new Mock <IAuditTask>(); // Setup mock methods/properties mockAuditTaskRepository.Setup(x => x.SaveAsync(It.IsNotNull <IAuditTask>())) .Throws(new Exception()); // Act var sut = new AuditTaskApplicationService( mockLogManager.Object, mockAuditTaskRepository.Object); var response = await sut.SaveAsync(mockAuditTask.Object); // Assert response.IsSuccessful.Should().BeFalse(); response.Errors.Count.Should().BeGreaterThan(0); response.Message.Should().NotBeNullOrEmpty(); // Verify the application service is calling the correct repository method. mockAuditTaskRepository.Verify(x => x.SaveAsync(It.IsAny <IAuditTask>())); // Verify the application service is logging the error. mockLogManager.Verify(x => x.LogError(It.IsAny <Exception>(), It.IsAny <string>())); }