コード例 #1
0
        public void FindProductsByFilterMaterializeResults()
        {
            //Arrange
            var customerRepository = new SICustomerRepository();
            var productRepository  = new SIProductRepository();
            var orderRepository    = new SIOrderRepository();

            productRepository.AllMatchingISpecificationOfProduct = (spec) =>
            {
                var book = new Book("title", "description", "publisher", "isbn");
                book.ChangeUnitPrice(10);
                book.GenerateNewIdentity();

                var software = new Software("title", "description", "license code");
                software.ChangeUnitPrice(10);
                software.GenerateNewIdentity();

                return(new List <Product>()
                {
                    book,
                    software
                });
            };

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            //act
            var result = salesManagement.FindProducts("filter text");

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count == 2);
        }
コード例 #2
0
        public void FindProductsInPageMaterializeResults()
        {
            //Arrange
            var customerRepository = new SICustomerRepository();
            var productRepository  = new SIProductRepository();
            var orderRepository    = new SIOrderRepository();

            productRepository.GetPagedInt32Int32ExpressionOfFuncOfProductKPropertyBoolean <string>((index, count, order, ascending) =>
            {
                var book = new Book("title", "description", "publisher", "isbn");
                book.ChangeUnitPrice(10M);
                book.GenerateNewIdentity();

                var software = new Software("title", "description", "license code");
                software.ChangeUnitPrice(10);
                software.GenerateNewIdentity();

                return(new List <Product>()
                {
                    book,
                    software
                });
            });


            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            //act
            var result = salesManagement.FindProducts(0, 2);


            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count == 2);
        }
コード例 #3
0
        public void FindOrdersInPageMaterializeResults()
        {
            //Arrange

            var customerRepository = new SICustomerRepository();
            var productRepository  = new SIProductRepository();
            var orderRepository    = new SIOrderRepository();

            orderRepository.GetPagedInt32Int32ExpressionOfFuncOfOrderKPropertyBoolean <DateTime>((index, count, order, ascending) =>
            {
                var item = new Order();
                item.GenerateNewIdentity();
                item.SetTheCustomerReferenceForThisOrder(Guid.NewGuid());

                return(new List <Order>()
                {
                    item
                });
            });
            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            //act
            var result = salesManagement.FindOrders(0, 1);

            //Assert

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Any());
        }
コード例 #4
0
        public void FindOrdersInDateRangeMaterializeResults()
        {
            //Arrange

            var customerRepository = new SICustomerRepository();
            var productRepository  = new SIProductRepository();
            var orderRepository    = new SIOrderRepository();

            orderRepository.AllMatchingISpecificationOfOrder = (spec) =>
            {
                var order = new Order();
                order.GenerateNewIdentity();
                order.SetTheCustomerReferenceForThisOrder(Guid.NewGuid());

                return(new List <Order>()
                {
                    order
                });
            };

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            //act
            var result = salesManagement.FindOrders(DateTime.Now.AddDays(-2), DateTime.Now.AddDays(-1));

            //Assert

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Any());
        }
コード例 #5
0
        public void FindOrdersMaterializeResultsIfCustomerExist()
        {
            //Arrange
            var customerRepository = new SICustomerRepository();
            var productRepository  = new SIProductRepository();
            var orderRepository    = new SIOrderRepository();

            orderRepository.GetFilteredExpressionOfFuncOfOrderBoolean = (filter) =>
            {
                var orders   = new List <Order>();
                var customer = new Customer();
                customer.ChangeCurrentIdentity(Guid.NewGuid());
                orders.Add(OrderFactory.CreateOrder(customer, "name", "city", "address", "zipcode"));

                return(orders);
            };

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            //act
            var result = salesManagement.FindOrders(Guid.NewGuid());


            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count == 1);
        }
コード例 #6
0
        public void AddNewValidOrderReturnAddedOrder()
        {
            //Arrange

            var productRepository  = new SIProductRepository();
            var orderRepository    = new SIOrderRepository();
            var customerRepository = new SICustomerRepository();
            var country            = new Country("Spain", "es-ES");

            country.GenerateNewIdentity();

            customerRepository.GetGuid = (guid) =>
            {
                //default credit limit is 1000
                var customer = CustomerFactory.CreateCustomer("Jhon", "El rojo", "+34343", "company", country, new Address("city", "zipCode", "addressline1", "addressline2"));

                return(customer);
            };


            orderRepository.UnitOfWorkGet = () =>
            {
                var uow = new SIUnitOfWork();
                uow.Commit = () => { };

                return(uow);
            };
            orderRepository.AddOrder = (order) => { };

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            var dto = new OrderDTO()
            {
                CustomerId      = Guid.NewGuid(),
                ShippingAddress = "Address",
                ShippingCity    = "city",
                ShippingName    = "name",
                ShippingZipCode = "zipcode",
                OrderLines      = new List <OrderLineDTO>()
                {
                    new OrderLineDTO()
                    {
                        ProductId = Guid.NewGuid(), Amount = 1, Discount = 0, UnitPrice = 20
                    }
                }
            };

            //act
            var result = salesManagement.AddNewOrder(dto);

            //assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Id != Guid.Empty);
            Assert.AreEqual(result.ShippingAddress, dto.ShippingAddress);
            Assert.AreEqual(result.ShippingCity, dto.ShippingCity);
            Assert.AreEqual(result.ShippingName, dto.ShippingName);
            Assert.AreEqual(result.ShippingZipCode, dto.ShippingZipCode);
            Assert.IsTrue(result.OrderLines.Count == 1);
            Assert.IsTrue(result.OrderLines.All(ol => ol.Id != Guid.Empty));
        }
コード例 #7
0
        public void ConstructorThrowExceptionIfCustomerRepositoryDependencyIsNull()
        {
            //Arrange
            SICustomerRepository customerRepository = null;
            var orderRepository   = new SIOrderRepository();
            var productRepository = new SIProductRepository();

            //Act
            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);
        }
コード例 #8
0
        public void AddNewSoftwareWithNullDataThrowArgumentException()
        {
            //Arrange
            var customerRepository = new SICustomerRepository();
            var productRepository  = new SIProductRepository();
            var orderRepository    = new SIOrderRepository();

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            //Act

            var result = salesManagement.AddNewSoftware(null);
        }
コード例 #9
0
        public void FindProductsInPageThrowExceptionWhenPageIsInvalid()
        {
            //Arrange

            var customerRepository = new SICustomerRepository();
            var productRepository  = new SIProductRepository();
            var orderRepository    = new SIOrderRepository();

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            //act
            var resultInvalidPageIndex = salesManagement.FindProducts(-1, 1);
        }
コード例 #10
0
        public void FindOrdersInPageThrowArgumentExceptionWhenPageDataIsInvalid()
        {
            //Arrange

            var customerRepository = new SICustomerRepository();
            var productRepository  = new SIProductRepository();
            var orderRepository    = new SIOrderRepository();

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            //act
            var resultInvalidPageIndex = salesManagement.FindOrders(-1, 1);

            //Assert
            Assert.IsNull(resultInvalidPageIndex);
        }
コード例 #11
0
        public void FindOrdersInPageThrowArgumentExceptionWhenPageDataIsInvalid()
        {
            //Arrange
            
            var customerRepository = new SICustomerRepository();
            var productRepository = new SIProductRepository();
            var orderRepository = new SIOrderRepository();

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            //act
            var resultInvalidPageIndex = salesManagement.FindOrders(-1, 1);
            
            //Assert
            Assert.IsNull(resultInvalidPageIndex);
        }
コード例 #12
0
        public void AddNewBookReturnAddedBook()
        {
            //Arrange
            var customerRepository = new SICustomerRepository();
            var orderRepository    = new SIOrderRepository();
            var productRepository  = new SIProductRepository();

            productRepository.UnitOfWorkGet = () =>
            {
                var uow = new SIUnitOfWork();
                uow.Commit = () => { };

                return(uow);
            };

            productRepository.AddProduct = (product) => { };


            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            var dto = new BookDTO()
            {
                Title         = "The title",
                Description   = "description",
                Publisher     = "license",
                ISBN          = "isbn",
                AmountInStock = 10,
                UnitPrice     = 10
            };

            //Act
            var result = salesManagement.AddNewBook(dto);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Id != Guid.Empty);
            Assert.AreEqual(result.Title, dto.Title);
            Assert.AreEqual(result.Description, dto.Description);
            Assert.AreEqual(result.Publisher, dto.Publisher);
            Assert.AreEqual(result.ISBN, dto.ISBN);
            Assert.AreEqual(result.AmountInStock, dto.AmountInStock);
            Assert.AreEqual(result.UnitPrice, dto.UnitPrice);
        }
コード例 #13
0
        public void FindOrdersWithInvalidPageIndexThrowException()
        {
            //Arrange

            var customerRepository = new SICustomerRepository();
            var productRepository  = new SIProductRepository();
            var orderRepository    = new SIOrderRepository();

            orderRepository.GetPagedInt32Int32ExpressionOfFuncOfOrderKPropertyBoolean <DateTime>((index, count, order, ascending) =>
            {
                return(new List <Order>());
            });


            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            //act
            var result = salesManagement.FindOrders(-1, 1);
        }
コード例 #14
0
        public void FindOrderReturnNullIfCustomerIdIsEmpty()
        {
            //Arrange

            var customerRepository = new SICustomerRepository();
            var productRepository  = new SIProductRepository();
            var orderRepository    = new SIOrderRepository();

            orderRepository.GetFilteredExpressionOfFuncOfOrderBoolean = (expression) => null;

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            //act
            var result = salesManagement.FindOrders(Guid.Empty);


            //Assert
            Assert.IsNull(result);
        }
コード例 #15
0
        public void AddNewBookReturnAddedBook()
        {
            //Arrange
            var adapter = PrepareTypeAdapter();
            var customerRepository = new SICustomerRepository();
            var orderRepository = new SIOrderRepository();
            var productRepository = new SIProductRepository();

            productRepository.UnitOfWorkGet = () =>
            {
                var uow = new SIUnitOfWork();
                uow.Commit = () => { };

                return uow;
            };

            productRepository.AddProduct = (product) => { };

            var salesManagement = new SalesAppService(adapter, productRepository, orderRepository,customerRepository);

            var dto = new BookDTO()
            {
                Title = "The title",
                Description = "description",
                Publisher = "license",
                ISBN = "isbn",
                AmountInStock = 10,
                UnitPrice = 10
            };

            //Act
            var result = salesManagement.AddNewBook(dto);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Id != Guid.Empty);
            Assert.AreEqual(result.Title, dto.Title);
            Assert.AreEqual(result.Description, dto.Description);
            Assert.AreEqual(result.Publisher, dto.Publisher);
            Assert.AreEqual(result.ISBN, dto.ISBN);
            Assert.AreEqual(result.AmountInStock, dto.AmountInStock);
            Assert.AreEqual(result.UnitPrice, dto.UnitPrice);
        }
コード例 #16
0
        public void FindOrdersWithInvalidPageIndexThrowException()
        {
            //Arrange

            var customerRepository = new SICustomerRepository();
            var productRepository = new SIProductRepository();
            var orderRepository = new SIOrderRepository();
            orderRepository.GetPagedInt32Int32ExpressionOfFuncOfOrderKPropertyBoolean<DateTime>((index, count, order, ascending) =>
            {
                return new List<Order>();
            });


            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            //act
            var result = salesManagement.FindOrders(-1, 1);


        }
コード例 #17
0
        public void AddNewSoftwareThrowExceptionWhenDataIsInvalid()
        {
            //Arrange
            var customerRepository = new SICustomerRepository();
            var productRepository  = new SIProductRepository();
            var orderRepository    = new SIOrderRepository();

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            var dto = new SoftwareDTO()
            {
                Title         = "The title",
                Description   = "the description",
                LicenseCode   = "license",
                AmountInStock = 10,
                UnitPrice     = -1//this is a not valid value
            };

            //Act
            var result = salesManagement.AddNewSoftware(dto);
        }
コード例 #18
0
        public void AddNewOrderWithoutCustomerIdThrowArgumentException()
        {
            //Arrange

            var customerRepository = new SICustomerRepository();
            var productRepository  = new SIProductRepository();
            var orderRepository    = new SIOrderRepository();

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            var order = new OrderDTO() // order is not valid when customer id is empty
            {
                CustomerId = Guid.Empty
            };

            //act
            var result = salesManagement.AddNewOrder(order);

            //assert
            Assert.IsNull(result);
        }
コード例 #19
0
        public void FindOrdersInDateRangeReturnNullWhenNoData()
        {
            //Arrange

            var customerRepository = new SICustomerRepository();
            var productRepository  = new SIProductRepository();
            var orderRepository    = new SIOrderRepository();

            orderRepository.AllMatchingISpecificationOfOrder = (spec) =>
            {
                return(new List <Order>());
            };

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            //act
            var result = salesManagement.FindOrders(DateTime.Now.AddDays(-2), DateTime.Now.AddDays(+2));


            //Assert
            Assert.IsNull(result);
        }
コード例 #20
0
        public void FindProductsInPageReturnNullWhenNoData()
        {
            //Arrange

            var customerRepository = new SICustomerRepository();
            var orderRepository    = new SIOrderRepository();
            var productRepository  = new SIProductRepository();

            productRepository.GetPagedInt32Int32ExpressionOfFuncOfProductKPropertyBoolean <string>((index, count, order, ascending) =>
            {
                return(new List <Product>());
            });

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            //act
            var result = salesManagement.FindProducts(0, 1);


            //Assert
            Assert.IsNull(result);
        }
コード例 #21
0
        public void FindOrderReturnNullIfCustomerIdIsEmpty()
        {
            //Arrange

            var customerRepository = new SICustomerRepository();
            var productRepository = new SIProductRepository();
            var orderRepository = new SIOrderRepository();
            orderRepository.GetFilteredExpressionOfFuncOfOrderBoolean = (expression) => null;

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            //act
            var result = salesManagement.FindOrders(Guid.Empty);


            //Assert
            Assert.IsNull(result);
        }
コード例 #22
0
        public void FindProductsByFilterMaterializeResults()
        {
            //Arrange
            var customerRepository = new SICustomerRepository();
            var productRepository = new SIProductRepository();
            var orderRepository = new SIOrderRepository();
            productRepository.AllMatchingISpecificationOfProduct = (spec) =>
            {
                var book = new Book("title","description","publisher","isbn");
                book.ChangeUnitPrice(10);
                book.GenerateNewIdentity();

                var software = new Software("title", "description","license code");
                software.ChangeUnitPrice(10);
                software.GenerateNewIdentity();

                return new List<Product>()
                {
                    book,
                    software
                };
            };

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            //act
            var result = salesManagement.FindProducts("filter text");

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count == 2);
        }
コード例 #23
0
        public void AddNewSoftwareWithNullDataReturnNull()
        {
            //Arrange
            var adapter = PrepareTypeAdapter();
            var customerRepository = new SICustomerRepository();
            var productRepository = new SIProductRepository();
            var orderRepository = new SIOrderRepository();

            var salesManagement = new SalesAppService(adapter, productRepository, orderRepository,customerRepository);

            //Act

            var result = salesManagement.AddNewSoftware(null);

            //Assert
            Assert.IsNull(result);
        }
コード例 #24
0
        public void ConstructorThrowExceptionIfOrderRepositoryDependencyIsNull()
        {
            //Arrange
            var adapter = PrepareTypeAdapter();
            var customerRepository = new SICustomerRepository();
            SIOrderRepository orderRepository = null;
            var productRepository = new SIProductRepository();

            //Act
            var salesManagement = new SalesAppService(adapter, productRepository, orderRepository,customerRepository);
        }
コード例 #25
0
        public void FindOrdersInDateRangeMaterializeResults()
        {
            //Arrange
            var adapter = PrepareTypeAdapter();
            var customerRepository = new SICustomerRepository();
            var productRepository = new SIProductRepository();
            var orderRepository = new SIOrderRepository();

            orderRepository.AllMatchingISpecificationOfOrder = (spec) =>
            {
                return new List<Order>()
                {
                    new Order(){Id = Guid.NewGuid(),CustomerId = Guid.NewGuid()}
                };
            };

            var salesManagement = new SalesAppService(adapter, productRepository, orderRepository,customerRepository);

            //act
            var result = salesManagement.FindOrders(DateTime.Now.AddDays(-2), DateTime.Now.AddDays(-1));

            //Assert

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Any());
        }
コード例 #26
0
        public void FindOrdersInPageReturnNullWhenNoData()
        {
            //Arrange
            var adapter = PrepareTypeAdapter();
            var customerRepository = new SICustomerRepository();
            var productRepository = new SIProductRepository();
            var orderRepository = new SIOrderRepository();
            orderRepository.GetPagedInt32Int32ExpressionOfFuncOfOrderKPropertyBoolean<DateTime>((index, count, order, ascending) =>
            {
                return new List<Order>();
            });

            var salesManagement = new SalesAppService(adapter, productRepository, orderRepository,customerRepository);

            //act
            var result = salesManagement.FindOrders(-1, 1);

            //Assert
            Assert.IsNull(result);
        }
コード例 #27
0
        public void FindProductsInPageMaterializeResults()
        {
            //Arrange
            var adapter = PrepareTypeAdapter();
            var customerRepository = new SICustomerRepository();
            var productRepository = new SIProductRepository();
            var orderRepository = new SIOrderRepository();
            productRepository.GetPagedInt32Int32ExpressionOfFuncOfProductKPropertyBoolean<string>((index, count, order, ascending) =>
            {
                return new List<Product>()
                {
                    new Book(){Id= Guid.NewGuid(),Title = "title",UnitPrice = 10,Description ="description",ISBN ="isbn",Publisher ="publisher"},
                    new Software(){Id= Guid.NewGuid(),Title = "title",UnitPrice = 10,Description ="description",LicenseCode ="license code"},
                };
            });

            var salesManagement = new SalesAppService(adapter, productRepository, orderRepository,customerRepository);

            //act
            var result = salesManagement.FindProducts(0, 2);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count == 2);
        }
コード例 #28
0
        public void FindProductsInPageReturnNullWhenNoData()
        {
            //Arrange
            
            var customerRepository = new SICustomerRepository();
            var orderRepository = new SIOrderRepository();
            var productRepository = new SIProductRepository();
            productRepository.GetPagedInt32Int32ExpressionOfFuncOfProductKPropertyBoolean<string>((index, count, order, ascending) =>
            {
                return new List<Product>();
            });

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            //act
            var result = salesManagement.FindProducts(0, 1);


            //Assert
            Assert.IsNull(result);
        }
コード例 #29
0
        public void AddNewSoftwareReturnAddedSoftware()
        {
            //Arrange 
            var customerRepository = new SICustomerRepository();
            var orderRepository = new SIOrderRepository();
            var productRepository = new SIProductRepository();

            productRepository.UnitOfWorkGet = () =>
            {
                var uow = new SIUnitOfWork();
                uow.Commit = () => { };

                return uow;
            };

            productRepository.AddProduct = (product) => { };


            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            var dto = new SoftwareDTO()
            {
                Title = "The title",
                Description = "description",
                LicenseCode = "license code",
                AmountInStock = 10,
                UnitPrice = 10
            };

            //Act
            var result = salesManagement.AddNewSoftware(dto);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Id != Guid.Empty);
            Assert.AreEqual(result.Title, dto.Title);
            Assert.AreEqual(result.Description, dto.Description);
            Assert.AreEqual(result.LicenseCode, dto.LicenseCode);
            Assert.AreEqual(result.AmountInStock, dto.AmountInStock);
            Assert.AreEqual(result.UnitPrice, dto.UnitPrice);
        }
コード例 #30
0
        public void AddNewBookThrowExceptionWhenDataIsInvalid()
        {
            //Arrange 
            
            var customerRepository = new SICustomerRepository();
            var productRepository = new SIProductRepository();
            var orderRepository = new SIOrderRepository();

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            var dto = new BookDTO()
            {
                Title = "The title",
                Description = "description",
                Publisher = "license",
                ISBN = "isbn",
                AmountInStock = 10,
                UnitPrice = -1//this is a not valid value
            };

            //Act
            var result = salesManagement.AddNewBook(dto);


        }
コード例 #31
0
        public void AddNewBookWithNullDataThrowArgumentException()
        {
            //Arrange 
            var customerRepository = new SICustomerRepository();
            var productRepository = new SIProductRepository();
            var orderRepository = new SIOrderRepository();

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            //Act

            var result = salesManagement.AddNewBook(null);

            //Assert
            Assert.IsNull(result);
        }
コード例 #32
0
        public void AddNewSoftwareThrowExceptionWhenDataIsInvalid()
        {
            //Arrange
            var adapter = PrepareTypeAdapter();
            var customerRepository = new SICustomerRepository();
            var productRepository = new SIProductRepository();
            var orderRepository = new SIOrderRepository();

            var salesManagement = new SalesAppService(adapter, productRepository, orderRepository,customerRepository);

            var dto = new SoftwareDTO()
            {
                Title = "The title",
                Description = "",
                LicenseCode = "license",
                AmountInStock = 10,
                UnitPrice = -1//this is a not valid value
            };

            //Act
            var result = salesManagement.AddNewSoftware(dto);
        }
コード例 #33
0
        public void AddNewOrderWithTotalGreaterCustomerCreditReturnNull()
        {
            //Arrange 
            var productRepository = new SIProductRepository();
            var orderRepository = new SIOrderRepository();
            var customerRepository = new SICustomerRepository();
            var country = new Country("spain", "es-ES");
            country.GenerateNewIdentity();

            customerRepository.GetGuid = (guid) =>
            {
                //default credit limit is 1000
                var customer = CustomerFactory.CreateCustomer("Jhon", "El rojo","+34343","company", country, new Address("city", "zipCode", "addressline1", "addressline2"));

                return customer;
            };


            orderRepository.UnitOfWorkGet = () =>
            {
                var uow = new SIUnitOfWork();
                uow.Commit = () => { };

                return uow;
            };
            orderRepository.AddOrder = (order) => { };

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            var dto = new OrderDTO()
            {
                CustomerId = Guid.NewGuid(),
                ShippingAddress = "Address",
                ShippingCity = "city",
                ShippingName = "name",
                ShippingZipCode = "zipcode",
                OrderLines = new List<OrderLineDTO>()
                {
                    new OrderLineDTO(){ProductId = Guid.NewGuid(),Amount = 1,Discount = 0,UnitPrice = 2000}
                }
            };

            //act
            var result = salesManagement.AddNewOrder(dto);

            //assert
            Assert.IsNull(result);
        }
コード例 #34
0
        public void AddNewOrderWithoutCustomerIdThrowArgumentException()
        {
            //Arrange 
            
            var customerRepository = new SICustomerRepository();
            var productRepository = new SIProductRepository();
            var orderRepository = new SIOrderRepository();

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            var order = new OrderDTO() // order is not valid when customer id is empty
            {
                CustomerId = Guid.Empty
            };

            //act
            var result = salesManagement.AddNewOrder(order);

            //assert
            Assert.IsNull(result);
        }
コード例 #35
0
        public void ConstructorThrowExceptionIfCustomerRepositoryDependencyIsNull()
        {
            //Arrange
            SICustomerRepository customerRepository = null;
            var orderRepository = new SIOrderRepository();
            var productRepository = new SIProductRepository();

            //Act
            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);
        }
コード例 #36
0
        public void FindProductsInPageReturnNullWhenPageIsInvalid()
        {
            //Arrange
            var adapter = PrepareTypeAdapter();
            var customerRepository = new SICustomerRepository();
            var productRepository = new SIProductRepository();
            var orderRepository = new SIOrderRepository();

            var salesManagement = new SalesAppService(adapter, productRepository, orderRepository,customerRepository);

            //act
            var resultInvalidPageIndex = salesManagement.FindProducts(-1, 1);
            var resultInvalidPageCount = salesManagement.FindProducts(0, 0);

            //Assert
            Assert.IsNull(resultInvalidPageIndex);
            Assert.IsNull(resultInvalidPageCount);
        }
コード例 #37
0
        public void FindOrdersInDateRangeReturnNullWhenNoData()
        {
            //Arrange

            var customerRepository = new SICustomerRepository();
            var productRepository = new SIProductRepository();
            var orderRepository = new SIOrderRepository();
            orderRepository.AllMatchingISpecificationOfOrder = (spec) =>
            {
                return new List<Order>();
            };

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            //act
            var result = salesManagement.FindOrders(DateTime.Now.AddDays(-2), DateTime.Now.AddDays(+2));


            //Assert
            Assert.IsNull(result);
        }
コード例 #38
0
        public void FindProductsByFilterMaterializeResults()
        {
            //Arrange
            var adapter = PrepareTypeAdapter();
            var customerRepository = new SICustomerRepository();
            var productRepository = new SIProductRepository();
            var orderRepository = new SIOrderRepository();
            productRepository.AllMatchingISpecificationOfProduct = (spec) =>
            {
                return new List<Product>()
                {
                    new Book(){Id= Guid.NewGuid(),Title = "title",UnitPrice = 10,Description ="description",ISBN ="isbn",Publisher ="publisher"},
                    new Software(){Id= Guid.NewGuid(),Title = "title",UnitPrice = 10,Description ="description",LicenseCode ="license code"},
                };
            };

            var salesManagement = new SalesAppService(adapter, productRepository, orderRepository,customerRepository);

            //act
            var result = salesManagement.FindProducts("filter text");

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count == 2);
        }
コード例 #39
0
        public void FindProductsInPageThrowExceptionWhenPageIsInvalid()
        {
            //Arrange
            
            var customerRepository = new SICustomerRepository();
            var productRepository = new SIProductRepository();
            var orderRepository = new SIOrderRepository();

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            //act
            var resultInvalidPageIndex = salesManagement.FindProducts(-1, 1);
        }
コード例 #40
0
        public void FindOrdersInPageMaterializeResults()
        {
            //Arrange
            var adapter = PrepareTypeAdapter();
            var customerRepository = new SICustomerRepository();
            var productRepository = new SIProductRepository();
            var orderRepository = new SIOrderRepository();
            orderRepository.GetPagedInt32Int32ExpressionOfFuncOfOrderKPropertyBoolean<DateTime>((index, count, order, ascending) =>
            {
                return new List<Order>()
                {
                    new Order(){Id = Guid.NewGuid(),CustomerId = Guid.NewGuid()}
                };
            });
            var salesManagement = new SalesAppService(adapter, productRepository, orderRepository,customerRepository);

            //act
            var result = salesManagement.FindOrders(0, 1);

            //Assert

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Any());
        }
コード例 #41
0
        public void FindOrdersInDateRangeMaterializeResults()
        {
            //Arrange
            
            var customerRepository = new SICustomerRepository();
            var productRepository = new SIProductRepository();
            var orderRepository = new SIOrderRepository();

            orderRepository.AllMatchingISpecificationOfOrder = (spec) =>
            {
                var order = new Order();
                order.GenerateNewIdentity();
                order.SetTheCustomerReferenceForThisOrder(Guid.NewGuid());

                return new List<Order>()
                {
                    order
                };
            };

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            //act
            var result = salesManagement.FindOrders(DateTime.Now.AddDays(-2), DateTime.Now.AddDays(-1));

            //Assert

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Any());

        }
コード例 #42
0
        public void FindOrderReturnNullIfCustomerIdIsEmpty()
        {
            //Arrange
            var adapter = PrepareTypeAdapter();
            var customerRepository = new SICustomerRepository();
            var productRepository = new SIProductRepository();
            var orderRepository = new SIOrderRepository();

            var salesManagement = new SalesAppService(adapter, productRepository, orderRepository,customerRepository);

            //act
            var result = salesManagement.FindOrders(Guid.Empty);

            //Assert
            Assert.IsNull(result);
        }
コード例 #43
0
        public void FindOrdersInPageMaterializeResults()
        {
            //Arrange
            
            var customerRepository = new SICustomerRepository();
            var productRepository = new SIProductRepository();
            var orderRepository = new SIOrderRepository();
            orderRepository.GetPagedInt32Int32ExpressionOfFuncOfOrderKPropertyBoolean<DateTime>((index, count, order, ascending) =>
            {
                var item = new Order();
                item.GenerateNewIdentity();
                item.SetTheCustomerReferenceForThisOrder(Guid.NewGuid());

                return new List<Order>()
                {
                    item
                };
            });
            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            //act
            var result = salesManagement.FindOrders(0, 1);

            //Assert

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Any());

        }
コード例 #44
0
        public void AddNewValidOrderReturnAddedOrder()
        {
            //Arrange
            var adapter = PrepareTypeAdapter();

            var productRepository = new SIProductRepository();
            var orderRepository = new SIOrderRepository();
            var customerRepository = new SICustomerRepository();
            customerRepository.GetGuid = (guid) =>
            {
                //default credit limit is 1000
                var customer = CustomerFactory.CreateCustomer("Jhon", "El rojo", Guid.NewGuid(), new Address("city", "zipCode", "addressline1", "addressline2"));
                customer.Id = IdentityGenerator.NewSequentialGuid();

                return customer;
            };

            orderRepository.UnitOfWorkGet = () =>
            {
                var uow = new SIUnitOfWork();
                uow.Commit = () => { };

                return uow;
            };
            orderRepository.AddOrder = (order) => { };

            var salesManagement = new SalesAppService(adapter, productRepository, orderRepository,customerRepository);

            var dto = new OrderDTO()
            {
                CustomerId = Guid.NewGuid(),
                ShippingAddress = "Address",
                ShippingCity = "city",
                ShippingName = "name",
                ShippingZipCode = "zipcode",
                OrderLines = new List<OrderLineDTO>()
                {
                    new OrderLineDTO(){ProductId = Guid.NewGuid(),Amount = 1,Discount = 0,UnitPrice = 20}
                }
            };

            //act
            var result = salesManagement.AddNewOrder(dto);

            //assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Id != Guid.Empty);
            Assert.AreEqual(result.ShippingAddress, dto.ShippingAddress);
            Assert.AreEqual(result.ShippingCity, dto.ShippingCity);
            Assert.AreEqual(result.ShippingName, dto.ShippingName);
            Assert.AreEqual(result.ShippingZipCode, dto.ShippingZipCode);
            Assert.IsTrue(result.OrderLines.Count == 1);
            Assert.IsTrue(result.OrderLines.All(ol=>ol.Id != Guid.Empty));
        }
コード例 #45
0
        public void FindOrdersMaterializeResultsIfCustomerExist()
        {
            //Arrange
            var customerRepository = new SICustomerRepository();
            var productRepository = new SIProductRepository();
            var orderRepository = new SIOrderRepository();
            orderRepository.GetFilteredExpressionOfFuncOfOrderBoolean = (filter) =>
            {
                var orders = new List<Order>();
                var customer = new Customer();
                customer.ChangeCurrentIdentity(Guid.NewGuid());
                orders.Add(OrderFactory.CreateOrder(customer, "name", "city", "address", "zipcode"));

                return orders;
            };

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            //act
            var result = salesManagement.FindOrders(Guid.NewGuid());


            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count == 1);
        }
コード例 #46
0
        public void AddNewOrderWithNotValidDataReturnNull()
        {
            //Arrange
            var adapter = PrepareTypeAdapter();
            var customerRepository = new SICustomerRepository();
            var productRepository = new SIProductRepository();
            var orderRepository = new SIOrderRepository();

            var salesManagement = new SalesAppService(adapter, productRepository, orderRepository,customerRepository);

            var order = new OrderDTO() // order is not valid when customer id is empty
            {
                CustomerId = Guid.Empty
            };

            //act
            var result = salesManagement.AddNewOrder(order);

            //assert
            Assert.IsNull(result);
        }
コード例 #47
0
        public void FindProductsInPageMaterializeResults()
        {
            //Arrange
            var customerRepository = new SICustomerRepository();
            var productRepository = new SIProductRepository();
            var orderRepository = new SIOrderRepository();
            productRepository.GetPagedInt32Int32ExpressionOfFuncOfProductKPropertyBoolean<string>((index, count, order, ascending) =>
            {
                var book = new Book("title", "description","publisher","isbn");
                book.ChangeUnitPrice(10M);
                book.GenerateNewIdentity();

                var software = new Software("title", "description","license code");
                software.ChangeUnitPrice(10);
                software.GenerateNewIdentity();

                return new List<Product>()
                {
                    book,
                    software
                };
            });


            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            //act
            var result = salesManagement.FindProducts(0, 2);


            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count == 2);
        }