public async Task BillingService_ShouldBeReturnInvoice_WhenTheRequestIsValid() { var invoiceId = 1; var billingSystemId = 2; var timeZoneConfigurations = new TimeZoneConfigurations { InvoicesTimeZone = TimeZoneHelper.GetTimeZoneByOperativeSystem("Argentina Standard Time") }; var billingMappers = new List <IBillingMapper> { new BillingForArMapper(Mock.Of <ISapBillingItemsService>(), Mock.Of <IDateTimeProvider>(), timeZoneConfigurations), new BillingForUsMapper(Mock.Of <ISapBillingItemsService>(), Mock.Of <IDateTimeProvider>(), timeZoneConfigurations) }; var sapTaskHandlerMock = new Mock <ISapTaskHandler>(); sapTaskHandlerMock.Setup(x => x.TryGetInvoiceByInvoiceIdAndOrigin(It.IsAny <int>(), It.IsAny <string>())) .ReturnsAsync(new SapSaleOrderInvoiceResponse { BillingSystemId = billingSystemId, CardCode = "CD001", DocEntry = 1 }); var sapServiceSettingsFactoryMock = new Mock <ISapServiceSettingsFactory>(); sapServiceSettingsFactoryMock.Setup(x => x.CreateHandler("US")).Returns(sapTaskHandlerMock.Object); var billingService = new BillingService(Mock.Of <IQueuingService>(), Mock.Of <IDateTimeProvider>(), Mock.Of <ILogger <BillingService> >(), Mock.Of <ISlackService>(), billingMappers, null, sapServiceSettingsFactoryMock.Object); var response = await billingService.GetInvoiceByDopplerInvoiceIdAndOrigin(billingSystemId, invoiceId, "doppler"); Assert.NotNull(response); Assert.Equal(billingSystemId, response.BillingSystemId); Assert.Equal("CD001", response.CardCode); Assert.Equal(1, response.DocEntry); sapTaskHandlerMock.Verify(x => x.TryGetInvoiceByInvoiceIdAndOrigin(invoiceId, "doppler"), Times.Once); }
public async Task BillingService_ShouldBeReturnNull_WhenInvoiceNotExistInSap() { var invoiceId = 1; var billingSystemId = 2; var timeZoneConfigurations = new TimeZoneConfigurations { InvoicesTimeZone = TimeZoneHelper.GetTimeZoneByOperativeSystem("Argentina Standard Time") }; var billingMappers = new List <IBillingMapper> { new BillingForArMapper(Mock.Of <ISapBillingItemsService>(), Mock.Of <IDateTimeProvider>(), timeZoneConfigurations), new BillingForUsMapper(Mock.Of <ISapBillingItemsService>(), Mock.Of <IDateTimeProvider>(), timeZoneConfigurations) }; var sapTaskHandlerMock = new Mock <ISapTaskHandler>(); sapTaskHandlerMock.Setup(x => x.TryGetInvoiceByInvoiceIdAndOrigin(invoiceId, "doppler")) .ReturnsAsync((SapSaleOrderInvoiceResponse)null); var sapServiceSettingsFactoryMock = new Mock <ISapServiceSettingsFactory>(); sapServiceSettingsFactoryMock.Setup(x => x.CreateHandler("US")).Returns(sapTaskHandlerMock.Object); var billingService = new BillingService(Mock.Of <IQueuingService>(), Mock.Of <IDateTimeProvider>(), Mock.Of <ILogger <BillingService> >(), Mock.Of <ISlackService>(), billingMappers, null, sapServiceSettingsFactoryMock.Object); var response = await billingService.GetInvoiceByDopplerInvoiceIdAndOrigin(billingSystemId, invoiceId, "doppler"); Assert.Null(response); sapTaskHandlerMock.Verify(x => x.TryGetInvoiceByInvoiceIdAndOrigin(invoiceId, "doppler"), Times.Once); }