Beispiel #1
0
        public IActionResult Create()
        {
            ViewBag.Models = new SelectList(_service.ListAvailableModels(), "TruckModelId", "Model");
            ViewBag.Years  = new[]
            {
                new SelectListItem()
                {
                    Value = DateTime.Now.Year.ToString(), Text = DateTime.Now.Year.ToString()
                },
                new SelectListItem()
                {
                    Value = (DateTime.Now.Year + 1).ToString(), Text = (DateTime.Now.Year + 1).ToString()
                }
            };

            return(View());
        }
Beispiel #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);
            });
        }
Beispiel #3
0
        public void TruckServiceFunctions()
        {
            ITruckService _service = serviceProvider.GetService <ITruckService>();

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

            Assert.NotNull(models);
            Assert.AreEqual(2, models.Count);
            // Get first available model
            var model = models[0];

            // Saving new Truck with specific information
            Truck truck = new Truck()
            {
                Description       = "TEST",
                ManufacturingYear = 1944,
                ModelYear         = 1944,
                Model             = model,
                TruckModelId      = model.TruckModelId
            };

            List <Truck> receivedTrucks = _service.ListAllTrucks();
            List <Truck> filtered       = receivedTrucks.Where(t => t.ManufacturingYear == 1944 || t.ModelYear == 1944).ToList();

            Assert.AreEqual(0, filtered.Count);

            _service.SaveOrUpdateTruck(truck);

            receivedTrucks = _service.ListAllTrucks();
            filtered       = receivedTrucks.Where(t => t.ManufacturingYear == 1944 || t.ModelYear == 1944).ToList();

            Assert.AreEqual(1, filtered.Count);

            Truck saved = filtered[0];

            Assert.AreEqual(1944, saved.ManufacturingYear);
            Assert.AreEqual(1944, saved.ModelYear);
            Assert.AreEqual("TEST", saved.Description);

            int id = saved.TruckId;

            Truck toUpdate = _service.FindTruckById(id);

            Assert.NotNull(toUpdate);

            toUpdate.ModelYear = 1950;
            _service.SaveOrUpdateTruck(toUpdate);

            receivedTrucks = _service.ListAllTrucks();
            filtered       = receivedTrucks.Where(t => t.ManufacturingYear == 1944 && t.ModelYear == 1950).ToList();

            Assert.AreEqual(1, filtered.Count);

            Truck updated = filtered[0];

            Assert.AreEqual(1944, updated.ManufacturingYear);
            Assert.AreEqual(1950, updated.ModelYear);
            Assert.AreEqual("TEST", updated.Description);

            _service.DeleteTruck(id);

            receivedTrucks = _service.ListAllTrucks();
            filtered       = receivedTrucks.Where(t => t.ManufacturingYear == 1944 || t.ModelYear == 1950).ToList();

            Assert.AreEqual(0, filtered.Count);
        }