Beispiel #1
0
        public void ShouldApproveWhenOrderHasLines()
        {
            var nextMonth = DateTime.Today.AddMonths(1);

            Order order = new(
                postingDate : DateTime.Today,
                deliveryDate : nextMonth,
                observation : "This order has an order item",
                customer : CustomerTests.GetCustomer());

            var product = ProductTests.GetProduct();

            var orderLine = new OrderLine(
                quantity: product.CombinedQuantity,
                unitaryPrice: product.CombinedPrice,
                additionalCosts: product.AdditionalCosts,
                product: product);

            order.AddOrderLine(orderLine);

            order.Approve();

            Assert.IsTrue(order.Valid);
            Assert.AreEqual(OrderStatus.Approved, order.Status);
            Assert.AreEqual(0, order.Notifications.Count);
        }
Beispiel #2
0
        public void ShouldReturnSucessWhenRemoveAllOrderLines()
        {
            var nextMonth = DateTime.Today.AddMonths(1);

            Order order = new(
                postingDate : DateTime.Today,
                deliveryDate : nextMonth,
                observation : "This sales order has no items",
                customer : CustomerTests.GetCustomer());

            var product = ProductTests.GetProduct();

            var orderLine = new OrderLine(
                quantity: product.CombinedQuantity,
                unitaryPrice: product.CombinedPrice,
                additionalCosts: product.AdditionalCosts,
                product: product);

            order.AddOrderLine(orderLine);

            order.RemoveOrderLine(orderLine);

            Assert.IsTrue(order.Valid);
            Assert.AreEqual(0, order.OrderLines.Count);
        }
Beispiel #3
0
        public void ShouldReturnSucessWhenEditOrderLineWithCorrectInputsData()
        {
            var product = ProductTests.GetProduct();

            OrderLine orderLine = new(
                quantity : product.CombinedQuantity,
                unitaryPrice : product.CombinedPrice,
                additionalCosts : product.AdditionalCosts,
                product : product);

            int     updatedQuantity        = 30000;
            decimal updatedUnitaryPrice    = 0.85m;
            decimal updatedAdditionalCosts = 0;

            Product updatedProduct = new(
                name : "COQUILHA OVAL 2",
                ncmCode : "84804910",
                combinedPrice : updatedUnitaryPrice,
                additionalCosts : updatedAdditionalCosts,
                combinedQuantity : updatedQuantity,
                details : "BANHO DE ZINCO",
                customerId : product.CustomerId);

            orderLine.Edit(
                quantity: updatedQuantity,
                unitaryPrice: updatedUnitaryPrice,
                additionalCosts: updatedAdditionalCosts,
                product: updatedProduct);

            Assert.IsTrue(orderLine.Valid);
            Assert.AreEqual(updatedQuantity, orderLine.Quantity);
            Assert.AreEqual(updatedUnitaryPrice, orderLine.UnitaryPrice);
            Assert.AreEqual(updatedAdditionalCosts, orderLine.AdditionalCosts);
            Assert.AreEqual(updatedProduct, orderLine.Product);
        }
Beispiel #4
0
        public void ShouldReturnErrorWhenEditOrderWithPostingDateBiggerThanDeliveryDate()
        {
            var nextMonth = DateTime.Today.AddMonths(1);

            Order order = new(
                postingDate : DateTime.Today,
                deliveryDate : nextMonth,
                observation : string.Empty,
                customer : CustomerTests.GetCustomer());

            var product = ProductTests.GetProduct();

            var orderLine = new OrderLine(
                quantity: product.CombinedQuantity,
                unitaryPrice: product.CombinedPrice,
                additionalCosts: product.AdditionalCosts,
                product: product);

            order.AddOrderLine(orderLine);

            DateTime updatedDeliveryDate = DateTime.Today.AddDays(7);
            DateTime updatedPostingDate  = updatedDeliveryDate.AddMonths(1);
            string   updatedObservation  = "This order has Posting Date bigger than Delivery Date. When Edited";

            order.Edit(
                postingDate: updatedPostingDate,
                deliveryDate: updatedDeliveryDate,
                observation: updatedObservation);

            Assert.IsFalse(order.Valid);
            Assert.AreEqual(1, order.Notifications.Count);
        }
Beispiel #5
0
        public void ShouldReturnSucessWhenEditOrderWithCorrectInputsData()
        {
            var nextMonth = DateTime.Today.AddMonths(1);

            Order order = new(
                postingDate : DateTime.Today,
                deliveryDate : nextMonth,
                observation : string.Empty,
                customer : CustomerTests.GetCustomer());

            var product = ProductTests.GetProduct();

            var orderLine = new OrderLine(
                quantity: product.CombinedQuantity,
                unitaryPrice: product.CombinedPrice,
                additionalCosts: product.AdditionalCosts,
                product: product);

            order.AddOrderLine(orderLine);

            DateTime updatedPostingDate  = DateTime.Today.AddDays(7);
            DateTime updatedDeliveryDate = updatedPostingDate.AddMonths(1);
            string   updatedObservation  = "Sorry, this sales order should be created next week.";


            order.Edit(
                postingDate: updatedPostingDate,
                deliveryDate: updatedDeliveryDate,
                observation: updatedObservation);

            Assert.AreEqual(order.PostingDate, updatedPostingDate);
            Assert.AreEqual(order.DeliveryDate, updatedDeliveryDate);
            Assert.AreEqual(order.Observation, updatedObservation);
            Assert.IsTrue(order.Valid);
        }
Beispiel #6
0
        public void ShouldNotBeAbleToBillWhenOrderHasAnLineAndWasNotApproved()
        {
            var nextMonth = DateTime.Today.AddMonths(1);

            Order order = new(
                postingDate : DateTime.Today,
                deliveryDate : nextMonth,
                observation : "This sales order can be invoiced",
                customer : CustomerTests.GetCustomer());

            var product = ProductTests.GetProduct();

            var orderLine = new OrderLine(
                quantity: product.CombinedQuantity,
                unitaryPrice: product.CombinedPrice,
                additionalCosts: product.AdditionalCosts,
                product: product);

            order.AddOrderLine(orderLine);

            bool expected = false;
            bool actual   = order.CanBillThisOrder();

            Assert.IsTrue(order.Valid);
            Assert.AreEqual(OrderStatus.Open, order.Status);
            Assert.AreEqual(expected, actual);
        }
Beispiel #7
0
        public void ShouldReturnErrorWhenTryCancelAnOrderWithApprovedStatus()
        {
            var nextMonth = DateTime.Today.AddMonths(1);

            Order order = new(
                postingDate : DateTime.Today,
                deliveryDate : nextMonth,
                observation : "Canceled Order",
                customer : CustomerTests.GetCustomer());

            var product = ProductTests.GetProduct();

            var orderLine = new OrderLine(
                quantity: product.CombinedQuantity,
                unitaryPrice: product.CombinedPrice,
                additionalCosts: product.AdditionalCosts,
                product: product);

            order.AddOrderLine(orderLine);

            order.Approve();
            order.Cancel();

            Assert.IsFalse(order.Valid);
            Assert.AreEqual(OrderStatus.Approved, order.Status);
            Assert.AreEqual(1, order.Notifications.Count);
        }
Beispiel #8
0
        public void ShouldCalculateTotalOrderWhenAddSomeLines(int quantityOrderItem)
        {
            var nextMonth = DateTime.Today.AddMonths(1);

            Order order = new(
                postingDate : DateTime.Today,
                deliveryDate : nextMonth,
                observation : "This order has some order item",
                customer : CustomerTests.GetCustomer());

            var product = ProductTests.GetProduct();

            var orderLine = new OrderLine(
                quantity: product.CombinedQuantity,
                unitaryPrice: product.CombinedPrice,
                additionalCosts: product.AdditionalCosts,
                product: product);

            for (int i = 0; i < quantityOrderItem; i++)
            {
                order.AddOrderLine(orderLine);
            }

            decimal expected = quantityOrderItem * (product.CombinedQuantity * (product.CombinedPrice + product.AdditionalCosts));

            Assert.IsTrue(order.Valid);
            Assert.AreEqual(expected, order.TotalOrder);
            Assert.AreEqual(0, order.Notifications.Count);
        }
Beispiel #9
0
        public void ShouldReturnErrorWhenOrderLineHasInvalidQuantity(int invalidQuantity)
        {
            var product = ProductTests.GetProduct();

            OrderLine orderLine = new (
                quantity : invalidQuantity,
                unitaryPrice : product.CombinedPrice,
                additionalCosts : product.AdditionalCosts,
                product : product);

            Assert.IsFalse(orderLine.Valid);
            Assert.AreEqual(1, orderLine.Notifications.Count);
        }
Beispiel #10
0
        public void ShouldReturnErrorWhenOrderLineHasNegativeUnitaryPrice()
        {
            var product = ProductTests.GetProduct();

            decimal invalidUnitaryPrice = -0.750m;

            OrderLine orderLine = new(
                quantity : product.CombinedQuantity,
                unitaryPrice : invalidUnitaryPrice,
                additionalCosts : product.AdditionalCosts,
                product : product);

            Assert.IsFalse(orderLine.Valid);
            Assert.AreEqual(1, orderLine.Notifications.Count);
        }