public void Submit_ShouldCallService_And_ReturnCorrectResult()
        {
            // Arrange
            var product = new ConfidentialInvoiceDiscount
            {
                TotalLedgerNetworth = 10m,
                AdvancePercentage   = 5.99m,
            };
            var application = new SellerApplication
            {
                Product     = product,
                CompanyData = new SellerCompanyData(),
            };
            var serviceResult = Mock.Of <IApplicationResult>(m => m.Success == true && m.ApplicationId == 2);

            var client = new ConfidentialInvoiceServiceClient(_confidentialInvoiceServiceMock.Object, _companyDataMapperMock.Object);

            _confidentialInvoiceServiceMock.Setup(m => m.SubmitApplicationFor(It.IsAny <CompanyDataRequest>(),
                                                                              product.TotalLedgerNetworth, product.AdvancePercentage, product.VatRate)).Returns(serviceResult);

            // Act
            var result = client.SubmitApplication(application);

            // Assert
            Assert.Equal(serviceResult.ApplicationId, result);
        }
Пример #2
0
        public void Can_Submit_Application_For_Product_ConfidentialInvoiceDiscount()
        {
            // Arrange

            var confidentialInvoiceDiscount = new ConfidentialInvoiceDiscount
            {
                Id = 1,
                TotalLedgerNetworth = 200,
                AdvancePercentage   = 80,
                VatRate             = 0.20M
            };

            var sellerApplication = new SellerApplication
            {
                Product     = confidentialInvoiceDiscount,
                CompanyData = GetCompanyData(),
            };

            var mockConfidentialInvoiceService = new Mock <IConfidentialInvoiceService>();

            mockConfidentialInvoiceService.Setup(cis => cis.SubmitApplicationFor(It.IsAny <CompanyDataRequest>(), 200, 80, 0.20M)).Returns(GetSuccessfulApplicationResult());

            var sut = new ProductApplicationService(
                new Mock <ISelectInvoiceService>().Object,
                mockConfidentialInvoiceService.Object,
                new Mock <IBusinessLoansService>().Object
                );

            // Act
            var applicationResult = sut.SubmitApplicationFor(sellerApplication);

            // Assert
            Assert.Equal(1, applicationResult);
            mockConfidentialInvoiceService.VerifyAll();
        }
        public void SubmitApplicationFor_ConfidentialInvoiceDiscount_CallsConfidentialInvoiceService()
        {
            // **Arrange**
            ConfidentialInvoiceDiscount cidProduct  = _fixture.Build <ConfidentialInvoiceDiscount>().Create();
            SellerCompanyData           companyData = _fixture.Build <SellerCompanyData>().Create();
            SellerApplication <ConfidentialInvoiceDiscount> application = _fixture.Build <SellerApplication <ConfidentialInvoiceDiscount> >()
                                                                          .With(a => a.Product, cidProduct)
                                                                          .With(a => a.CompanyData, companyData)
                                                                          .Create();

            cid.SubmitApplicationFor(
                Arg.Is <CompanyDataRequest>(x => x.DirectorName == companyData.DirectorName &&
                                            x.CompanyNumber == companyData.Number &&
                                            x.CompanyName == companyData.Name &&
                                            x.CompanyFounded == companyData.Founded),
                cidProduct.TotalLedgerNetworth,
                cidProduct.AdvancePercentage,
                cidProduct.VatRate)
            .Returns(new TestApplicationResult(10, true, new List <string>()));

            // **Act**
            int result = _service.SubmitApplicationFor(application);

            // **Assert**
            cid.Received(1).SubmitApplicationFor(Arg.Is <CompanyDataRequest>(x => x.DirectorName == companyData.DirectorName &&
                                                                             x.CompanyNumber == companyData.Number &&
                                                                             x.CompanyName == companyData.Name &&
                                                                             x.CompanyFounded == companyData.Founded), cidProduct.TotalLedgerNetworth, cidProduct.AdvancePercentage, cidProduct.VatRate);
            Assert.Equal(10, result);
        }
        private void SetupMockConfidentialInvoiceDiscount(ISellerApplication application, IApplicationResult result)
        {
            ConfidentialInvoiceDiscount product = (ConfidentialInvoiceDiscount)application.Product;

            _mockConfidentialInvoiceService
            .Setup(p => p.SubmitApplicationFor(It.IsAny <CompanyDataRequest>(), product.TotalLedgerNetworth, product.AdvancePercentage, product.VatRate))
            .Returns(result)
            .Verifiable();
        }
        public void WhenProductIsConfidentialInvoiceDiscountCanHandleSubmitApplication()
        {
            //Arrange

            IProduct product = new ConfidentialInvoiceDiscount {
                Id = 2, AdvancePercentage = 3, TotalLedgerNetworth = 500, VatRate = 0.3M
            };

            ISellerCompanyData companyData1 = new SellerCompanyData {
                DirectorName = "Me", Founded = DateTime.Now, Name = "My Company", Number = 12
            };
            ISellerCompanyData companyData2 = new SellerCompanyData {
                DirectorName = "Us", Founded = DateTime.Now, Name = "Our Company", Number = 10
            };

            ISellerApplication sellerApp1 = new SellerApplication {
                Product = product, CompanyData = companyData1
            };
            ISellerApplication sellerApp2 = new SellerApplication {
                Product = product, CompanyData = companyData2
            };

            //-------------------------------------------------------------------------------------------------------

            Mock <ISelectInvoiceService>       mockSelectInvoiceService       = new Mock <ISelectInvoiceService>(MockBehavior.Strict);
            Mock <IConfidentialInvoiceService> mockConfidentialInvoiceService = new Mock <IConfidentialInvoiceService>(MockBehavior.Strict);
            Mock <IBusinessLoansService>       mockBusinessLoansService       = new Mock <IBusinessLoansService>(MockBehavior.Strict);

            Mock <IApplicationResult> appResultSuccess = new Mock <IApplicationResult>();
            Mock <IApplicationResult> appResultFail    = new Mock <IApplicationResult>();

            appResultSuccess.SetupGet(x => x.ApplicationId).Returns(3);
            appResultSuccess.Setup(x => x.Success).Returns(true);

            appResultFail.Setup(x => x.Success).Returns(false);

            mockConfidentialInvoiceService.Setup(m => m.SubmitApplicationFor(It.Is <CompanyDataRequest>(r => r.CompanyName == "My Company"), It.IsAny <decimal>(), It.IsAny <decimal>(), It.IsAny <decimal>())).Returns(appResultSuccess.Object);
            mockConfidentialInvoiceService.Setup(m => m.SubmitApplicationFor(It.Is <CompanyDataRequest>(r => r.CompanyName != "My Company"), It.IsAny <decimal>(), It.IsAny <decimal>(), It.IsAny <decimal>())).Returns(appResultFail.Object);

            //-------------------------------------------------------------------------------------------------------

            IProductApplicationService applicationService = new ProductApplicationService(mockSelectInvoiceService.Object, mockConfidentialInvoiceService.Object, mockBusinessLoansService.Object);

            //Act
            int result1 = applicationService.SubmitApplicationFor(sellerApp1);
            int result2 = applicationService.SubmitApplicationFor(sellerApp2);

            //Assert
            mockConfidentialInvoiceService.Verify();

            Assert.Equal(3, result1);
            Assert.Equal(-1, result2);
        }
Пример #6
0
        private int SubmitCompanyDataRequest(ISellerCompanyData application, ConfidentialInvoiceDiscount cid)
        {
            var companyDataRequest = CreateCompanyDataRequest(application);

            var result = _confidentialInvoiceWebService.SubmitApplicationFor(
                companyDataRequest, cid.TotalLedgerNetworth, cid.AdvancePercentage, cid.VatRate);

            if (!result.Success)
            {
                return(-1);
            }

            return(result.ApplicationId ?? -1);
        }
        public void SubmitApplicationFor_ConfidentialInvoiceDiscount_CallConfidentialInvoiceService_UnSuccessfully()
        {
            var cid = Substitute.For <IConfidentialInvoiceService>();

            var cidProduct  = new ConfidentialInvoiceDiscount(cid);
            var companyData = _fixture.Build <SellerCompanyData>().Create();

            var cidRequestResult = Substitute.For <IApplicationResult>();

            cidRequestResult.ApplicationId = null;
            cidRequestResult.Errors        = null;
            cidRequestResult.Success       = false;

            cid.SubmitApplicationFor(Arg.Any <CompanyDataRequest>(), cidProduct.TotalLedgerNetworth, cidProduct.AdvancePercentage, cidProduct.VatRate).Returns(cidRequestResult);

            var result = cidProduct.SubmitApplicationFor(companyData);

            cid.Received(1).SubmitApplicationFor(Arg.Any <CompanyDataRequest>(), cidProduct.TotalLedgerNetworth, cidProduct.AdvancePercentage, cidProduct.VatRate);
            Assert.Equal(-1, result);
        }
        public void CreateDiscountRequestApplication__Handle__AssertIsRedirectedToConfidentialInvoiceService()
        {
            var invoiceDiscount = new ConfidentialInvoiceDiscount()
            {
                Id = 1, AdvancePercentage = 2, TotalLedgerNetworth = 3, VatRate = 4
            };
            var application = new SellerApplication(invoiceDiscount, GetCompanyData());
            var confidentialInvoiceService = new Mock <IConfidentialInvoiceService>();

            confidentialInvoiceService.Setup(svc => svc.SubmitApplicationFor(It.IsAny <CompanyDataRequest>(), It.IsAny <decimal>(), 2, 4)).Returns(GetValidApplicationResult());

            var applicationService = applicationServiceFactory.CreateProductApplicationService(
                new Mock <IBusinessLoansService>().Object,
                confidentialInvoiceService.Object,
                new Mock <ISelectInvoiceService>().Object
                );
            var applicationResult = applicationService.SubmitApplicationFor(application);

            confidentialInvoiceService.VerifyAll();
            Assert.Equal(1, applicationResult);
        }
        public void Can_Map_To_CompanyDataRequest()
        {
            var confidentialInvoiceDiscount = new ConfidentialInvoiceDiscount
            {
                Id = 1,
                TotalLedgerNetworth = 200,
                AdvancePercentage   = 80,
                VatRate             = 0.20M
            };

            var sellerApplication = new SellerApplication
            {
                Product     = confidentialInvoiceDiscount,
                CompanyData = new SellerCompanyData
                {
                    Name         = "Company 1",
                    Number       = 1,
                    DirectorName = "Director 1",
                    Founded      = new DateTime(2020, 1, 1),
                }
            };

            var expected = new CompanyDataRequest
            {
                CompanyFounded = new DateTime(2020, 1, 1),
                CompanyNumber  = 1,
                CompanyName    = "Company 1",
                DirectorName   = "Director 1"
            };

            var sut = new SellerApplicationMapper();

            var result = sut.MapToCompanyDataRequest(sellerApplication);

            Assert.Equal(sellerApplication.CompanyData.Founded, expected.CompanyFounded);
            Assert.Equal(sellerApplication.CompanyData.Number, expected.CompanyNumber);
            Assert.Equal(sellerApplication.CompanyData.Name, expected.CompanyName);
            Assert.Equal(sellerApplication.CompanyData.DirectorName, expected.DirectorName);
        }
Пример #10
0
        public IApplicationResult SubmitApplicationFor(SellerApplication application)
        {
            if (application is null)
            {
                throw new ArgumentNullException(nameof(application));
            }

            var companyData = MapToCompanyDataRequest(application.CompanyData);

            return(application.Product switch
            {
                SelectiveInvoiceDiscount sid
                => SubmitRequest(companyData, sid),

                ConfidentialInvoiceDiscount cid
                => SubmitRequest(companyData, cid),

                BusinessLoans loans
                => SubmitRequest(companyData, loans),

                _ => throw new InvalidOperationException(
                    $"Unknown/unsupported/null product: {application.Product?.GetType()?.Name ?? "(null)"}")
            });
Пример #11
0
        private int SubmitApplicationForConfidentialInvoiceDiscount(ISellerApplication application, ConfidentialInvoiceDiscount cid)
        {
            var result = _confidentialInvoiceWebService.SubmitApplicationFor(
                _sellerApplicationMapper.MapToCompanyDataRequest(application),
                cid.TotalLedgerNetworth,
                cid.AdvancePercentage,
                cid.VatRate
                );

            return(_applicationResultMapper.MapToResultCode(result));
        }
Пример #12
0
        /// <inheritdoc />
        public int SubmitForConfidentialInvoiceDiscount(ISellerCompanyData companyData, ConfidentialInvoiceDiscount cid)
        {
            var result = _confidentialInvoiceWebService.SubmitApplicationFor(
                new CompanyDataRequest
            {
                CompanyFounded = companyData.Founded,
                CompanyNumber  = companyData.Number,
                CompanyName    = companyData.Name,
                DirectorName   = companyData.DirectorName
            }, cid.TotalLedgerNetworth, cid.AdvancePercentage, cid.VatRate);

            return((result.Success) ? result.ApplicationId ?? -1 : -1);
        }
Пример #13
0
 public SellerApplication(ConfidentialInvoiceDiscount confidentialInvoiceDiscount, SellerCompanyData companyData)
 {
     ConfidentialInvoiceDiscount = confidentialInvoiceDiscount;
     CompanyData = companyData;
 }
        private int CallConfidentialInvoiceWebService(ISellerCompanyData companyData, ConfidentialInvoiceDiscount cid)
        {
            var companyDataRequest = GetCompanyDataRequest(companyData);

            var result = _confidentialInvoiceWebService.SubmitApplicationFor(
                companyDataRequest,
                cid.TotalLedgerNetworth,
                cid.AdvancePercentage,
                cid.VatRate);

            return(ProcessApplicationResult(result));
        }