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 void throw_product_not_found()
        {
            // setp
            customerRepository
            .Setup(cr => cr.GetById(1))
            .Returns(CustomerMother.Random());

            productRepository
            .Setup(pr => pr.GetById(1))
            .Returns(It.IsAny <Product>());

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

            // act - val
            Assert.Throws <ProductNotFound>(() => 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);
        }
Ejemplo n.º 4
0
        public void Should_return_all_leases_for_a_specific_customer()
        {
            long customerId = CustomerMother.CreateCustomerRecord( );

            LeaseMother.CreateLeaseFor(customerId);

            IRichList <ISlipLease> leasesForCustomer = ListFactory.From(CreateSUT( ).AllLeasesFor(customerId));

            Assert.AreEqual(1, leasesForCustomer.Count);
        }
Ejemplo n.º 5
0
        public void Should_be_able_to_find_customer_by_username()
        {
            string username   = "******";
            long   customerId = CustomerMother.CreateCustomerRecordWith(username);

            ICustomer foundCustomer = CreateSUT( ).FindBy(username);

            Assert.AreEqual(customerId, foundCustomer.ID( ));
            Assert.AreEqual(username, foundCustomer.Registration( ).Username( ));
        }
Ejemplo n.º 6
0
        public void Should_return_3_boats()
        {
            long customerId = CustomerMother.CreateCustomerRecord( );

            BoatMother.AddBoatsFor(customerId);

            IRichList <IBoat> boats = ListFactory.From(CreateSUT( ).AllBoatsFor(customerId));

            Assert.AreEqual(3, boats.Count);
        }
        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);
            }
        }
Ejemplo n.º 8
0
        public void Should_be_able_to_insert_new_leases_for_customer()
        {
            long customerId = CustomerMother.CreateCustomerRecord( );

            IList <ISlipLease> leases = new List <ISlipLease>( );

            leases.Add(new SlipLease(new Slip(1000, null, 100, 100, true), LeaseDurations.Daily));

            ILeaseDataMapper mapper = CreateSUT( );

            mapper.Insert(leases, customerId);

            IRichList <ISlipLease> foundLeases = ListFactory.From(mapper.AllLeasesFor(customerId));

            Assert.AreEqual(1, foundLeases.Count);
        }
Ejemplo n.º 9
0
        public void Should_insert_new_boats_for_customer()
        {
            long          customerId = CustomerMother.CreateCustomerRecord( );
            IList <IBoat> boats      = CreateBoats( );

            IBoatDataMapper mapper = CreateSUT( );

            mapper.Insert(boats, customerId);

            IBoat thirdBoat = new Boat("reg3", "HONDA", new DateTime(1999, 1, 1), 300);

            boats.Add(thirdBoat);

            mapper.Update(boats, customerId);

            IRichList <IBoat> insertedBoats = ListFactory.From(mapper.AllBoatsFor(customerId));

            Assert.AreEqual(3, insertedBoats.Count);
            Assert.IsTrue(insertedBoats.Contains(thirdBoat));
        }
Ejemplo n.º 10
0
        public void Should_be_able_to_insert_new_boats_for_customer()
        {
            IBoat firstBoat  = new Boat("reg1", "TOYOTA", new DateTime(2001, 1, 1), 100);
            IBoat secondBoat = new Boat("reg2", "YAMAHA", new DateTime(2005, 1, 1), 200);

            IList <IBoat> boats = new List <IBoat>( );

            boats.Add(firstBoat);
            boats.Add(secondBoat);

            long            customerId = CustomerMother.CreateCustomerRecord( );
            IBoatDataMapper mapper     = CreateSUT( );

            mapper.Insert(boats, customerId);

            IRichList <IBoat> insertedBoats = ListFactory.From(mapper.AllBoatsFor(customerId));

            Assert.AreEqual(2, insertedBoats.Count);
            Assert.IsTrue(insertedBoats.Contains(firstBoat));
            Assert.IsTrue(insertedBoats.Contains(secondBoat));
        }
        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);
        }