public async void SaveTest() { // Arrange var mockLogManager = new Mock <ILogManager>(); var mockCertificateOfInsuranceValidator = new Mock <ICertificateOfInsuranceValidator>(); var mockCertificateOfInsuranceRepository = new Mock <ICertificateOfInsuranceRepository>(); var mockCertificateOfInsurance = new Mock <ICertificateOfInsurance>(); var mockFileUploadApplicationService = new Mock <IFileUploadApplicationService>(); // Setup mock methods/properties mockCertificateOfInsuranceRepository.Setup(x => x.SaveAsync(It.IsNotNull <ICertificateOfInsurance>())) .Returns(Task.FromResult(new SaveResponse <ICertificateOfInsurance> { Message = "Successful." })); // Act var sut = new CertificateOfInsuranceApplicationService( mockLogManager.Object, mockCertificateOfInsuranceRepository.Object, mockCertificateOfInsuranceValidator.Object, mockFileUploadApplicationService.Object); var response = await sut.SaveAsync(mockCertificateOfInsurance.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. mockCertificateOfInsuranceRepository.Verify(x => x.SaveAsync(It.IsAny <ICertificateOfInsurance>())); }
public async void SaveErrorTest() { // Arrange var mockLogManager = new Mock <ILogManager>(); var mockCertificateOfInsuranceValidator = new Mock <ICertificateOfInsuranceValidator>(); var mockCertificateOfInsuranceRepository = new Mock <ICertificateOfInsuranceRepository>(); var mockCertificateOfInsurance = new Mock <ICertificateOfInsurance>(); var mockFileUploadApplicationService = new Mock <IFileUploadApplicationService>(); // Setup mock methods/properties mockCertificateOfInsuranceRepository.Setup(x => x.SaveAsync(It.IsNotNull <ICertificateOfInsurance>())) .Throws(new Exception()); // Act var sut = new CertificateOfInsuranceApplicationService( mockLogManager.Object, mockCertificateOfInsuranceRepository.Object, mockCertificateOfInsuranceValidator.Object, mockFileUploadApplicationService.Object); var response = await sut.SaveAsync(mockCertificateOfInsurance.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. mockCertificateOfInsuranceRepository.Verify(x => x.SaveAsync(It.IsAny <ICertificateOfInsurance>())); // Verify the application service is logging the error. mockLogManager.Verify(x => x.LogError(It.IsAny <Exception>(), It.IsAny <string>())); }