public static PaymentInfoRowCarrier Build(OrderDiscountCarrier discount, Guid paymentInfoID, int index)
        {
            var result = new PaymentInfoRowCarrier(discount, paymentInfoID, index);

            result.TotalPrice     = Math.Abs(discount.DiscountAmount) * -1;
            result.TotalVatAmount = Math.Abs(discount.VATAmount) * -1;
            return(result);
        }
        public void Build_OrderDiscountCarrier(decimal totalPrice, decimal totalVat, decimal expectedPrice, decimal expectedVat)
        {
            var discount = new OrderDiscountCarrier
            {
                // We assume the TotalPrice was rounded by OrderTotalCalculator
                DiscountAmount = totalPrice,
                VATAmount      = totalVat
            };
            var paymentInfoID = Guid.NewGuid();

            var result = PaymentInfoRowBuilder.Build(discount, paymentInfoID, 1);

            Assert.Equal(expectedPrice, result.TotalPrice);
            Assert.Equal(expectedVat, result.TotalVatAmount);
        }
예제 #3
0
        public void CalculateTotalDiscount_VatPercentage_NoOrderRows_UseExistingVatPercentage()
        {
            var discount = new OrderDiscountCarrier
            {
                DiscountAmount = 1.672268908m,
                VATPercentage  = 0.32m
            };

            var order = new OrderCarrier();

            order.OrderDiscounts.Add(discount);

            sut.CalculateTotalDiscount(order);

            Assert.Equal(0.32m, discount.VATPercentage);
        }
예제 #4
0
        public void CalculateTotalDiscount_DiscountWithoutVAT_CalculateDiscountAmountWithVAT()
        {
            var discount = new OrderDiscountCarrier
            {
                DiscountAmount = 1.672268908m,
                VATPercentage  = 0.19m
            };

            var order = new OrderCarrier();

            order.OrderDiscounts.Add(discount);

            sut.CalculateTotalDiscount(order);

            Assert.Equal(1.99m, discount.DiscountAmountWithVAT);
        }
예제 #5
0
        public void CalculateTotalDiscount_CalledByCalculateFromCarrier()
        {
            var discount = new OrderDiscountCarrier
            {
                DiscountAmount = 1.672268908m,
                VATPercentage  = 0.19m
            };

            var order = new OrderCarrier();

            order.OrderDiscounts.Add(discount);
            order.OrderDiscounts.Add(discount);

            sut.CalculateFromCarrier(order, null);

            Assert.Equal(3.344m, order.TotalDiscount);
            Assert.Equal(0.636m, order.TotalDiscountVAT);
        }
예제 #6
0
        public void CalculateTotalDiscount_VatPercentage_NoOrderTotal_FallbackToOrderRows()
        {
            var discount = new OrderDiscountCarrier
            {
                DiscountAmount = 1.672268908m
            };

            var order = new OrderCarrier
            {
                OrderRows = new List <OrderRowCarrier>
                {
                    new OrderRowCarrier
                    {
                        TotalPrice     = 100,
                        TotalVATAmount = 10,
                        VATPercentage  = 0.1m
                    },
                    new OrderRowCarrier
                    {
                        TotalPrice     = 100,
                        TotalVATAmount = 20,
                        VATPercentage  = 0.2m
                    },
                    new OrderRowCarrier
                    {
                        TotalPrice     = 100,
                        TotalVATAmount = 0,
                        CarrierState   =
                        {
                            IsMarkedForCreating = false,
                            IsMarkedForDeleting = true
                        }
                    }
                }
            };

            order.OrderDiscounts.Add(discount);

            sut.CalculateTotalDiscount(order);

            Assert.Equal(0.15m, discount.VATPercentage);
        }
예제 #7
0
        public void CalculateTotalDiscount_SkipMarkedForDeletion()
        {
            var discount = new OrderDiscountCarrier
            {
                DiscountAmount = 1.672268908m,
                VATPercentage  = 0.19m,
                CarrierState   =
                {
                    IsMarkedForCreating = false,
                    IsMarkedForDeleting = true
                }
            };

            var order = new OrderCarrier();

            order.OrderDiscounts.Add(discount);

            sut.CalculateTotalDiscount(order);

            Assert.Equal(0, order.TotalDiscount);
        }