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 ProductApplicationService_SubmitApplicationFor_WhenCalledWithSelectiveInvoiceDiscount_ShouldReturnOne()
        {
            _confidentialInvoiceServiceMock.Setup(m => m.SubmitApplicationFor(It.IsAny <CompanyDataRequest>(), It.IsAny <decimal>(), It.IsAny <decimal>(), It.IsAny <decimal>())).Returns(_result.Object);
            var result = _sut.SubmitApplicationFor(_sellerApplication);

            result.Should().Be(1);
        }
Beispiel #3
0
        public void Can_Not_Submit_Application_For_Unsupported_Product()
        {
            // Arrange

            var unsupportedProduct = new UnsupportedProduct
            {
                Id         = 1,
                LoanAmount = 200,
            };

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

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

            // Act and Assert
            Assert.Throws <InvalidOperationException>(() => sut.SubmitApplicationFor(sellerApplication));
        }
Beispiel #4
0
        public void ProductApplicationService_SubmitApplicationFor_WhenCalled_ShouldCallMediatorSubmitApplicationForOnce()
        {
            _mediatorService.Setup(m => m.SubmitApplicationFor(It.IsAny <ISellerApplication>())).Returns(_result);
            var result = _sut.SubmitApplicationFor(_sellerApplication);

            result.Should().Be(_result);
        }
Beispiel #5
0
        public void ConfidentialInvoiceService_Submit_Throws_ProductApplicationException()
        {
            _confidentialInvoiceServiceMock.Setup(m =>
                                                  m.SubmitApplicationFor(
                                                      It.IsAny <CompanyDataRequest>(),
                                                      It.IsAny <decimal>(),
                                                      It.IsAny <decimal>(),
                                                      It.IsAny <decimal>()))
            .Returns(_errorsResult.Object);

            var services = new ServiceCollection();

            services.AddSingleton(typeof(IConfidentialInvoiceService), _confidentialInvoiceServiceMock.Object);
            var serviceProvider = services.BuildServiceProvider();

            var sellerApplicationMock = new Mock <ISellerApplication>();

            sellerApplicationMock.SetupProperty(p => p.Product, new ConfidentialInvoiceDiscount());
            sellerApplicationMock.SetupProperty(p => p.CompanyData, new SellerCompanyData());
            var sellerApplication = sellerApplicationMock.Object;

            var productApplicationService = new ProductApplicationService(serviceProvider);

            Assert.Throws <ProductApplicationException>(() => productApplicationService.SubmitApplicationFor(sellerApplication));
        }
Beispiel #6
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();
        }
Beispiel #7
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();
        }
Beispiel #8
0
        public void Can_Submit_Application_For_Product_BusinessLoans()
        {
            // Arrange

            var businessLoans = new BusinessLoans
            {
                Id = 1,
                InterestRatePerAnnum = 0.05M,
                LoanAmount           = 100,
            };

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

            var mockBusinessLoansService = new Mock <IBusinessLoansService>();

            mockBusinessLoansService.Setup(bls => bls.SubmitApplicationFor(It.IsAny <CompanyDataRequest>(), It.IsAny <LoansRequest>())).Returns(GetSuccessfulApplicationResult());

            var sut = new ProductApplicationService(
                new Mock <ISelectInvoiceService>().Object,
                new Mock <IConfidentialInvoiceService>().Object,
                mockBusinessLoansService.Object
                );

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

            // Assert
            Assert.Equal(1, applicationResult);
            mockBusinessLoansService.VerifyAll();
        }
        public void Should_Throw_Error_if_application_is_Null()
        {
            ISellerApplication sellerApplciation = null;
            var productApplciationservice        = new ProductApplicationService(_selectInvoiceService.Object, _confidentialInvoiceService.Object, _businessLoanService.Object);

            Assert.Throws <NullReferenceException>(() => productApplciationservice.SubmitApplicationFor(sellerApplciation));
        }
        public void SubmitApplicationFor_WhenCalledWithNull_ShouldThrowException()
        {
            // Arrange
            var service = new ProductApplicationService(_serviceClientFactoryMock.Object);

            // Assert
            Assert.Throws <ArgumentNullException>(() => service.SubmitApplicationFor(null));
        }
        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 Should_Throw_Error_as_no_product()
        {
            ISellerApplication sellerApplication = new SellerApplication()
            {
                CompanyData = companyData
            };

            var productApplciationservice = new ProductApplicationService(_selectInvoiceService.Object, _confidentialInvoiceService.Object, _businessLoanService.Object);

            Assert.Throws <InvalidOperationException>(() => productApplciationservice.SubmitApplicationFor(sellerApplication));
        }
Beispiel #14
0
        public void SubmitApplicationFor_HandlerNotFound_ThrowsInvalidOperationException()
        {
            _applicationHandlerFactoryMock
            .Setup(f => f.GetHandler(It.IsAny <ISellerApplication>()))
            .Returns((IApplicationHandler)null);

            var service = new ProductApplicationService(_applicationHandlerFactoryMock.Object);

            Func <int> act = () => service.SubmitApplicationFor(_applicationMock.Object);

            act.Should().Throw <InvalidOperationException>();
        }
Beispiel #15
0
        public void ProductApplicationService_SubmitApplicationFor_WhenCalledWithSelectiveInvoiceDiscount_ShouldReturnOne()
        {
            _sellerApplication = TestSellerApplicationProvider.GetTestSellerApplication(new SelectiveInvoiceDiscount());
            _selectInvoiceServiceMock.Setup(m => m.SubmitApplicationFor(It.IsAny <string>(), It.IsAny <decimal>(), It.IsAny <decimal>())).Returns(1);
            var result = _sut.SubmitApplicationFor(_sellerApplication);

            result.Should().Be(1);
        }
        public void UnsupportedProductTypeException_ShouldBeThrowed_WhenThereAreNoSpecificStrategy()
        {
            // Arrange
            var submitApplicationStrategyFactory = new SubmitApplicationStrategyFactory(null, null, null);
            var productApplicationService        = new ProductApplicationService(submitApplicationStrategyFactory);
            var application = new SellerApplication()
            {
                Product = new UnexistingProduct()
            };

            // Act & Assert
            Assert.Throws <UnsupportedProductTypeException>(() =>
                                                            productApplicationService.SubmitApplicationFor(application)
                                                            );
        }
        public void SubmitApplicationFor_WhenCalledWithoutCompanyData_WhouldReturnMinusOne()
        {
            // Arrange
            var application = new SellerApplication
            {
                Product = new BusinessLoans(),
            };
            var service = new ProductApplicationService(_serviceClientFactoryMock.Object);

            // Act
            var result = service.SubmitApplicationFor(application);

            // Assert
            result.Should().Be(-1);
        }
        public void SellApplicationObjectNullExceptionTest()
        {
            //Arrange
            ProductApplicationService thisProductApplicationService = new ProductApplicationService(null, null, null);

            //Act
            try
            {
                thisProductApplicationService.SubmitApplicationFor(null);
            }
            //Assert
            catch (System.ArgumentNullException ex)
            {
                throw ex;
            }
        }
Beispiel #19
0
        public void Calls_SelectInvoiceService_With_Proper_Args_And_Success_Result()
        {
            // Arrange
            var sis = new Mock <ISelectInvoiceService>(MockBehavior.Strict);
            var cis = new Mock <IConfidentialInvoiceService>(MockBehavior.Strict);
            var bls = new Mock <IBusinessLoansService>(MockBehavior.Strict);

            var pas = new ProductApplicationService(sis.Object, cis.Object, bls.Object);

            (string num, decimal amount, decimal advPct)? calledArgs = null;
            sis.Setup(s => s.SubmitApplicationFor(It.IsAny <string>(), It.IsAny <decimal>(), It.IsAny <decimal>()))
            .Returns <string, decimal, decimal>(
                (num, amount, advPct) =>
            {
                calledArgs = (num, amount, advPct);
                return(0);
            });

            var app = new SellerApplication
            {
                CompanyData = new SellerCompanyData
                {
                    DirectorName = "Smith",
                    Founded      = new DateTime(2000, 01, 01),
                    Name         = "ACME",
                    Number       = 123
                },
                Product = new SelectiveInvoiceDiscount
                {
                    InvoiceAmount     = 123000.456M,
                    AdvancePercentage = 5.67M
                }
            };

            // Act
            var result = pas.SubmitApplicationFor(app);

            // Assert
            Assert.True(result.Success);
            Assert.True(!result.Errors.Any());
            Assert.Null(result.ApplicationId);

            Assert.NotNull(calledArgs);
            Assert.Equal("123", calledArgs.Value.num);
            Assert.Equal(123000.456M, calledArgs.Value.amount);
            Assert.Equal(5.67M, calledArgs.Value.advPct);
        }
Beispiel #20
0
        public void ProductApplicationService_SubmitApplicationFor_WhenCalledWithBusinessLoans_ShouldReturnOne()
        {
            var sut = new ProductApplicationService(_selectInvoiceServiceMock.Object, _confidentialInvoiceServiceMock.Object, _businessLoansServiceMock.Object);

            _result.SetupProperty(p => p.ApplicationId, 1);
            _result.SetupProperty(p => p.Success, true);
            var sellerApplicationMock = new Mock <ISellerApplication>();

            sellerApplicationMock.SetupProperty(p => p.Product, new BusinessLoans());
            sellerApplicationMock.SetupProperty(p => p.CompanyData, new SellerCompanyData());
            var sellerApplication = sellerApplicationMock.Object;

            _businessLoansServiceMock.Setup(m => m.SubmitApplicationFor(It.IsAny <CompanyDataRequest>(), It.IsAny <LoansRequest>())).Returns(_result.Object);

            var result = sut.SubmitApplicationFor(sellerApplication);

            result.Should().Be(1);
        }
Beispiel #21
0
        public void SubmitApplicationFor_HandlerIsFound_ReturnsApplicationId()
        {
            var applicationId          = AutoFaker.Generate <int>();
            var applicationHandlerMock = new Mock <IApplicationHandler>();

            applicationHandlerMock.Setup(h => h.SubmitApplicationFor(_applicationMock.Object))
            .Returns(applicationId);

            _applicationHandlerFactoryMock
            .Setup(f => f.GetHandler(It.IsAny <ISellerApplication>()))
            .Returns(applicationHandlerMock.Object);

            var service = new ProductApplicationService(_applicationHandlerFactoryMock.Object);

            var result = service.SubmitApplicationFor(_applicationMock.Object);

            result.Should().Be(applicationId);
        }
        public void SubmitApplicationFor_ShouldCallServiceClient()
        {
            // Arrange
            var application = new SellerApplication
            {
                Product     = new BusinessLoans(),
                CompanyData = new SellerCompanyData(),
            };
            var service = new ProductApplicationService(_serviceClientFactoryMock.Object);

            var serviceClientMock = new Mock <IServiceClient>();

            serviceClientMock.Setup(m => m.SubmitApplication(application)).Returns(1);
            _serviceClientFactoryMock.Setup(m => m.GetService(application.Product)).Returns(serviceClientMock.Object);

            // Act
            var result = service.SubmitApplicationFor(application);

            // Assert
            result.Should().Be(1);
        }
        public void Submit_with_Business_Loan()
        {
            ISellerApplication sellerApplication = new SellerApplication()
            {
                CompanyData = companyData,
                Product     = new BusinessLoans()
                {
                    Id                   = 1,
                    LoanAmount           = 100,
                    InterestRatePerAnnum = 5
                }
            };

            _businessLoanService.Setup(x => x.SubmitApplicationFor(It.IsAny <CompanyDataRequest>(), It.IsAny <LoansRequest>())).Returns(new ApplicationResult()
            {
                ApplicationId = 1, Success = true
            });

            var productApplciationservice = new ProductApplicationService(_selectInvoiceService.Object, _confidentialInvoiceService.Object, _businessLoanService.Object);

            var result = productApplciationservice.SubmitApplicationFor(sellerApplication);

            Assert.Equal(1, result);
        }
Beispiel #24
0
        public void ProductApplicationService_SubmitApplicationFor_WhenCalledWithConfidentialInvoiceDiscount_ShouldReturnOne()
        {
            var result = _sut.SubmitApplicationFor(_sellerApplication);

            result.Should().Be(1);
        }
 public void SubmitApplicationFor_throws_exception_when_application_is_unknown()
 {
     Assert.Throws <InvalidOperationException>(() => productApplicationService.SubmitApplicationFor(sellerApplication));
 }
Beispiel #26
0
        public void ProductApplicationService_Should_Throw_Exception_When_Product_Not_Defined()
        {
            var application = new SellerApplication();

            Assert.Throws <InvalidOperationException>(() => _productApplicationService.SubmitApplicationFor(application));
        }
        public void WhenSellerApplicationIsNullThrowsArgumentNullException()
        {
            IProductApplicationService applicationService = new ProductApplicationService(null, null, null);

            Assert.Throws <ArgumentNullException>(() => applicationService.SubmitApplicationFor(null));
        }