private int CallSelectInvoiceService(int companyNumber, SelectiveInvoiceDiscount sid)
 {
     return(_selectInvoiceService.SubmitApplicationFor(
                companyNumber.ToString(),
                sid.InvoiceAmount,
                sid.AdvancePercentage));
 }
Esempio n. 2
0
        public void Can_Submit_Application_For_SelectiveInvoiceDiscount()
        {
            // Arrange

            var selectInvoiceDiscount = new SelectiveInvoiceDiscount
            {
                Id                = 1,
                InvoiceAmount     = 200,
                AdvancePercentage = 80,
            };

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

            var mockSelectInvoiceService = new Mock <ISelectInvoiceService>();

            mockSelectInvoiceService.Setup(sis => sis.SubmitApplicationFor(It.IsAny <string>(), 200, 80)).Returns(1);

            var sut = new ProductApplicationService(
                mockSelectInvoiceService.Object,
                new Mock <IConfidentialInvoiceService>().Object,
                new Mock <IBusinessLoansService>().Object
                );

            // Act

            var applicationResult = sut.SubmitApplicationFor(sellerApplication);

            // Assert
            Assert.Equal(1, applicationResult);
            mockSelectInvoiceService.VerifyAll();
        }
        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);
        }
        private void SetupMockSelectInvoiceService(ISellerApplication application, int rtn)
        {
            SelectiveInvoiceDiscount product = (SelectiveInvoiceDiscount)application.Product;

            _mockSelectInvoiceService
            .Setup(p => p.SubmitApplicationFor(application.CompanyData.Number.ToString(), product.InvoiceAmount, product.AdvancePercentage))
            .Returns(rtn)
            .Verifiable();
        }
        public void SubmitApplicationFor_SelectInvoiceDiscount_CallSelectInvoiceService()
        {
            var sid = Substitute.For <ISelectInvoiceService>();

            var sidProduct  = new SelectiveInvoiceDiscount(sid);
            var companyData = _fixture.Build <SellerCompanyData>().Create();

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

            var result = sidProduct.SubmitApplicationFor(companyData);

            sid.Received(1).SubmitApplicationFor(companyData.Number.ToString(), sidProduct.InvoiceAmount, sidProduct.AdvancePercentage);
            Assert.Equal(100, result);
        }
        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 CreateSelectiveInvoiceDiscountApplication__Handle__AssertIsRedirectedToBusinessLoansService()
        {
            var selectiveInvoiceDiscount = new SelectiveInvoiceDiscount()
            {
                InvoiceAmount = 1, AdvancePercentage = 2, Id = 3
            };
            var application             = new SellerApplication(selectiveInvoiceDiscount, GetCompanyData());
            var selectiveInvoiceService = new Mock <ISelectInvoiceService>();

            selectiveInvoiceService.Setup(svc => svc.SubmitApplicationFor(
                                              It.IsAny <string>(), 1, 2)).Returns(1);

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

            selectiveInvoiceService.VerifyAll();
            Assert.Equal(1, applicationResult);
        }
Esempio n. 9
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)"}")
            });
Esempio n. 10
0
 private int SubmitApplicationForSelectiveInvoiceDiscount(ISellerApplication application, SelectiveInvoiceDiscount sid)
 {
     return(_selectInvoiceService.SubmitApplicationFor(application.CompanyData.Number.ToString(), sid.InvoiceAmount, sid.AdvancePercentage));
 }
Esempio n. 11
0
 public SellerApplication(SelectiveInvoiceDiscount selectiveInvoiceDiscount, SellerCompanyData companyData)
 {
     SelectiveInvoiceDiscount = selectiveInvoiceDiscount;
     CompanyData = companyData;
 }