public void TestAddCarToRace() { using (raceRepository) { Car car = new Car() { Driver = "Mads", Name = "Suzuki" }; var track = new Track() { BestTime = 121213123, LengthInMeters = 123214, MaxCars = 50, Name = "RaceTrack" }; var race = new Race() { NumberOfLaps = 5, PlannedEnd = new DateTime(1920, 11, 11), PlannedStart = new DateTime(1920, 11, 11), Track = track }; context.Cars.Add(car); context.Races.Add(race); context.SaveChanges(); raceRepository.AddCarToRace(car.Id, race.Id, 5); var carInRace = (from carInRaces in context.CarsInRace where carInRaces.CarId == car.Id && carInRaces.RaceId == race.Id select carInRaces).Count(); Assert.True(carInRace > 0); } }
public void Add_Car_To_Race_That_Is_Full_Returns_False() { var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); var builder = new DbContextOptionsBuilder <SlotCarContext>() .UseSqlite(connection); _context = new SlotCarContext(builder.Options); _context.Database.EnsureCreated(); var track = new Track() { Id = 1, Name = "Huge Lane", LengthInMeters = 1000, MaxCars = 1 }; var race = new Race() { Id = 1, TrackId = 1, Track = track, NumberOfLaps = 2, }; var car = new Car() { Id = 1, Name = "BMW", Driver = "Hugh Hefner" }; var car2 = new Car() { Id = 2, Name = "Opel", Driver = "Barack Obama" }; var raceCar = new CarInRace() { CarId = car.Id, RaceId = race.Id, Car = car, Race = race }; _context.Cars.Add(car); _context.Cars.Add(car2); _context.Races.Add(race); _context.CarsInRace.Add(raceCar); _context.SaveChanges(); using (var repository = new RaceRepository(_context)) { var result = repository.AddCarToRace(2, 1); Assert.False(result.ok); Assert.Equal("Race is full", result.error); } connection.Close(); }
public void Add_Car_To_Race_That_Is_Started_Returns_False() { var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); var builder = new DbContextOptionsBuilder <SlotCarContext>() .UseSqlite(connection); _context = new SlotCarContext(builder.Options); _context.Database.EnsureCreated(); var track = new Track() { Id = 1, Name = "Short Lane", LengthInMeters = 1000, MaxCars = 1 }; var race = new Race() { Id = 1, TrackId = 1, Track = track, NumberOfLaps = 2, ActualStart = new DateTime(2017, 9, 28) }; var car = new Car() { Id = 1, Name = "BMW", Driver = "Hugh Hefner" }; _context.Cars.Add(car); _context.Races.Add(race); _context.SaveChanges(); using (var repository = new RaceRepository(_context)) { var result = repository.AddCarToRace(1, 1); Assert.False(result.ok); Assert.Equal("Race started", result.error); } connection.Close(); }
public void Add_Car_To_Race_Runs_Correct_Methods() { var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); var builder = new DbContextOptionsBuilder <SlotCarContext>() .UseSqlite(connection); _context = new SlotCarContext(builder.Options); _context.Database.EnsureCreated(); var track = new Track() { Id = 1, Name = "Long Lane", LengthInMeters = 1000, MaxCars = 4 }; var race = new Race() { Id = 1, TrackId = 1, Track = track, NumberOfLaps = 2 }; var car = new Car() { Id = 1, Name = "BMW", Driver = "Hugh Hefner" }; _context.Cars.Add(car); _context.Races.Add(race); _context.SaveChanges(); using (var repository = new RaceRepository(_context)) { var result = repository.AddCarToRace(1, 1); Assert.True(result.ok); Assert.Equal("YAY! " + car.Name + " " + race.Track.Name, result.error); } connection.Close(); }