public T Create <T>(int id,
                            int weightInKilogram) where T : IVehicle
        {
            if (typeof(T) == typeof(IStandardCar))
            {
                IVehicle car = new StandardCar(new VehicleFees(new FeeCalculator()),
                                               id,
                                               weightInKilogram);
                return(( T )car);
            }
            if (typeof(T) == typeof(ILuxuryCar))
            {
                IVehicle car = new LuxuryCar(new VehicleFees(new FeeCalculator()),
                                             id,
                                             weightInKilogram);
                return(( T )car);
            }
            if (typeof(T) == typeof(IMotorbike))
            {
                IVehicle car = new Motorbike(new VehicleFees(new FeeCalculator()),
                                             id,
                                             weightInKilogram);
                return(( T )car);
            }
            if (typeof(T) == typeof(ITruck))
            {
                IVehicle car = new Truck(new VehicleFees(new FeeCalculator()),
                                         id,
                                         weightInKilogram);
                return(( T )car);
            }

            throw new ArgumentException("Unknown vehicle type '{0}'!".Inject(typeof(T)));
        }
Exemplo n.º 2
0
 private void PayFeesForAllOtherCars()
 {
     // 8.	Pay the outstanding fees for the remaining cars
     StandardCar.PaysFee();
     Motorbike.PaysFee();
     Truck.PaysFee();
 }
Exemplo n.º 3
0
        public void ShortDescription_ReturnsString_WhenCalled()
        {
            // Arrange
            var fees = Substitute.For <IVehicleFees>();
            var sut  = new StandardCar(fees,
                                       DefaultId,
                                       DefaultWeightInKilogram);

            // Act
            string actual = sut.ShortDescription;

            // Assert
            Assert.AreEqual("StandardCar",
                            actual);
        }
Exemplo n.º 4
0
        public void StandardCar_IsValidTest_02()
        {
            // StandardCar with acceleration = 2
            ICar sc = new StandardCar(2);

            IList <Point> routeGridPoints  = new List <Point>();
            Point         gridPointClicked = new Point();
            bool          result;

            routeGridPoints.Add(new Point(2, 2));
            routeGridPoints.Add(new Point(4, 4));

            gridPointClicked.X = 5;
            gridPointClicked.Y = 5;
            result             = sc.IsValid(routeGridPoints, gridPointClicked);
            Assert.IsTrue(result);
            gridPointClicked.X = 6;
            gridPointClicked.Y = 5;
            result             = sc.IsValid(routeGridPoints, gridPointClicked);
            Assert.IsTrue(result);
            gridPointClicked.X = 7;
            gridPointClicked.Y = 5;
            result             = sc.IsValid(routeGridPoints, gridPointClicked);
            Assert.IsTrue(result);

            gridPointClicked.X = 5;
            gridPointClicked.Y = 6;
            result             = sc.IsValid(routeGridPoints, gridPointClicked);
            Assert.IsTrue(result);
            gridPointClicked.X = 6;
            gridPointClicked.Y = 6;
            result             = sc.IsValid(routeGridPoints, gridPointClicked);
            Assert.IsTrue(result);
            gridPointClicked.X = 7;
            gridPointClicked.Y = 6;
            result             = sc.IsValid(routeGridPoints, gridPointClicked);
            Assert.IsTrue(result);

            gridPointClicked.X = 5;
            gridPointClicked.Y = 7;
            result             = sc.IsValid(routeGridPoints, gridPointClicked);
            Assert.IsTrue(result);
            gridPointClicked.X = 6;
            gridPointClicked.Y = 7;
            result             = sc.IsValid(routeGridPoints, gridPointClicked);
            Assert.IsTrue(result);
            gridPointClicked.X = 7;
            gridPointClicked.Y = 7;
            result             = sc.IsValid(routeGridPoints, gridPointClicked);
            Assert.IsTrue(result);

            gridPointClicked.X = 4;
            gridPointClicked.Y = 4;
            result             = sc.IsValid(routeGridPoints, gridPointClicked);
            Assert.IsTrue(result);
            gridPointClicked.X = 5;
            gridPointClicked.Y = 4;
            result             = sc.IsValid(routeGridPoints, gridPointClicked);
            Assert.IsTrue(result);
            gridPointClicked.X = 6;
            gridPointClicked.Y = 4;
            result             = sc.IsValid(routeGridPoints, gridPointClicked);
            Assert.IsTrue(result);
            gridPointClicked.X = 7;
            gridPointClicked.Y = 4;
            result             = sc.IsValid(routeGridPoints, gridPointClicked);
            Assert.IsTrue(result);
            gridPointClicked.X = 8;
            gridPointClicked.Y = 4;
            result             = sc.IsValid(routeGridPoints, gridPointClicked);
            Assert.IsTrue(result);

            gridPointClicked.X = 4;
            gridPointClicked.Y = 8;
            result             = sc.IsValid(routeGridPoints, gridPointClicked);
            Assert.IsTrue(result);
            gridPointClicked.X = 5;
            gridPointClicked.Y = 8;
            result             = sc.IsValid(routeGridPoints, gridPointClicked);
            Assert.IsTrue(result);
            gridPointClicked.X = 6;
            gridPointClicked.Y = 8;
            result             = sc.IsValid(routeGridPoints, gridPointClicked);
            Assert.IsTrue(result);
            gridPointClicked.X = 7;
            gridPointClicked.Y = 8;
            result             = sc.IsValid(routeGridPoints, gridPointClicked);
            Assert.IsTrue(result);
            gridPointClicked.X = 8;
            gridPointClicked.Y = 8;
            result             = sc.IsValid(routeGridPoints, gridPointClicked);
            Assert.IsTrue(result);

            gridPointClicked.X = 4;
            gridPointClicked.Y = 6;
            result             = sc.IsValid(routeGridPoints, gridPointClicked);
            Assert.IsTrue(result);

            gridPointClicked.X = 8;
            gridPointClicked.Y = 6;
            result             = sc.IsValid(routeGridPoints, gridPointClicked);
            Assert.IsTrue(result);

            gridPointClicked.X = 3;
            gridPointClicked.Y = 6;
            result             = sc.IsValid(routeGridPoints, gridPointClicked);
            Assert.IsFalse(result);

            gridPointClicked.X = 9;
            gridPointClicked.Y = 6;
            result             = sc.IsValid(routeGridPoints, gridPointClicked);
            Assert.IsFalse(result);

            gridPointClicked.X = 6;
            gridPointClicked.Y = 3;
            result             = sc.IsValid(routeGridPoints, gridPointClicked);
            Assert.IsFalse(result);

            gridPointClicked.X = 6;
            gridPointClicked.Y = 9;
            result             = sc.IsValid(routeGridPoints, gridPointClicked);
            Assert.IsFalse(result);
        }