Example #1
0
        public void AddMake(Make make)
        {
            if (_context.Makes.Any(m => m.Name == make.Name))
                throw new ArgumentException("Make already exists");

            _context.Makes.Add(make);
            _context.SaveChanges();
        }
        public VehicleControllerTests()
        {
            _context = new MockContext();
            _context.Users.Add(new User
            {
                Id = 1,
                Username = "******"
            });

            var make = new Make
            {
                Id = 1,
                Name = "make"
            };

            var model = new Model
            {
                Id = 1,
                Name = "model",
                Make = make
            };

            var user = new User
            {
                Id = 1,
                Email = "Test"
            };

            make.Models = new List<Model> {model};

            _context.Models.Add(model);
            _context.Makes.Add(make);

            _context.Vehicles.Add(new Vehicle
            {
                Id = 1,
                Year = "2015",
                Kilometers = 100,
                Model = model,
                User = user
            });
            _context.Vehicles.Add(new Vehicle
            {
                Id = 2,
                Year = "2014",
                Kilometers = 1000,
                Model = model,
                User = user
            });

            user.Vehicles = new List<Vehicle>();
            user.Vehicles.Add(_context.Vehicles.First());
            user.Vehicles.Add(_context.Vehicles.Last());
        }
        public void Add_Duplicate_Make()
        {
            var context = new MockContext();
            var store = new VehicleStore(context);
            var make = new Make
            {
                Id = 1,
                Name = "cow"
            };
            context.Makes.Add(make);

            make.Id = 2;
            store.AddMake(make);
        }