Example #1
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));
        }
Example #2
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));
        }
Example #4
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();
        }
Example #5
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 ProductApplicationServiceTests()
 {
     _productApplicationService = new ProductApplicationService(_selectInvoiceServiceMock.Object,
                                                                _confidentialInvoiceServiceMock.Object, _businessLoansServiceMock.Object);
     _result.SetupProperty(p => p.ApplicationId, 1);
     _result.SetupProperty(p => p.Success, true);
 }
Example #7
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));
        }
        public void SubmitApplicationFor_WhenCalledWithNull_ShouldThrowException()
        {
            // Arrange
            var service = new ProductApplicationService(_serviceClientFactoryMock.Object);

            // Assert
            Assert.Throws <ArgumentNullException>(() => service.SubmitApplicationFor(null));
        }
Example #9
0
 public ProductApplicationTests()
 {
     // In real world with DI I would simply use DI to have this factory as a singleton.
     // Or I would implement my own singleton, but as it's out of scope of this task, I just think it's worth to mention
     _productApplicationFactory = new ProductApplicationServiceFactory();
     InitStrategies();
     _sut = new ProductApplicationService(_productApplicationFactory);
 }
 public ProductApplicationServiceTests()
 {
     _fixture = new Fixture();
     sid      = Substitute.For <ISelectInvoiceService>();
     cid      = Substitute.For <IConfidentialInvoiceService>();
     loans    = Substitute.For <IBusinessLoansService>();
     _service = new ProductApplicationService(sid, cid, loans);
 }
Example #11
0
        void IBootStrap.Start()
        {
            var dataStore   = new CustomerBasketDataStore();
            var productRepo = new ProductApplicationService();
            var basketRepo  = new CustomerBasketRepository(dataStore);

            this.appQueryGateway  = new AppQueryHandler(basketRepo, productRepo);
            this.appCommandGatway = new AppCommandHandler(basketRepo);
        }
Example #12
0
        public ProductApplicationTests()
        {
            var businessLoansService          = new BusinessLoansService();
            var confidentialInvoiceWebService = new ConfidentialInvoiceService();
            var selectInvoiceService          = new SelectInvoiceService();

            _productHandlerLocator             = new ProductHandlerLocator(selectInvoiceService, confidentialInvoiceWebService, businessLoansService);
            _productApplicationService         = new ProductApplicationService(selectInvoiceService, confidentialInvoiceWebService, businessLoansService);
            _productApplicationServiceEnhanced = new ProductApplicationServiceEnhanced(_productHandlerLocator);
        }
        private IProductState GetProductState(string productId)
        {
            var prdState = ProductApplicationService.Get(productId);

            if (prdState == null)
            {
                throw new ArgumentException(String.Format("Product NOT found. Product Id.: {0}", productId));
            }
            return(prdState);
        }
Example #14
0
        public ProductApplicationTests()
        {
            _sut = new ProductApplicationService(_mediatorService.Object);

            var sellerApplicationMock = new Mock <ISellerApplication>();

            sellerApplicationMock.SetupProperty(p => p.Product, new ConfidentialInvoiceDiscount());
            sellerApplicationMock.SetupProperty(p => p.CompanyData, new SellerCompanyData());
            _sellerApplication = sellerApplicationMock.Object;
        }
        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));
        }
        public ProductApplicationTests()
        {
            _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 ConfidentialInvoiceDiscount());
            sellerApplicationMock.SetupProperty(p => p.CompanyData, new SellerCompanyData());
            _sellerApplication = sellerApplicationMock.Object;
        }
Example #17
0
        public void TestGetProductByIdNull()
        {
            //Arrange
            Mock <IProductRepository>  mockProductRepository      = new Mock <IProductRepository>();
            IProductApplicationService productsApplicationService = new ProductApplicationService(mockProductRepository.Object);
            int id = 0;

            //Act & Assert
            Assert.Throws <InvalidOperationException>(() => productsApplicationService
                                                      .GetProductById(id));
        }
Example #18
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>();
        }
        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);
        }
Example #20
0
        public void NullTestSaveProduct()
        {
            //Arrange
            Mock <IProductRepository> mockProductRepository =
                new Mock <IProductRepository>();
            ProductDto product = null;
            IProductApplicationService productsApplicationService =
                new ProductApplicationService(mockProductRepository.Object);

            //Act & Assert
            Assert.Throws <NullReferenceException>(() => productsApplicationService
                                                   .SaveProduct(product));
        }
Example #21
0
        private (IProductApplicationService ApplicationService, ISellerApplication SellerApplication) SetupServiceWithApplication(
            IProduct product,
            int?applicationId,
            bool isSuccess)
        {
            SetupExternalServices(applicationId, isSuccess);
            var sut = new ProductApplicationService(
                _selectInvoiceService.Object,
                _confidentialInvoiceServiceMock.Object,
                _bussinesLoansService.Object);

            return(sut, SetupSellerApplication(product));
        }
Example #22
0
        public ProductApplicationTests()
        {
            _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 ConfidentialInvoiceDiscount());
            sellerApplicationMock.SetupProperty(p => p.CompanyData, new SellerCompanyData());
            _sellerApplication = sellerApplicationMock.Object;

            _confidentialInvoiceServiceMock.Setup(m => m.SubmitApplicationFor(It.IsAny <CompanyDataRequest>(), It.IsAny <decimal>(), It.IsAny <decimal>(), It.IsAny <decimal>())).Returns(_result.Object);
            _selectInvoiceServiceMock.Setup(m => m.SubmitApplicationFor(It.IsAny <string>(), It.IsAny <decimal>(), It.IsAny <decimal>())).Returns(It.IsAny <int>);
            _businessLoansServiceMock.Setup(m => m.SubmitApplicationFor(It.IsAny <CompanyDataRequest>(), It.IsAny <LoansRequest>())).Returns(_result.Object);
        }
        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 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 SellApplicationObjectNullExceptionTest()
        {
            //Arrange
            ProductApplicationService thisProductApplicationService = new ProductApplicationService(null, null, null);

            //Act
            try
            {
                thisProductApplicationService.SubmitApplicationFor(null);
            }
            //Assert
            catch (System.ArgumentNullException ex)
            {
                throw ex;
            }
        }
Example #26
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);
        }
        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);
        }
Example #28
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);
        }
Example #29
0
        public void GetProducts()
        {
            //Arrange
            Mock <IProductRepository> mockProductRepository =
                new Mock <IProductRepository>();

            mockProductRepository.Setup(service => service.GetProducts())
            .Returns(new List <Product>()
            {
                new Product(), new Product()
            });
            IProductApplicationService productsApplicationService = new ProductApplicationService(mockProductRepository.Object);
            //Act
            IList <ProductDto> result = productsApplicationService.GetProducts();

            //Assert
            Assert.IsAssignableFrom <IList <ProductDto> >(result);
        }
Example #30
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);
        }