public async void SaveAllTest() { // Arrange var mockLogManager = new Mock <ILogManager>(); var mockAuditStatusRepository = new Mock <IAuditStatusRepository>(); var mockAuditStatuss = new List <IAuditStatus> { new Mock <IAuditStatus>().Object }; // Setup mock methods/properties mockAuditStatusRepository.Setup(x => x.SaveAllAsync(It.IsAny <IReadOnlyList <IAuditStatus> >())) .Returns(Task.FromResult(new SaveResponse <IReadOnlyList <IAuditStatus> > { Message = "Successful." })); // Act var sut = new AuditStatusApplicationService( mockLogManager.Object, mockAuditStatusRepository.Object); var response = await sut.SaveAllAsync(mockAuditStatuss); // 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. mockAuditStatusRepository.Verify(x => x.SaveAllAsync(It.IsAny <IReadOnlyList <IAuditStatus> >())); }
public async void SaveAllErrorTest() { // Arrange var mockLogManager = new Mock <ILogManager>(); var mockAuditStatusRepository = new Mock <IAuditStatusRepository>(); var mockAuditStatuss = new List <IAuditStatus> { new Mock <IAuditStatus>().Object }; // Setup mock methods/properties mockAuditStatusRepository.Setup(x => x.SaveAllAsync(It.IsAny <IReadOnlyList <IAuditStatus> >())) .Throws(new Exception()); // Act var sut = new AuditStatusApplicationService( mockLogManager.Object, mockAuditStatusRepository.Object); var response = await sut.SaveAllAsync(mockAuditStatuss); // 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. mockAuditStatusRepository.Verify(x => x.SaveAllAsync(It.IsAny <IReadOnlyList <IAuditStatus> >())); // Verify the application service is logging the error. mockLogManager.Verify(x => x.LogError(It.IsAny <Exception>(), It.IsAny <string>())); }