public async void GetAllSalesTest() { // Arrange var mockLogManager = new Mock <ILogManager>(); var mockSalesValidator = new Mock <ISalesValidator>(); var mockSalesRepository = new Mock <ISalesRepository>(); var mockFileUploader = new Mock <IFileUploadApplicationService>(); // Setup mock methods/properties mockSalesRepository.Setup(x => x.GetAllSalesAsync(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <SalesPeriodType>())) .Returns(Task.FromResult(new GetResponse <IReadOnlyList <ISales> > { Message = "Successful." })); // Act var sut = new SalesApplicationService( mockLogManager.Object, mockSalesRepository.Object, mockSalesValidator.Object, mockFileUploader.Object); var response = await sut.GetAllSalesAsync(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <SalesPeriodType>()); // 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. mockSalesRepository.Verify(x => x.GetAllSalesAsync(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <SalesPeriodType>())); }
public async void GetAllSalesVerificationErrorTest() { // Arrange var mockLogManager = new Mock <ILogManager>(); var mockSalesValidator = new Mock <ISalesValidator>(); var mockSalesRepository = new Mock <ISalesRepository>(); var mockFileUploader = new Mock <IFileUploadApplicationService>(); // Setup mock methods/properties mockSalesRepository.Setup(x => x.GetAllSalesVerificationAsync(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <SalesPeriodType>())) .Throws(new Exception()); // Act var sut = new SalesApplicationService( mockLogManager.Object, mockSalesRepository.Object, mockSalesValidator.Object, mockFileUploader.Object); var response = await sut.GetAllSalesAsync(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <SalesPeriodType>()); // 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. mockSalesRepository.Verify(x => x.GetAllSalesAsync(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <SalesPeriodType>())); // Verify the application service is logging the error. mockLogManager.Verify(x => x.LogError(It.IsAny <Exception>(), It.IsAny <string>())); }