public async void UpdateCarInRaceAsync_given_car_updates_car()
        {
            var builder = new DbContextOptionsBuilder <SlotCarContext>().UseInMemoryDatabase("UpdateCarInRace");

            SlotCarContext context = new SlotCarContext(builder.Options);

            context.Database.EnsureCreated();

            using (var repository = new RaceRepository(context))
            {
                var track = new Track
                {
                    Name           = "Monte Carlo",
                    LengthInMeters = 1002,
                    MaxCars        = 20
                };

                var race = new Race
                {
                    Id           = 42,
                    NumberOfLaps = 5,
                    Track        = track
                };

                var car = new Car
                {
                    Id     = 42,
                    Name   = "Lynet McQueen",
                    Driver = "McQueen"
                };

                var carinrace = new CarInRace
                {
                    Car  = car,
                    Race = race
                };
                await context.Races.AddAsync(race);

                await context.Tracks.AddAsync(track);

                await context.Cars.AddAsync(car);

                await context.CarsInRace.AddAsync(carinrace);

                await context.SaveChangesAsync();

                var dto = new RaceCarDTO
                {
                    CarId         = 42,
                    RaceId        = 42,
                    StartPosition = 1
                };

                var result = await repository.UpdateCarInRaceAsync(dto);

                Assert.True(result.ok);
            }
        }
Beispiel #2
0
        public async Task TestUpdateCarInRaceAsync()
        {
            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
                };
                await context.AddAsync(carInRace);

                await context.SaveChangesAsync();

                var UpdatedCarInRaceInfo = new RaceCarDTO()
                {
                    CarId         = car.Id,
                    RaceId        = race.Id,
                    EndPosition   = 2,
                    FastestLap    = 123123,
                    StartPosition = 1212,
                    TotalTime     = 2121212
                };
                await raceRepository.UpdateCarInRaceAsync(UpdatedCarInRaceInfo);

                Assert.Equal(UpdatedCarInRaceInfo.EndPosition, context.CarsInRace.Find(carInRace.RaceId, carInRace.CarId).EndPosition);
                Assert.Equal(UpdatedCarInRaceInfo.FastestLap, context.CarsInRace.Find(carInRace.RaceId, carInRace.CarId).FastestLap);
                Assert.Equal(UpdatedCarInRaceInfo.TotalTime, context.CarsInRace.Find(carInRace.RaceId, carInRace.CarId).TotalTime);
                Assert.Equal(UpdatedCarInRaceInfo.StartPosition, context.CarsInRace.Find(carInRace.RaceId, carInRace.CarId).StartPosition);
            }
        }