예제 #1
0
        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) });
        }
예제 #3
0
        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);
        }
예제 #4
0
        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());
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }