Beispiel #1
0
        public IActionResult ListTrucks()
        {
            var trucks = _service.ListAllTrucks();
            List <TruckViewModel> res = new List <TruckViewModel>();

            trucks.ForEach(t =>
            {
                TruckViewModel tvm = new TruckViewModel()
                {
                    TruckId           = t.TruckId,
                    Description       = t.Description,
                    ManufacturingYear = t.ManufacturingYear,
                    ModelYear         = t.ModelYear,
                    ModelId           = t.Model?.TruckModelId,
                    ModelName         = t.Model?.Model
                };
                res.Add(tvm);
            });
            return(View("ListTrucks", res));
        }
 public async Task <IActionResult> Index()
 {
     return(View(await _truckService.ListAllTrucks()));
 }
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);
        }