Beispiel #1
0
        public async Task TestRemoveCarFromRace()
        {
            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
                };
                var carInRace = new CarInRace()
                {
                    Car = car, Race = race
                };
                context.Add(carInRace);
                await context.SaveChangesAsync();

                await raceRepository.RemoveCarFromRaceAsync(car.Id, race.Id);


                Assert.Null(await context.CarsInRace.FindAsync(carInRace.CarId, carInRace.RaceId));
            }
        }
        public async void RemoveCarFromRaceAsync_given_carid_and_racid_removes_car()
        {
            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.RemoveCarFromRaceAsync(1, 1);

                Assert.True(result.ok);
            }

            connection.Close();
        }