public void UpdateCreditNotePaymentStatus_ShouldBeThrowsAnException_WhenBillingSystemIdIsNotValid() { var updateCreditNotePaymentStatusRequest = new UpdateCreditNotePaymentStatusRequest { BillingSystemId = 0, Type = 2, CreditNoteId = 1 }; var loggerMock = new Mock <ILogger <BillingController> >(); var billingServiceMock = new Mock <IBillingService>(); billingServiceMock.Setup(x => x.UpdateCreditNotePaymentStatus(updateCreditNotePaymentStatusRequest)).ThrowsAsync(new ArgumentException("Value can not be null", "BillingSystemId")); var controller = new BillingController(loggerMock.Object, billingServiceMock.Object); // Act var ex = Assert.ThrowsAsync <ArgumentException>(() => controller.UpdateCreditNotePaymentStatus(updateCreditNotePaymentStatusRequest)); // Assert Assert.Equal("Value can not be null (Parameter 'BillingSystemId')", ex.Result.Message); }
public async Task UpdateCreditNotePaymentStatus_ShouldBeHttpStatusCodeOk_WhenRequestIsValid() { var updateCreditNotePaymentStatusRequest = new UpdateCreditNotePaymentStatusRequest { BillingSystemId = 2, Type = 2, CreditNoteId = 1 }; var loggerMock = new Mock <ILogger <BillingController> >(); var billingServiceMock = new Mock <IBillingService>(); billingServiceMock.Setup(x => x.UpdateCreditNotePaymentStatus(updateCreditNotePaymentStatusRequest)).Returns(Task.CompletedTask); var controller = new BillingController(loggerMock.Object, billingServiceMock.Object); // Act var response = await controller.UpdateCreditNotePaymentStatus(updateCreditNotePaymentStatusRequest); // Assert Assert.IsType <OkObjectResult>(response); Assert.Equal("Successfully", ((ObjectResult)response).Value); }
public async Task UpdateCreditNotePaymentStatus(UpdateCreditNotePaymentStatusRequest updateCreditNotePaymentStatusRequest) { try { var sapSystem = SapSystemHelper.GetSapSystemByBillingSystem(updateCreditNotePaymentStatusRequest.BillingSystemId); var validator = GetValidator(sapSystem); validator.ValidateUpdateCreditNotePaymentStatusRequest(updateCreditNotePaymentStatusRequest); var creditNoteRequest = GetMapper(sapSystem).MapUpdateCreditNotePaymentStatusRequestToCreditNoteRequest(updateCreditNotePaymentStatusRequest); _queuingService.AddToTaskQueue( new SapTask { CreditNoteRequest = creditNoteRequest, TaskType = SapTaskEnum.UpdateCreditNote } ); } catch (Exception e) { _logger.LogError($"Failed at update credit note request for invoice: {updateCreditNotePaymentStatusRequest.CreditNoteId}.", e); await _slackService.SendNotification($"Failed at update credit note request for invoice: {updateCreditNotePaymentStatusRequest.CreditNoteId}. Error: {e.Message}"); } }
public async Task BillingService_ShouldBeNotAddOneTaskInQueue_WhenUpdateCreditNotePaymentStatusRequestHasInvalidBillingSystemId() { 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 slackServiceMock = new Mock <ISlackService>(); slackServiceMock.Setup(x => x.SendNotification(It.IsAny <string>())).Returns(Task.CompletedTask); var queuingServiceMock = new Mock <IQueuingService>(); var billingService = new BillingService(queuingServiceMock.Object, Mock.Of <IDateTimeProvider>(), Mock.Of <ILogger <BillingService> >(), slackServiceMock.Object, billingMappers, null, Mock.Of <ISapServiceSettingsFactory>()); var updateCreditNotePaymentStatusRequest = new UpdateCreditNotePaymentStatusRequest { BillingSystemId = 0, Type = 2, CreditNoteId = 1 }; await billingService.UpdateCreditNotePaymentStatus(updateCreditNotePaymentStatusRequest); queuingServiceMock.Verify(x => x.AddToTaskQueue(It.IsAny <SapTask>()), Times.Never); slackServiceMock.Verify(x => x.SendNotification(It.IsAny <string>()), Times.Once); }
public async Task BillingService_ShouldBeAddOneTaskInQueue_WhenUpdateCreditNotePaymentStatusRequestHasValidElement() { var billingValidations = new List <IBillingValidation> { new BillingForArValidation(Mock.Of <ILogger <BillingForArValidation> >()), new BillingForUsValidation(Mock.Of <ILogger <BillingForUsValidation> >()) }; 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 queuingServiceMock = new Mock <IQueuingService>(); var billingService = new BillingService(queuingServiceMock.Object, Mock.Of <IDateTimeProvider>(), Mock.Of <ILogger <BillingService> >(), Mock.Of <ISlackService>(), billingMappers, billingValidations, Mock.Of <ISapServiceSettingsFactory>()); var updateCreditNotePaymentStatusRequest = new UpdateCreditNotePaymentStatusRequest { BillingSystemId = 2, Type = 2, CreditNoteId = 1 }; await billingService.UpdateCreditNotePaymentStatus(updateCreditNotePaymentStatusRequest); queuingServiceMock.Verify(x => x.AddToTaskQueue(It.IsAny <SapTask>()), Times.Once); }
public Task UpdateCreditNotePaymentStatus(UpdateCreditNotePaymentStatusRequest updatePaymentStatusRequest) { return(Task.CompletedTask); }
public CreditNoteRequest MapUpdateCreditNotePaymentStatusRequestToCreditNoteRequest(UpdateCreditNotePaymentStatusRequest updateCreditNotePaymentStatusRequest) { return(new CreditNoteRequest { BillingSystemId = updateCreditNotePaymentStatusRequest.BillingSystemId, CreditNoteId = updateCreditNotePaymentStatusRequest.CreditNoteId, CardErrorCode = updateCreditNotePaymentStatusRequest.CardErrorCode, CardErrorDetail = updateCreditNotePaymentStatusRequest.CardErrorDetail, TransactionApproved = updateCreditNotePaymentStatusRequest.TransactionApproved, TransferReference = updateCreditNotePaymentStatusRequest.TransferReference, Type = updateCreditNotePaymentStatusRequest.Type }); }