public void Submit_ShouldCallService_And_ReturnCorrectResult()
        {
            // Arrange
            var product = new SelectiveInvoiceDiscount
            {
                AdvancePercentage = 6.99m,
                InvoiceAmount     = 1500m,
            };
            var companyData = new SellerCompanyData
            {
                Number = 123,
            };
            var serviceResult = 3;

            var client = new SelectInvoiceServiceClient(_selectInvoiceServiceMock.Object);

            _selectInvoiceServiceMock.Setup(m => m.SubmitApplicationFor("123", product.InvoiceAmount, product.AdvancePercentage))
            .Returns(serviceResult);

            // Act
            var result = client.SubmitApplication(new SellerApplication
            {
                Product     = product,
                CompanyData = companyData,
            });

            // Assert
            Assert.Equal(serviceResult, result);
        }
        public void SubmitApplicationFor_BusinessLoans_CallsBusinessLoansService()
        {
            // **Arrange**
            BusinessLoan      product     = _fixture.Build <BusinessLoan>().Create();
            SellerCompanyData companyData = _fixture.Build <SellerCompanyData>().Create();
            SellerApplication <BusinessLoan> application = _fixture.Build <SellerApplication <BusinessLoan> >()
                                                           .With(a => a.Product, product)
                                                           .With(a => a.CompanyData, companyData)
                                                           .Create();

            loans.SubmitApplicationFor(
                Arg.Is <CompanyDataRequest>(x => x.DirectorName == companyData.DirectorName &&
                                            x.CompanyNumber == companyData.Number &&
                                            x.CompanyName == companyData.Name &&
                                            x.CompanyFounded == companyData.Founded),
                Arg.Is <LoansRequest>(y => y.InterestRatePerAnnum == product.InterestRatePerAnnum &&
                                      y.LoanAmount == product.LoanAmount))
            .Returns(new TestApplicationResult(10, true, new List <string>()));

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

            // **Assert**
            loans.Received(1).SubmitApplicationFor(Arg.Is <CompanyDataRequest>(x => x.DirectorName == companyData.DirectorName &&
                                                                               x.CompanyNumber == companyData.Number &&
                                                                               x.CompanyName == companyData.Name &&
                                                                               x.CompanyFounded == companyData.Founded),
                                                   Arg.Is <LoansRequest>(y => y.InterestRatePerAnnum == product.InterestRatePerAnnum &&
                                                                         y.LoanAmount == product.LoanAmount));
            Assert.Equal(10, result);
        }
        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);
        }
        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);
        }
        public void WhenProductIsSelectiveInvoiceCanHandleSubmitApplication()
        {
            //Arrange

            IProduct product = new SelectiveInvoiceDiscount {
                Id = 1, InvoiceAmount = 300, AdvancePercentage = 5
            };

            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);

            mockSelectInvoiceService.Setup(m => m.SubmitApplicationFor(It.Is <string>(companyNumber => companyNumber == "12"), It.IsAny <decimal>(), It.IsAny <decimal>())).Returns(1);
            mockSelectInvoiceService.Setup(m => m.SubmitApplicationFor(It.Is <string>(companyNumber => companyNumber != "12"), It.IsAny <decimal>(), It.IsAny <decimal>())).Returns(-1);

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

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

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

            //Assert
            mockSelectInvoiceService.Verify();

            Assert.Equal(1, result1);
            Assert.Equal(-1, result2);
        }
        public void SubmitApplicationFor_SelectInvoiceDiscount_CallsSelectInvoiceService()
        {
            // **Arrange**
            SelectiveInvoiceDiscount sidProduct  = _fixture.Build <SelectiveInvoiceDiscount>().Create();
            SellerCompanyData        companyData = _fixture.Build <SellerCompanyData>().Create();
            SellerApplication <SelectiveInvoiceDiscount> application = _fixture.Build <SellerApplication <SelectiveInvoiceDiscount> >()
                                                                       .With(a => a.Product, sidProduct)
                                                                       .With(a => a.CompanyData, companyData)
                                                                       .Create();

            sid.SubmitApplicationFor(application.CompanyData.Number.ToString(), sidProduct.InvoiceAmount, sidProduct.AdvancePercentage).Returns(100);

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

            // **Assert**
            sid.Received(1).SubmitApplicationFor(application.CompanyData.Number.ToString(), sidProduct.InvoiceAmount, sidProduct.AdvancePercentage);
            Assert.Equal(100, result);
        }
        public void MapToRequest_ShouldMapCorrectly()
        {
            // Arrange
            var data = new SellerCompanyData
            {
                DirectorName = "Director #1",
                Founded      = DateTime.Today,
                Name         = "Name #1",
                Number       = 1,
            };
            var mapper = new CompanyDataMapper();

            // Act
            var result = mapper.MapToRequest(data);

            // Assert
            Assert.Equal(data.DirectorName, result.DirectorName);
            Assert.Equal(data.Founded, result.CompanyFounded);
            Assert.Equal(data.Name, result.CompanyName);
            Assert.Equal(data.Number, result.CompanyNumber);
        }
示例#8
0
 public SellerApplication(BusinessLoans businessLoans, SellerCompanyData companyData)
 {
     BusinessLoans = businessLoans;
     CompanyData   = companyData;
 }
示例#9
0
 public SellerApplication(SelectiveInvoiceDiscount selectiveInvoiceDiscount, SellerCompanyData companyData)
 {
     SelectiveInvoiceDiscount = selectiveInvoiceDiscount;
     CompanyData = companyData;
 }
示例#10
0
 public SellerApplication(ConfidentialInvoiceDiscount confidentialInvoiceDiscount, SellerCompanyData companyData)
 {
     ConfidentialInvoiceDiscount = confidentialInvoiceDiscount;
     CompanyData = companyData;
 }