Exemplo n.º 1
0
        // <summary>
        /// Starting point of factory design pattern demo
        /// </summary>
        public void Initiate()
        {
            Dictionary <string, int> products = new Dictionary <string, int>();
            string repeat = string.Empty;

            do
            {
                WriteLine("Enter prduct name to add in shopping cart");
                string productName = ReadLine();

                WriteLine("Choose the delievry speed");
                WriteLine("1 - Fast");
                WriteLine("2 - Normal");

                string choice = ReadLine();

                if (!int.TryParse(choice, out int deliverySpeed))
                {
                    throw new ArgumentException("Please enter integer only");
                }
                else if (deliverySpeed > 2 || deliverySpeed < 1)
                {
                    throw new ArgumentOutOfRangeException("Please enter the correct delivery method");
                }

                products.Add(productName, deliverySpeed);

                WriteLine("Want to add more products (Y|N)");
                repeat = ReadLine();
            } while (repeat.Equals("y", StringComparison.OrdinalIgnoreCase));

            if (products == null || !products.Any())
            {
                WriteLine("No product is added in cart to ship");
                return;
            }

            // Factory which cretes concrete objects
            VehicleFactory vehicleFactory = new ConcreteVehicleFactory();

            foreach (KeyValuePair <string, int> product in products)
            {
                // Get the actual concrete shipping vehicle object using factory
                IShippingVehicle shippingVehicle = vehicleFactory.GetShippingVehicle((DeliverySpeedEnum)product.Value);
                shippingVehicle.ShipProduct(product.Key);
                Thread.Sleep(2000);
            }

            WriteLine("\nAll products are shipped successfully");

            ReadKey();
        }
        public void DeliveryService_UnclesTruckDefaults()
        {
            //Arrange
            double costPerRefuel = 200;

            vehicle  = new Truck();
            delivery = new UnclesTruck(vehicle);
            //Act

            //Assert
            Assert.IsNotNull(delivery);
            Assert.IsNotNull(delivery.ShippingVehicle);
            Assert.AreEqual(delivery.CostPerRefuel, costPerRefuel);
        }
        public void DeliveryService_AirExpressDefaults()
        {
            //Arrange
            double costPerRefuel = 2000;

            vehicle  = new Plane();
            delivery = new AirExpress(vehicle);
            //Act

            //Assert
            Assert.IsNotNull(delivery);
            Assert.IsNotNull(delivery.ShippingVehicle);
            Assert.AreEqual(delivery.CostPerRefuel, costPerRefuel);
        }
Exemplo n.º 4
0
        public void DeliveryService_SnailServiceDefaults()
        {
            //Arrange
            double costPerRefuel = 2;

            vehicle  = new ShippingSnail();
            delivery = new SnailService(vehicle);
            //Act

            //Assert
            Assert.IsNotNull(delivery);
            Assert.IsNotNull(delivery.ShippingVehicle);
            Assert.AreEqual(delivery.CostPerRefuel, costPerRefuel);
        }
        public void ShippingVehicle_PlaneDefaults()
        {
            //Arrange
            sv = new Plane();
            uint MaxDistance, MaxWeight, TopSpeed;

            //Act
            MaxDistance = 5000;
            MaxWeight   = 1000;
            TopSpeed    = 200;
            //Assert
            Assert.AreEqual(MaxDistance, sv.MaxDistancePerRefuel);
            Assert.AreEqual(MaxWeight, sv.MaxWeight);
            Assert.AreEqual(TopSpeed, sv.TopSpeed);
        }
        public void ShippingVehicle_SnailDefaults()
        {
            //Arrange
            sv = new ShippingSnail();
            uint MaxDistance, MaxWeight, TopSpeed;

            //Act
            MaxDistance = 20;
            MaxWeight   = 1;
            TopSpeed    = 1;
            //Assert
            Assert.AreEqual(MaxDistance, sv.MaxDistancePerRefuel);
            Assert.AreEqual(MaxWeight, sv.MaxWeight);
            Assert.AreEqual(TopSpeed, sv.TopSpeed);
        }
        public void GetShippingService(string service)
        {
            switch (service)
            {
            case "Delivery Service":
                vehicle  = new Truck();
                delivery = new UnclesTruck(vehicle);
                break;

            case "Shipping Service":
                vehicle  = new Plane();
                delivery = new AirExpress(vehicle);
                break;

            case "Shipping Vehicle":
                vehicle  = new ShippingSnail();
                delivery = new SnailService(vehicle);
                break;
            }
        }
 public SnailService(IShippingVehicle vehicle) : base(vehicle)
 {
 }
Exemplo n.º 9
0
 public SnailService(IShippingVehicle vehicle) : base(vehicle)
 {
     CostPerRefuel = 2;
 }
Exemplo n.º 10
0
 public AirExpress(IShippingVehicle vehicle) : base(vehicle)
 {
     costPerRefuel = 2000;
     NameOfService = "Air Express";
 }
Exemplo n.º 11
0
 public AirExpress(IShippingVehicle vehicle) : base(vehicle)
 {
 }
Exemplo n.º 12
0
 public AirExpress(IShippingVehicle vehicle) : base(vehicle)
 {
     CostPerRefuel = 2000;
 }
Exemplo n.º 13
0
 public SnailService(IShippingVehicle vehicle) : base(vehicle)
 {
     name              = "Snail Service";
     costPerRefuel     = 2;
     this.shippingRate = 0.0;
 }
Exemplo n.º 14
0
 public SnailService(IShippingVehicle vehicle) : base(vehicle)
 {
     costPerRefuel = 2;
     NameOfService = "Snail Service";
 }
Exemplo n.º 15
0
 public UnclesTruck(IShippingVehicle vehicle) : base(vehicle)
 {
     name          = "Uncles Truck";
     costPerRefuel = 200;
     shippingRate  = .15;
 }
Exemplo n.º 16
0
 public DeliveryService(IShippingVehicle vehicle)
 {
     shippingVehicle = vehicle;
 }
Exemplo n.º 17
0
 public UnclesTruck(IShippingVehicle vehicle) : base(vehicle)
 {
     costPerRefuel = 200;
     NameOfService = "Uncles Truck";
 }
Exemplo n.º 18
0
 public UnclesTruck(IShippingVehicle vehicle) : base(vehicle)
 {
     this.costPerRefuel = 200;
 }
Exemplo n.º 19
0
 public AirExpress(IShippingVehicle vehicle) : base(vehicle)
 {
     name          = "Air Express";
     costPerRefuel = 2000;
     shippingRate  = .15;
 }
 public UnclesTruck(IShippingVehicle vehicle) : base(vehicle)
 {
 }