Esempio n. 1
0
        public void EnumerableProductToListProductDTOAdapter()
        {
            //Arrange
            var software = new Software("the title", "The description", "AB001");

            software.ChangeUnitPrice(10);
            software.IncrementStock(10);
            software.GenerateNewIdentity();

            var products = new List <Software>()
            {
                software
            };

            //Act
            ITypeAdapter adapter     = TypeAdapterFactory.CreateAdapter();
            var          productsDTO = adapter.Adapt <IEnumerable <Product>, List <ProductDTO> >(products);

            //Assert
            Assert.Equal(products[0].Id, productsDTO[0].Id);
            Assert.Equal(products[0].Title, productsDTO[0].Title);
            Assert.Equal(products[0].Description, productsDTO[0].Description);
            Assert.Equal(products[0].AmountInStock, productsDTO[0].AmountInStock);
            Assert.Equal(products[0].UnitPrice, productsDTO[0].UnitPrice);
        }
Esempio n. 2
0
        public void FindProductsByFilterMaterializeResults()
        {
            //Arrange
            var customerRepository = new Mock <ICustomerRepository>();
            var productRepository  = new Mock <IProductRepository>();
            var orderRepository    = new Mock <IOrderRepository>();
            Mock <ILogger <SalesAppService> > _mockLogger = new Mock <ILogger <SalesAppService> >();

            productRepository
            .Setup(x => x.AllMatching(It.IsAny <ISpecification <Product> >()))
            .Returns((ISpecification <Product> 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.Object, orderRepository.Object, customerRepository.Object, _mockLogger.Object);

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

            //Assert
            Assert.NotNull(result);
            Assert.True(result.Count == 2);
        }
        public void EnumerableSoftwareToListSoftwareDtoAdapter()
        {
            //Arrange
            var software = new Software("the title", "The description", "AB001");

            software.ChangeUnitPrice(10);
            software.IncrementStock(10);
            software.GenerateNewIdentity();

            var softwares = new List <Software>()
            {
                software
            };

            //Act
            var adapter      = TypeAdapterFactory.CreateAdapter();
            var softwaresDto = adapter.Adapt <IEnumerable <Software>, List <SoftwareDto> >(softwares);

            //Assert
            Assert.AreEqual(softwares[0].Id, softwaresDto[0].Id);
            Assert.AreEqual(softwares[0].Title, softwaresDto[0].Title);
            Assert.AreEqual(softwares[0].Description, softwaresDto[0].Description);
            Assert.AreEqual(softwares[0].AmountInStock, softwaresDto[0].AmountInStock);
            Assert.AreEqual(softwares[0].UnitPrice, softwaresDto[0].UnitPrice);
            Assert.AreEqual(softwares[0].LicenseCode, softwaresDto[0].LicenseCode);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }
        public void SoftwareToSoftwareDtoAdapter()
        {
            //Arrange
            var software = new Software("the title", "The description", "AB001");

            software.ChangeUnitPrice(10);
            software.IncrementStock(10);
            software.GenerateNewIdentity();
            //Act
            var adapter     = TypeAdapterFactory.CreateAdapter();
            var softwareDto = adapter.Adapt <Software, SoftwareDto>(software);

            //Assert
            Assert.AreEqual(software.Id, softwareDto.Id);
            Assert.AreEqual(software.Title, softwareDto.Title);
            Assert.AreEqual(software.Description, softwareDto.Description);
            Assert.AreEqual(software.AmountInStock, softwareDto.AmountInStock);
            Assert.AreEqual(software.UnitPrice, softwareDto.UnitPrice);
            Assert.AreEqual(software.LicenseCode, softwareDto.LicenseCode);
        }
        public void ProductToProductDtoAdapter()
        {
            //Arrange
            var product = new Software("the title", "The description", "AB001");

            product.ChangeUnitPrice(10);
            product.IncrementStock(10);
            product.GenerateNewIdentity();

            //Act
            var adapter    = TypeAdapterFactory.CreateAdapter();
            var productDto = adapter.Adapt <Product, ProductDto>(product);

            //Assert
            Assert.AreEqual(product.Id, productDto.Id);
            Assert.AreEqual(product.Title, productDto.Title);
            Assert.AreEqual(product.Description, productDto.Description);
            Assert.AreEqual(product.AmountInStock, productDto.AmountInStock);
            Assert.AreEqual(product.UnitPrice, productDto.UnitPrice);
        }
        /// <summary>
        /// <see cref="Microsoft.Samples.NLayerApp.Application.MainBoundedContext.ERPModule.Services.ISalesAppService"/>
        /// </summary>
        /// <param name="softwareDTO"><see cref="Microsoft.Samples.NLayerApp.Application.MainBoundedContext.ERPModule.Services.ISalesAppService"/></param>
        public SoftwareDTO AddNewSoftware(SoftwareDTO softwareDTO)
        {
            if (softwareDTO == null)
            {
                throw new ArgumentException(Messages.warning_CannotAddSoftwareWithNullInformation);
            }

            //Create the softare entity
            var newSoftware = new Software(softwareDTO.Title, softwareDTO.Description, softwareDTO.LicenseCode);

            //set unit price and stock
            newSoftware.ChangeUnitPrice(softwareDTO.UnitPrice);
            newSoftware.IncrementStock(softwareDTO.AmountInStock);

            //Assign the poid
            newSoftware.GenerateNewIdentity();

            //save software
            SaveProduct(newSoftware);

            //return software dto
            return(newSoftware.ProjectedAs <SoftwareDTO>());
        }
Esempio n. 9
0
        public void FindProductsInPageMaterializeResults()
        {
            //Arrange
            var customerRepository = new Mock <ICustomerRepository>();
            var productRepository  = new Mock <IProductRepository>();
            var orderRepository    = new Mock <IOrderRepository>();
            Mock <ILogger <SalesAppService> > _mockLogger = new Mock <ILogger <SalesAppService> >();

            productRepository
            .Setup(x => x.GetPaged <string>(It.IsAny <Int32>(), It.IsAny <Int32>(), It.IsAny <Expression <Func <Product, string> > >(), It.IsAny <bool>()))
            .Returns((Int32 index, Int32 count, Expression <Func <Product, string> > order, bool 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.Object, orderRepository.Object, customerRepository.Object, _mockLogger.Object);

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


            //Assert
            Assert.NotNull(result);
            Assert.True(result.Count == 2);
        }
        protected override void Seed(MainBCUnitOfWork unitOfWork)
        {
            /*
             * Countries agg
             */

            var spainCountry = new Country("Spain", "es-ES");

            spainCountry.ChangeCurrentIdentity(new Guid("32BB805F-40A4-4C37-AA96-B7945C8C385C"));

            var usaCountry = new Country("EEUU", "en-US");

            usaCountry.ChangeCurrentIdentity(new Guid("C3C82D06-6A07-41FB-B7EA-903EC456BFC5"));

            unitOfWork.Countries.Add(spainCountry);
            unitOfWork.Countries.Add(usaCountry);

            /*
             * Customers agg
             */

            var customerJhon = CustomerFactory.CreateCustomer("Jhon", "Jhon", "+34617", "company", spainCountry, new Address("Madrid", "280181", "Paseo de La finca", ""));

            customerJhon.ChangeCurrentIdentity(new Guid("43A38AC8-EAA9-4DF0-981F-2685882C7C45"));


            var customerMay = CustomerFactory.CreateCustomer("May", "Garcia", "+34617", "company", usaCountry, new Address("Seatle", "3332", "Alaskan Way", ""));

            customerMay.ChangeCurrentIdentity(new Guid("0CD6618A-9C8E-4D79-9C6B-4AA69CF18AE6"));


            unitOfWork.Customers.Add(customerJhon);
            unitOfWork.Customers.Add(customerMay);


            /*
             * Product agg
             */
            var book = new Book("The book title", "Any book description", "Krassis Press", "ABC");

            book.ChangeUnitPrice(40M);
            book.IncrementStock(2);

            book.ChangeCurrentIdentity(new Guid("44668EBF-7B54-4431-8D61-C1298DB50857"));

            var software = new Software("the new SO", "the software description", "XXXX0000--111");

            software.ChangeUnitPrice(100M);
            software.IncrementStock(3);
            software.ChangeCurrentIdentity(new Guid("D7E5C537-6A0C-4E19-B41E-3653F4998085"));

            unitOfWork.Products.Add(book);
            unitOfWork.Products.Add(software);

            /*
             * Orders agg
             */

            var orderA = OrderFactory.CreateOrder(customerJhon, "shipping name", "shipping city", "shipping address", "shipping zip code");

            orderA.ChangeCurrentIdentity(new Guid("3135513C-63FD-43E6-9697-6C6E5D8CE55B"));
            orderA.OrderDate = DateTime.Now;

            orderA.AddNewOrderLine(book.Id, 1, 40, 0);

            var orderB = OrderFactory.CreateOrder(customerMay, "shipping name", "shipping city", "shipping address", "shipping zip code");

            orderB.GenerateNewIdentity();
            orderB.OrderDate = DateTime.Now;

            orderB.AddNewOrderLine(software.Id, 3, 12, 0);

            unitOfWork.Orders.Add(orderA);
            unitOfWork.Orders.Add(orderB);

            /*
             * Bank Account agg
             */

            var         bankAccountNumberJhon = new BankAccountNumber("1111", "2222", "3333333333", "01");
            BankAccount bankAccountJhon       = BankAccountFactory.CreateBankAccount(customerJhon, bankAccountNumberJhon);

            bankAccountJhon.ChangeCurrentIdentity(new Guid("0343C0B0-7C40-444A-B044-B463F36A1A1F"));
            bankAccountJhon.DepositMoney(1000, "Open BankAccount");

            var         bankAccountNumberMay = new BankAccountNumber("4444", "5555", "3333333333", "02");
            BankAccount bankAccountMay       = BankAccountFactory.CreateBankAccount(customerMay, bankAccountNumberMay);

            bankAccountMay.GenerateNewIdentity();
            bankAccountJhon.DepositMoney(2000, "Open BankAccount");

            unitOfWork.BankAccounts.Add(bankAccountJhon);
            unitOfWork.BankAccounts.Add(bankAccountMay);
        }