示例#1
0
        public void valid_insert_product()
        {
            // setp
            repository
            .Setup(rp => rp.Insert(It.IsAny <Product>()))
            .Verifiable();

            var productRandom = ProductMother.MartilloProductWithStock();

            // act
            var productCreate = createManager.Create(
                description: productRandom.Description,
                name: productRandom.Name,
                friendlyName: productRandom.FriendlyName,
                price: productRandom.Price,
                tax: productRandom.Tax,
                initialStock: new QuantityValue(100, "UM"),
                taxDescription: productRandom.TaxDescription)

                                // val
                                .Should()
                                .BeOfType <ProductViewModel>();

            repository.Verify();
        }
        public void throw_outstock_invoice()
        {
            // setp
            customerRepository
            .Setup(cr => cr.GetById(1))
            .Returns(CustomerMother.Random());

            productRepository
            .Setup(pr => pr.GetById(1))
            .Returns(ProductMother.TaladroProductWitMinStock());

            var products = new List <ProductInputModel>()
            {
                new ProductInputModel()
                {
                    ProductId = 1,
                    Quantity  = new QuantityValue(10, "UM"),
                }
            };

            // act - val
            Assert.Throws <OutStock>(() => createManager.Create(
                                         date: DateTime.Now,
                                         expirationDate: DateTime.Now.AddDays(2),
                                         totalReceived: new MonetaryValue(100, "CO"),
                                         customerId: 1,
                                         productInputs: products));
        }
        public static Invoice StandardInvoice()
        {
            var invoice = new Invoice(
                DateTime.Now,
                DateTime.Now,
                new MonetaryValue(100000, "CO"),
                CustomerMother.Random());

            var product = ProductMother.MartilloProductWithStock();

            invoice.AddItem(
                name: product.Name,
                productId: product.Id,
                taxDescription: product.TaxDescription,
                unitPrice: product.Price,
                unitTax: product.Tax,
                quantity: new QuantityValue(2, "UM"));

            product = ProductMother.TaladroProductWithStock();
            invoice.AddItem(
                name: product.Name,
                productId: product.Id,
                taxDescription: product.TaxDescription,
                unitPrice: product.Price,
                unitTax: product.Tax,
                quantity: new QuantityValue(1, "UM"));

            return(invoice);
        }
        protected override void Given()
        {
            base.Given();

            var model = ProductMother.Simple();

            _model = SUT.AddAsync(AdminUserId, model).Result;
            Assert.IsNotNull(SUT.GetAsync(AdminUserId, _model.Id).Result);
        }
        public void valid_adjust_products_stock()
        {
            // setp
            customerRepository
            .Setup(cr => cr.GetById(1))
            .Returns(CustomerMother.Random());

            productRepository
            .Setup(pr => pr.GetById(1))
            .Returns(ProductMother.StandardProductWith1000Stock());

            var productsUpdates = new List <Product>();

            productRepository
            .Setup(pr => pr.Update(It.IsAny <IEnumerable <Product> >()))
            .Callback <IEnumerable <Product> >(products =>
            {
                productsUpdates.AddRange(products);
            });

            var products = new List <ProductInputModel>()
            {
                new ProductInputModel()
                {
                    ProductId = 1,
                    Quantity  = new QuantityValue(10, "UM"),
                }
            };

            // act
            var invoice = createManager.Create(
                date: DateTime.Now,
                expirationDate: DateTime.Now.AddDays(2),
                totalReceived: new MonetaryValue(100, "CO"),
                customerId: 1,
                productInputs: products);

            // val
            foreach (var item in invoice.Items)
            {
                var stockExpected = new QuantityValue(
                    ProductMother.StandardProductWith1000Stock().StockQuantity.Value - item.Quantity.Value, "UM");

                var product = productsUpdates.FirstOrDefault(p => p.Id == item.ProductId);

                product
                .Should()
                .NotBeNull();

                product
                .StockQuantity
                .Should()
                .Be(stockExpected);
            }
        }
        public void valid_delete_product()
        {
            repository
            .Setup(rp => rp.GetById(1))
            .Returns(ProductMother.MartilloProductWithStock());

            // act
            deleteManager.Delete(1);

            //
            repository.Verify(rp => rp.Delete(It.IsAny <Product>()), Times.Once);
        }
        protected override void Given()
        {
            base.Given();

            _models = new List <Product>
            {
                ProductMother.Typical(),
                    ProductMother.Typical()
            };

            _originalCount = SUT.CountAsync().Result;
        }
        public async void It_should_return_a_product()
        {
            var id = ProductIdMother.Create();
            var expectedProduct = ProductMother.Create();

            productRepository.Setup(x => x.Search(It.IsAny <ProductId>())).Returns(Task.FromResult(expectedProduct));

            var actualProduct = await productFinder.Execute(id).ConfigureAwait(false);

            productRepository.Verify(r => r.Search(id), Times.Once);
            Assert.Same(expectedProduct, actualProduct);
        }
示例#9
0
        public void valid_update_throw_not_found_product()
        {
            // setp
            var product = ProductMother.MartilloProductWithStock();

            repository
            .Setup(rp => rp.GetById(It.IsAny <int>()))
            .Returns(It.IsAny <Product>());

            // act - Val
            Assert.Throws <ProductNotFound>(() => updateManager.Update(product.Id));
        }
示例#10
0
        public void It_should_save_a_new_product()
        {
            var expectedProduct = ProductMother.Create();

            productSQLRepository.Save(expectedProduct).ConfigureAwait(false).GetAwaiter().GetResult();

            var task          = productSQLRepository.Search(expectedProduct.Id).ConfigureAwait(false);
            var actualProduct = task.GetAwaiter().GetResult();

            Assert.NotNull(actualProduct);
            Assert.Equal(actualProduct.Id.Value, expectedProduct.Id.Value);
        }
示例#11
0
        public async void It_should_delete_product()
        {
            var product = ProductMother.Create();
            var id      = ProductIdMother.Create();

            productRepository.Setup(x => x.Search(It.IsAny <ProductId>())).Returns(Task.FromResult(product));
            productRepository.Setup(x => x.Remove(It.IsAny <Product>()));

            await productDeleter.Execute(id).ConfigureAwait(false);

            productRepository.Verify(r => r.Search(id), Times.Once);
            productRepository.Verify(r => r.Remove(product), Times.Once);
        }
示例#12
0
        public void It_should_faild_when_product_not_exist()
        {
            var product = ProductMother.Create();
            var id      = ProductIdMother.Create();

            productRepository.Setup(x => x.Search(It.IsAny <ProductId>())).Returns(Task.FromResult <Product>(null));
            productRepository.Setup(x => x.Remove(It.IsAny <Product>()));


            var task = Assert.ThrowsAsync <Exception>(async() => await productDeleter.Execute(id).ConfigureAwait(false));

            Assert.Equal("Product not exist", task.Result.Message);
            productRepository.Verify(r => r.Search(id), Times.Once);
            productRepository.Verify(r => r.Remove(product), Times.Never);
        }
示例#13
0
        public void valid_search_by_id_products()
        {
            repository
            .Setup(rp => rp.GetById(1))
            .Returns(ProductMother.MartilloProductWithStock())
            .Verifiable();

            var product = searchByIdManager.Search(1);

            product
            .Should()
            .NotBeNull();

            repository.Verify();
        }
示例#14
0
        public async void it_should_rename_product()
        {
            var id       = ProductIdMother.Create();
            var product  = ProductMother.Create();
            var name_new = ProductNameMother.Create(name: "Rename product");

            productRepository.Setup(x => x.Search(It.IsAny <ProductId>())).Returns(Task.FromResult <Product>(product));
            productRepository.Setup(x => x.Modify(It.IsAny <Product>()));

            await productRenamer.Execute(id, name_new).ConfigureAwait(false);

            productRepository.Verify(r => r.Search(id), Times.Once);
            productRepository.Verify(r => r.Modify(product), Times.Once);
            Assert.Equal(name_new, product.Name);
        }
示例#15
0
        public void it_should_fail_when_the_product_no_exist()
        {
            var id       = ProductIdMother.Create();
            var product  = ProductMother.Create();
            var name_new = ProductNameMother.Create(name: "Rename product");

            productRepository.Setup(x => x.Search(It.IsAny <ProductId>())).Returns(Task.FromResult <Product>(null));
            productRepository.Setup(x => x.Modify(It.IsAny <Product>()));

            var task = Assert.ThrowsAsync <Exception>(async() => await productRenamer.Execute(id, name_new).ConfigureAwait(false));

            productRepository.Verify(r => r.Search(id), Times.Once);
            productRepository.Verify(r => r.Modify(product), Times.Never);
            Assert.Equal("Product not exist", task.Result.Message);
        }
示例#16
0
        public void valid_update_name_product()
        {
            // setp
            var product = ProductMother.MartilloProductWithStock();

            repository.Setup(rp => rp.GetById(It.IsAny <int>()))
            .Returns(product);
            var newName = "Martillo 2";

            // act
            var productUpdate = updateManager.Update(product.Id, name: newName);

            productUpdate
            .Name
            .Should()
            .Be(newName);
        }
示例#17
0
        public void valid_update_description_product()
        {
            // setp
            var product = ProductMother.MartilloProductWithStock();

            repository.Setup(rp => rp.GetById(It.IsAny <int>()))
            .Returns(product);
            var newDescription = "Nueva descripcion";

            // act
            var productUpdate = updateManager.Update(product.Id, description: newDescription);

            productUpdate
            .Description
            .Should()
            .Be(newDescription);
        }
示例#18
0
        public void valid_update_price_product()
        {
            // setp
            var product = ProductMother.MartilloProductWithStock();

            repository.Setup(rp => rp.GetById(It.IsAny <int>()))
            .Returns(product);
            var newPrice = new MonetaryValue(100, "CO");

            // act
            var productUpdate = updateManager.Update(product.Id, price: newPrice);

            productUpdate
            .Price
            .Should()
            .Be(newPrice);
        }
示例#19
0
        public void valid_initial_stock_product()
        {
            // setp
            repository
            .Setup(rp => rp.Insert(It.IsAny <Product>()));

            var productRandom   = ProductMother.MartilloProductWithStock();
            var initialQuantity = new QuantityValue(100, "UM");

            // act
            var productCreate = createManager.Create(
                description: productRandom.Description,
                name: productRandom.Name,
                friendlyName: productRandom.FriendlyName,
                price: productRandom.Price,
                tax: productRandom.Tax,
                initialStock: initialQuantity,
                taxDescription: productRandom.TaxDescription);

            // val
            productCreate
            .Should()
            .NotBeNull();

            productCreate
            .StockQuantity
            .Should().Be(initialQuantity);

            productCreate
            .StockQuantityHistories
            .Should()
            .NotBeEmpty();

            var firstHistory = productCreate.StockQuantityHistories.FirstOrDefault();

            firstHistory
            .Should()
            .NotBeNull();

            firstHistory
            .QuantityAdjustment
            .Should()
            .Be(initialQuantity);

            repository.Verify();
        }
示例#20
0
        public void valid_update_product()
        {
            // setp
            var product = ProductMother.MartilloProductWithStock();

            repository
            .Setup(rp => rp.GetById(It.IsAny <int>()))
            .Returns(product);

            repository
            .Setup(rp => rp.Update(It.IsAny <Product>()))
            .Verifiable();

            // act
            updateManager.Update(product.Id);

            // val
            repository.Verify();
        }
        public void valid_insert_invoice()
        {
            // setp
            var products = new List <ProductInputModel>()
            {
                new ProductInputModel()
                {
                    ProductId = 1,
                    Quantity  = new QuantityValue(1, "UM"),
                }
            };

            customerRepository
            .Setup(cr => cr.GetById(1))
            .Returns(CustomerMother.Random())
            .Verifiable();

            productRepository
            .Setup(pr => pr.GetById(It.IsAny <int>()))
            .Returns(ProductMother.StandardProductWith1000Stock())
            .Verifiable();

            // act
            createManager.Create(
                date: DateTime.Now,
                expirationDate: DateTime.Now.AddDays(2),
                totalReceived: new MonetaryValue(100, "CO"),
                customerId: 1,
                productInputs: products)

            // valitation
            .Should().As <InvoiceViewModel>();

            productRepository.Verify();
            productRepository.Verify();
            productRepository.Verify(pr => pr.Update(It.IsAny <IEnumerable <Product> >()), Times.AtLeastOnce);
            invoiceRepository.Verify(re => re.Insert(It.IsAny <Invoice>()), Times.AtLeastOnce);
        }
示例#22
0
        public void valid_update_tax_product()
        {
            // setp
            var product = ProductMother.MartilloProductWithStock();

            repository.Setup(rp => rp.GetById(It.IsAny <int>()))
            .Returns(product);
            var newTax         = new MonetaryValue(100, "CO");
            var taxDescription = "IVA 20% UP";

            // act
            var productUpdate = updateManager.Update(product.Id, tax: newTax, taxDescription: taxDescription);

            productUpdate
            .Tax
            .Should()
            .Be(newTax);

            productUpdate
            .TaxDescription
            .Should()
            .Be(taxDescription);
        }
        protected override void Given()
        {
            base.Given();

            _model = ProductMother.Typical();
        }