示例#1
0
        public IActionResult Create([Bind] TruckViewModel truck)
        {
            if (ModelState.IsValid)
            {
                var truckModel = _service.FindModelById((int)truck.ModelId);
                var newTruck   = new Truck()
                {
                    ModelYear         = truck.ModelYear,
                    Description       = truck.Description,
                    ManufacturingYear = truck.ManufacturingYear,
                    Model             = truckModel
                };
                _service.SaveOrUpdateTruck(newTruck);
            }

            return(RedirectToAction("ListTrucks"));
        }
示例#2
0
        public void TruckServiceModelFunctions()
        {
            ITruckService _service = serviceProvider.GetService <ITruckService>();

            // Validating pre-populated models
            List <TruckModel> models = _service.ListModels();

            Assert.NotNull(models);
            Assert.AreEqual(4, models.Count);

            TruckModel model1 = _service.FindModelById(1);

            Assert.NotNull(model1);
            Assert.AreEqual(1, model1.TruckModelId);
            Assert.AreEqual("FH", model1.Model);
            Assert.AreEqual(true, model1.Available);

            TruckModel model2 = _service.FindModelById(2);

            Assert.NotNull(model2);
            Assert.AreEqual(2, model2.TruckModelId);
            Assert.AreEqual("FM", model2.Model);
            Assert.AreEqual(true, model2.Available);

            TruckModel model3 = _service.FindModelById(3);

            Assert.NotNull(model3);
            Assert.AreEqual(3, model3.TruckModelId);
            Assert.AreEqual("FMX", model3.Model);
            Assert.AreEqual(false, model3.Available);

            TruckModel model4 = _service.FindModelById(4);

            Assert.NotNull(model4);
            Assert.AreEqual(4, model4.TruckModelId);
            Assert.AreEqual("VM", model4.Model);
            Assert.AreEqual(false, model4.Available);

            List <TruckModel> availableModels = _service.ListAvailableModels();

            Assert.NotNull(availableModels);
            availableModels.ForEach(m => {
                Assert.AreEqual(true, m.Available);
            });
        }