예제 #1
0
        public async Task AddOrderIncome(CreateViewModel orderModel)
        {
            // we create the date with the current date
            var dateOrderIncome = DateTime.Now;

            OrderIncome order = new OrderIncome
            {
                IdProvider = orderModel.IdProvider,
                IdUser     = orderModel.IdUser,
                Total      = orderModel.Total,
                State      = "Accept"
            };

            _context.OrderIncomes.Add(order);
            await _context.SaveChangesAsync();

            // Adding details to detailOrder
            var IdOrderIncome = order.IdOrderIncome;

            // We loop de property details in CreateViewModel to add every
            // detail in OrderDetail Table in the same method Add of OrderIncome
            foreach (var det in orderModel.Details)
            {
                OrderIncomeDetails detail = new OrderIncomeDetails
                {
                    IdOrderIncome = IdOrderIncome,
                    IdProduct     = det.IdProduct,
                    Amount        = det.Amount,
                    DueDate       = det.DueDate,
                    UnitCost      = det.UnitCost
                };
                _context.OrderIncomeDetails.Add(detail);
            }
            await _context.SaveChangesAsync();
        }
예제 #2
0
        public void SetRegistroBitacoraStatusOk()
        {
            //Arrange(Preparar)
            OrderIncome order = OrderFactory.CreateOrder(_customer, "", "", "");

            //Act(Actuar)
            order.SetRegistroBitacoraStatus();
            //Assert(Afirmar)
            order.OrderIncomeStatusId.ShouldBe(OrderIncomeStatus.RegistroBitacora.Id);
        }
예제 #3
0
        public void SetCompletadoStatusOk()
        {
            //Arrange(Preparar)
            OrderIncome order = OrderFactory.CreateOrder(_customer, "", "", "");

            //Act(Actuar)
            order.SetRegistroBitacoraStatus();
            order.SetDianStatus();
            order.SetVerificacionBitacoraStatus();
            order.SetCompletadoStatus();
            //Assert(Afirmar)
            order.OrderIncomeStatusId.ShouldBe(OrderIncomeStatus.Completado.Id);
        }
예제 #4
0
        public void SetCompletadoStatusFail()
        {
            //Arrange(Preparar)
            OrderIncome order = OrderFactory.CreateOrder(_customer, "", "", "");

            //Act(Actuar)
            // No se hacen los Estados previos

            //Assert(Afirmar)
            Should.Throw <Exception>(() =>
            {
                order.SetCompletadoStatus();
            });
        }
예제 #5
0
        public void SetRegistroBitacoraStatusFail()
        {
            //Arrange(Preparar)
            OrderIncome order = OrderFactory.CreateOrder(_customer, "", "", "");

            //Act(Actuar)
            order.SetRegistroBitacoraStatus();

            //Assert(Afirmar)
            Should.Throw <Exception>(() =>
            {
                order.SetRegistroBitacoraStatus();
            });
        }
예제 #6
0
        public void SetTheCustomerForThisOrderOk()
        {
            //Arrange(Preparar)
            OrderIncome order     = OrderFactory.CreateOrder(_customer, "", "", "");
            string      lastName  = "El rojo";
            string      firstName = "Jhon";
            string      telephone = "+34111111";
            string      company   = "company name";

            Customer customernew = CustomerFactory.CreateCustomer(firstName, lastName, telephone, company, "*****@*****.**", _country, new Address("city", "zipcode", "AddressLine1", "AddressLine2"));

            //Act(Actuar)
            order.CustomerId.ShouldBe(_customer.Id);
            order.SetTheCustomerForThisOrder(customernew);
            //Assert(Afirmar)
            order.CustomerId.ShouldBe(customernew.Id);
        }
예제 #7
0
        public OrderIncomeAggTest()
        {
            OrderIncome order     = new OrderIncome(); //Constructor EF
            string      lastName  = "El rojo";
            string      firstName = "Jhon";
            string      telephone = "+34111111";
            string      company   = "company name";

            _country = CountryFactory.CreateCountry("Spain", "es-ES");

            _customer = CustomerFactory.CreateCustomer(firstName, lastName, telephone, company, "*****@*****.**", _country, new Address("city", "zipcode", "AddressLine1", "AddressLine2"));

            for (int i = 0; i < 5; i++)
            {
                Product prod = ProductFactory.CreateProduct("product" + i, "description" + i);
                _products.Add(prod);
            }
        }
예제 #8
0
        public void SetTheCustomerReferenceForThisOrderFail()
        {
            //Arrange(Preparar)
            OrderIncome order     = OrderFactory.CreateOrder(_customer, "", "", "");
            string      lastName  = "El Negro";
            string      firstName = "Alex";
            string      telephone = "+34111111";
            string      company   = "company name";

            Customer customernew = CustomerFactory.CreateCustomer(firstName, lastName, telephone, company, "*****@*****.**", _country, new Address("city", "zipcode", "AddressLine1", "AddressLine2"));

            //Act(Actuar)
            order.CustomerId.ShouldBe(_customer.Id);

            //Assert(Afirmar)
            Should.Throw <Exception>(() =>
            {
                order.SetTheCustomerReferenceForThisOrder(Guid.Empty);
            });
        }
예제 #9
0
        public void AddOrderItemOk()
        {
            //Arrange(Preparar)
            OrderIncome order = OrderFactory.CreateOrder(_customer, "", "", "");

            MeasurentUnit measurentUnit = MeasurentUnitFactory.CreateMeasurentUnit(MeasurentUnitType.Longitud, "Litro");
            //Act(Actuar)
            Product product = _products.First();
            int     amount  = 1;

            order.AddOrderItem(product, measurentUnit, amount);

            //Assert(Afirmar)
            order.OrderIncomeLines.Count.ShouldBe(1);

            OrderIncomeLine xline = order.OrderIncomeLines
                                    .SingleOrDefault(o => (o.ProductId == product.Id && o.MeasurentUnitId == measurentUnit.Id));

            xline.ShouldNotBeNull();

            xline?.ProductId.ShouldBe(product.Id);
            xline?.Amount.ShouldBe(amount);
        }
예제 #10
0
        public async Task DeleteOrderIncome(OrderIncome order)
        {
            _context.OrderIncomes.Remove(order);

            await _context.SaveChangesAsync();
        }