public void TestUPSShippingIs425(ShippingOptions shippingMethod, double expectedCost)
        {
            IShippingCostStrategy shippingCostStrategy;

            switch (shippingMethod)
            {
            case ShippingOptions.FedEx:
                shippingCostStrategy = new ShippingCostStrategyFedEx();
                break;

            case ShippingOptions.UPS:
                shippingCostStrategy = new ShippingCostStrategyUPS();
                break;

            case ShippingOptions.USPS:
                shippingCostStrategy = new ShippingCostStrategyUSPS();
                break;

            default:
                throw new ArgumentException($"Unknown shipping method: {shippingMethod}");
            }

            var shippingCalculator = new ShippingCostCalculatorService(shippingCostStrategy);
            var order = TestHelpers.CreateOrder(shippingMethod);
            var cost  = shippingCalculator.CalculateShippingCost(order);

            Assert.AreEqual((decimal)expectedCost, cost);
        }
        public void Return_3_When_Shipping_Via_Usps()
        {
            var service = new ShippingCostCalculatorService(
                new UspsShippingCostStrategy());

            var cost = service.CalculateShippingCost(new Order());

            Assert.Equal(3, cost);
        }
        public void Return_5_When_Shipping_Via_FedEx()
        {
            var service = new ShippingCostCalculatorService(
                new FedExShippingCostStrategy());

            var cost = service.CalculateShippingCost(new Order());

            Assert.Equal(5, cost);
        }
Пример #4
0
        public void When_shipping_via_UPS_The_shipping_cost_is_425()
        {
            var strategy = new UPSShippingCostStrategy();
            var shippingCalculatorService = new ShippingCostCalculatorService(strategy);
            var order = Mother.CreateOrder_UPS();
            var cost  = shippingCalculatorService.CalculateShippingCost(order);

            Assert.AreEqual(4.25d, cost);
        }
Пример #5
0
        public void When_shipping_via_FedEx_The_shipping_cost_is_5()
        {
            var strategy = new FedExShippingCostStrategy();
            var shippingCalculatorService = new ShippingCostCalculatorService(strategy);
            var order = Mother.CreateOrder_FedEx();
            var cost  = shippingCalculatorService.CalculateShippingCost(order);

            Assert.AreEqual(5.00d, cost);
        }
Пример #6
0
        static void Main(string[] args)
        {
            var service = new ShippingCostCalculatorService(new FakePriceStrategy());

            System.Console.WriteLine(service.Calculate(new Order()
            {
                Price = 1
            }));
        }
Пример #7
0
        public void When_shipping_via_FedEx_the_cost_is_500()
        {
            var strategy = new FedExStrategy();
            var shippingCalculatorService = new ShippingCostCalculatorService(strategy);
            var order = new Order();
            //var order = Mother.CreateOrder_UPS();
            var cost = shippingCalculatorService.CalculateShippingCost(order);

            Assert.AreEqual(5.00, cost);
            Assert.AreEqual(1, order.Id);
        }
Пример #8
0
        static void executeStrategy()
        {
            var strategy = new FedExShippingCostStrategy();
            ShippingCostCalculatorService shippingCostCalculatorService = new ShippingCostCalculatorService(strategy);
            var order = new Order()
            {
                ShippingMethod = "FedEx",
                Destination    = "1234 Desmesa St. Makati City philippines",
                Origin         = "123 Linoln St. America"
            };

            var cost = shippingCostCalculatorService.CalculateShippingCost(order);

            Console.WriteLine("Shipping Method: " + order.ShippingMethod);
            Console.WriteLine("Destination: " + order.Destination);
            Console.WriteLine("Origin: " + order.Origin);

            Console.WriteLine("Cost: " + cost);
            Console.ReadKey();
        }
Пример #9
0
        public static void Main(string[] args)
        {
            Func <Order, double> fedExStrategy = CalcForFedEx;
            Func <Order, double> upsStrategy   = delegate(Order order) { return(4.00d); };
            Func <Order, double> uspsStrategy  = order => 3.25d;

            Order theOrder = Mother.CreateOrder();

            var calculatorService = new ShippingCostCalculatorService();

            Console.WriteLine("FedEx Shipping Cost: " +
                              calculatorService.CalculateShippingCost(theOrder, fedExStrategy));

            Console.WriteLine("UPS Shipping Cost: " +
                              calculatorService.CalculateShippingCost(theOrder, upsStrategy));

            Console.WriteLine("USPS Shipping Cost: " +
                              calculatorService.CalculateShippingCost(theOrder, uspsStrategy));

            Console.ReadKey();
        }
Пример #10
0
        public DetailedOrderDto CheckOutCart(Guid userId, string address)
        {
            try
            {
                OrderSet orderSet;
                var      orderProducts         = new List <OrderProductSet>();
                var      ShipmentToAddressCost = ShippingCostCalculatorService.Calculate(address);

                //Moving the user cart to new "PAID" order
                var userCart = DreamerDbContext.CartItems.Where(ci => ci.IsValid && ci.DreamerUserId == userId).Include(ci => ci.Product).AsEnumerable();
                if (!userCart.Any())
                {
                    return(null);
                }
                foreach (var item in userCart)
                {
                    var orderProductSet = new OrderProductSet
                    {
                        ProductId          = item.ProductId,
                        DiscountPercentage = item.Product.DiscountPercentage,
                        OneItemPrice       = item.Product.Price,
                        Quantity           = item.Quantity,
                        DiscountValue      = item.Product.Price * item.Quantity * item.Product.DiscountPercentage / 100
                    };
                    orderProductSet.NetPrice = (orderProductSet.OneItemPrice * orderProductSet.Quantity) - orderProductSet.DiscountValue;
                    orderProducts.Add(orderProductSet);
                }
                orderSet = new OrderSet
                {
                    PaymentDateTime       = DateTimeOffset.UtcNow,
                    DreamerUserId         = userId,
                    Status                = Models.Enums.OrderStatus.Paid,
                    NetItemsPrice         = orderProducts.Sum(op => op.NetPrice),
                    NetItemsDiscountValue = orderProducts.Sum(op => op.DiscountValue),
                    OrderProducts         = orderProducts,
                    OrderShipment         = new OrderShipmentSet {
                        Address = address, ShipmentCost = ShipmentToAddressCost
                    },
                    FreeDelivery = userCart.Any(ci => ci.Product.FreeDelivary)
                };

                //One free-shipping product in the card is enough to make the whole card shipment for free
                if (orderSet.FreeDelivery)
                {
                    orderSet.OrderShipment.ShipmentCost = 0;
                }
                else
                {
                    orderSet.OrderShipment.ShipmentCost = ShipmentToAddressCost;
                }

                //Calculating the total for the order
                orderSet.Total = orderSet.NetItemsPrice + orderSet.OrderShipment.ShipmentCost;

                DreamerDbContext.Orders.Add(orderSet);
                DreamerDbContext.SaveChanges();

                //Clearing the cart
                ClearCart(userId);

                //Send email notification
                var userEmail = DreamerDbContext.DreamerUsers.Where(user => user.Id == userId).Select(c => c.Email).Single();
                if (EmailNotifierService.SendPaidSuccessfully(userEmail, orderSet))
                {
                    orderSet.EmailNotified = true;
                    DreamerDbContext.SaveChanges();
                }

                //Set as shipped the next day
                InternalHangfireService.EnqueueMarkOrderAsShipped(orderSet.Id);

                return(GetOrderDetails(orderSet.Id));
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
                return(null);
            }
        }