Beispiel #1
0
        public async Task 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);
                await context.SaveChangesAsync();

                await raceRepository.AddCarToRaceAsync(car.Id, race.Id, 5);

                var carInRace = (from carInRaces in context.CarsInRace.AsParallel()
                                 where carInRaces.CarId == car.Id && carInRaces.RaceId == race.Id
                                 select carInRaces).Count();
                Assert.True(carInRace > 0);
            }
        }
        public async void AddCarToRaceAsync_given_carid_raceid_and_startposition_returns_true()
        {
            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"
            };

            await _context.Cars.AddAsync(car);

            await _context.Races.AddAsync(race);

            await _context.SaveChangesAsync();

            using (var repository = new RaceRepository(_context))
            {
                var result = await repository.AddCarToRaceAsync(1, 1);

                Assert.True(result.ok);
            }

            connection.Close();
        }