Esempio n. 1
0
        public void MockTest()
        {
            //Arrange
            DefaultShippingService defaultService;

            var mockDeliveryService  = new Mock <IDeliveryService>();
            var mockProduct          = new Mock <IProduct>();
            var mockShippingLocation = new Mock <IShippingLocation>();

            //Act
            mockDeliveryService.Setup(dS => dS.CostPerRefuel).Equals(5);
            mockDeliveryService.Setup(dS => dS.ShippingVehicle).Equals(new CarrierPigeon());

            mockShippingLocation.Setup(sL => sL.StartZipCode).Equals("101011");
            mockShippingLocation.Setup(sL => sL.DestinationZipCode).Equals("7088");

            mockProduct.Setup(p => p.Name).Equals("Rubik's Cube");
            mockProduct.Setup(p => p.ShippingWeight).Equals(2);
            mockProduct.Setup(p => p.ShortDescription).Equals("A puzzle (in cube form)!");

            List <IProduct> products = new List <IProduct>();

            products.Add(mockProduct.Object);

            defaultService = new DefaultShippingService(mockDeliveryService.Object, products, mockShippingLocation.Object);
            double cost;

            cost = defaultService.ShippingCost();

            //Assert
            Assert.IsInstanceOfType(defaultService.DeliveryService, typeof(IDeliveryService));
            Assert.IsInstanceOfType(defaultService.ShippingLocation, typeof(IShippingLocation));
            Assert.IsInstanceOfType(defaultService.Products, typeof(List <IProduct>));
        }
Esempio n. 2
0
        public void TestShippingControllerCalculateShipping()
        {
            //Arrange
            DefaultShippingService deliveryService;
            var    mockDeliveryService  = new Mock <IDeliveryService>();
            var    mockProduct          = new Mock <IProduct>();
            var    mockShippingLocation = new Mock <IShippingLocation>();
            double cost;

            //Act
            mockDeliveryService.SetupGet(ds => ds.CostPerRefuel).Returns(1);
            mockDeliveryService.SetupGet(ds => ds.ShippingVehicle).Returns(new Truck());

            mockShippingLocation.SetupGet(sl => sl.StartZipCode).Returns(111111);
            mockShippingLocation.SetupGet(sl => sl.DestinationZipCode).Returns(60605);

            mockProduct.SetupGet(p => p.Name).Returns("Test Product");
            mockProduct.SetupGet(p => p.ShippingWeight).Returns(100);
            mockProduct.SetupGet(p => p.ShortDescription).Returns("Test Product Desc");

            List <IProduct> products = new List <IProduct>();

            products.Add(mockProduct.Object);

            deliveryService = new DefaultShippingService(mockDeliveryService.Object, products, mockShippingLocation.Object);

            cost = deliveryService.ShippingCost();

            //Assert

            Assert.IsNotNull(deliveryService);
            Assert.AreEqual(200, cost);
        }
        private void EnterBtn_Click(object sender, RoutedEventArgs e)
        {
            string zipcode = DestinationTxtb.Text;
            string service = ServiceTypecmbb.Text;

            Location newShippingLocation = new Location(zipcode);

            GetShippingService(service);



            shippingService = new DefaultShippingService(delivery, products, newShippingLocation);

            DisplayShippingCostAndRefuels();
        }
        public ActionResult CalculateShipping(IFormCollection collection)
        {
            try
            {
                uint zipCode = 0;
                uint.TryParse(collection["FromZip"].ToString(), out zipCode);
                ////I couldn't figure out how to send the selected item from the ddl to the controller if it was set as an object
                ////I decided to make the DLL a string and use if/else to have it do what I wanted

                if (collection["ShippingMethods"].ToString() == model.DDLOfVehicles[0])
                {
                    DefaultShippingService defaultShip = new DefaultShippingService(new AirExpress(new Plane()), new List <IProduct>(), new ShippingLocation());
                    defaultShip.ShippingLocation.DestinationZipCode = zipCode;
                    return(View(defaultShip));
                }
                else if (collection["ShippingMethods"].ToString() == model.DDLOfVehicles[1])
                {
                    DefaultShippingService defaultShip = new DefaultShippingService(new SnailService(new ShippingSnail()), new List <IProduct>(), new ShippingLocation());
                    defaultShip.ShippingLocation.DestinationZipCode = zipCode;
                    return(View(defaultShip));
                }

                else if (collection["ShippingMethods"].ToString() == model.DDLOfVehicles[2])
                {
                    DefaultShippingService defaultShip = new DefaultShippingService(new UnclesTruck(new Truck()), new List <IProduct>(), new ShippingLocation());
                    defaultShip.ShippingLocation.DestinationZipCode = zipCode;
                    return(View(defaultShip));
                }
                else
                {
                    DefaultShippingService defaultShip = new DefaultShippingService(new AirExpress(new Plane()), new List <IProduct>(), new ShippingLocation());
                    defaultShip.ShippingLocation.DestinationZipCode = zipCode;
                    return(View(defaultShip));
                }
            }
            catch
            {
                return(View());
            }
        }