public void AddVehicle(string username, Vehicle vehicle) { var user = _context.Users.FirstOrDefault(u => u.Username == username); if (user == null) throw new ArgumentException("Invalid User"); vehicle.User = user; _context.Vehicles.Add(vehicle); _context.SaveChanges(); }
public MaintenanceStoreTests() { var otherVehicle = new Vehicle { Id = 2, Kilometers = 2000, User = new User { Id = 2, Username = "******" } }; _schedules.Add(new Schedule { Id = 1, Title = "Oil", Vehicle = _vehicle }); _schedules.Add(new Schedule { Id = 2, Title = "Spark Plug", Vehicle = _vehicle }); _schedules.Add(new Schedule { Id = 3, Title = "Cable", Vehicle = _vehicle }); _schedules.Add(new Schedule { Id = 4, Title = "Exhaust", Vehicle = otherVehicle }); _schedules.Add(new Schedule { Id = 5, Title = "Intake", Vehicle = otherVehicle }); _tasks.Add(new MaintenanceTask { Id = 6, Title = "Tyre", Vehicle = _vehicle, Started = new DateTime(2013, 7, 1) }); _tasks.Add(new MaintenanceTask { Id = 7, Title = "Chain", Vehicle = _vehicle, Started = new DateTime(2013, 7, 2) }); _tasks.Add(new MaintenanceTask { Id = 8, Title = "Sproket", Vehicle = _vehicle, Started = new DateTime(2013, 7, 3) }); _tasks.Add(new MaintenanceTask { Id = 9, Title = "Seat", Vehicle = otherVehicle, Started = new DateTime(2013, 7, 4) }); _tasks.Add(new MaintenanceTask { Id = 10, Title = "Air Filter", Vehicle = otherVehicle, Started = new DateTime(2013, 7, 5) }); }
public void Delete_Vehicle_Wrong_Vehicle() { var context = new MockContext(); var vehicle = new Vehicle { Id = 1, User = _user }; context.Vehicles.Add(vehicle); var store = new VehicleStore(context); store.DeleteVehicle(2, 2); }
public void Delete_Vehicle() { var context = new MockContext(); var vehicle = new Vehicle { Id = 1, User = _user}; context.Vehicles.Add(vehicle); var store = new VehicleStore(context); store.DeleteVehicle(_user.Id, 1); Assert.AreEqual(0, context.Vehicles.Count()); }
public void Add_Vehicle_Invalid_User() { var context = new MockContext(); context.Models.Add(_model); context.Users.Add(_user); var store = new VehicleStore(context); var vehicle = new Vehicle { Kilometers = 7000, Model = context.Models.First(), Year = "1991" }; store.AddVehicle("abc", vehicle); }
public void Add_Valid_Vehicle() { var context = new MockContext(); context.Models.Add(_model); context.Users.Add(_user); var store = new VehicleStore(context); var vehicle = new Vehicle { Kilometers = 7000, Model = context.Models.First(), Year = "1991" }; store.AddVehicle(_user.Username, vehicle); vehicle = context.Vehicles.First(); Assert.AreEqual(7000, vehicle.Kilometers); Assert.AreEqual(context.Models.First(), vehicle.Model); Assert.AreEqual("1991", vehicle.Year); Assert.AreEqual(1, context.SaveChangesCalls); }