예제 #1
0
        public void WhenTruckInspectionPassesButTrackCountReachedLimit()
        {
            //arrange
            truck = new Truck
            {
                TowStrap   = true,
                LiftHeight = 4
            };

            //act
            var allowed = truck.AllowOnTrack(5);

            //assert
            Assert.IsFalse(allowed);
        }
예제 #2
0
        public void WhenTruckHasStrapAndLiftedMoreThanFiveInchesInspectionFails()
        {
            //arrange
            truck = new Truck
            {
                TowStrap   = true,
                LiftHeight = 6
            };

            //act
            var allowed = truck.AllowOnTrack(0);

            //assert
            Assert.IsFalse(allowed);
        }
예제 #3
0
        public void WhenTruckHasStrapAndLiftedLessThanOrEqualToFiveInchesInspectionPasses()
        {
            //arrange
            truck = new Truck
            {
                TowStrap   = true,
                LiftHeight = 4
            };

            //act
            var allowed = truck.AllowOnTrack(0);

            //assert
            Assert.IsTrue(allowed);
        }
예제 #4
0
        public ActionResult AddVehicle(AddVehicleViewModel model)
        {
            if (ModelState.IsValid)
            {
                _raceTrackRepository = new RaceTrackRepository(dbContext);

                if (model.Vehicle.VehicleType == VehicleType.Truck)
                {
                    Truck newTruck = new Truck
                    {
                        TowStrap    = model.Vehicle.TowStrap,
                        LiftHeight  = model.TruckLiftHeight,
                        VehicleType = model.Vehicle.VehicleType
                    };

                    if (newTruck.AllowOnTrack(_raceTrackRepository.GetVehicleCount()))
                    {
                        _raceTrackRepository.Add(newTruck);
                    }
                    else
                    {
                        ModelState.AddModelError("", "Not allowed");
                    }
                }

                if (model.Vehicle.VehicleType == VehicleType.Car)
                {
                    Car newCar = new Car
                    {
                        TowStrap    = model.Vehicle.TowStrap,
                        TireWear    = model.CarTireWear,
                        VehicleType = model.Vehicle.VehicleType
                    };

                    if (newCar.AllowOnTrack(_raceTrackRepository.GetVehicleCount()))
                    {
                        _raceTrackRepository.Add(newCar);
                    }
                    else
                    {
                        ModelState.AddModelError("", "Not allowed");
                    }
                }
            }

            return(RedirectToAction("Index", "Home"));
        }