public void TruckRepositoryCRUD()
        {
            ITruckModelRepository _modelRepo = serviceProvider.GetService <ITruckModelRepository>();
            ITruckRepository      _truckRepo = serviceProvider.GetService <ITruckRepository>();

            Assert.NotNull(_modelRepo.FindAllAvailableModels());
            Assert.AreEqual(2, _modelRepo.FindAllAvailableModels().Count);

            // Get first available model
            var model = _modelRepo.FindAllAvailableModels()[0];

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

            _truckRepo.Save(truck);

            // List existing trucks
            List <Truck> trucks = _truckRepo.FindAllTrucks();

            // Checking for id for that specific truck saved above
            Truck savedTruck = trucks.AsQueryable().Where(el => el.ManufacturingYear == 1929).First();

            Assert.NotNull(savedTruck);
            Assert.AreEqual(1929, savedTruck.ManufacturingYear);
            Assert.AreEqual(1929, savedTruck.ModelYear);
            Assert.AreEqual("TEST", savedTruck.Description);

            int id = savedTruck.TruckId;

            // Updating truck
            Truck toUpdate = _truckRepo.FindById(id);

            toUpdate.ModelYear = 1930;
            _truckRepo.Update(toUpdate);

            // Refetching truck
            Truck updated = _truckRepo.FindById(id);

            Assert.NotNull(updated);
            Assert.AreEqual(1929, updated.ManufacturingYear);
            Assert.AreEqual(1930, updated.ModelYear);
            Assert.AreEqual("TEST", updated.Description);

            // Deleting truck
            _truckRepo.Delete(id);

            Truck deleted = _truckRepo.FindById(id);

            Assert.Null(deleted);
        }
 public Truck FindTruckById(int id)
 {
     return(_truckRepo.FindById(id));
 }
Esempio n. 3
0
        public async Task DeleteTruck(Guid id)
        {
            var truck = _truckRepository.FindById(id);

            _truckRepository.Remove(truck);
        }