Пример #1
0
        public async Task TestUpdate()
        {
            using (raceRepository)
            {
                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 trackupdated = new Track()
                {
                    BestTime       = 12121312321121,
                    LengthInMeters = 1232142112,
                    MaxCars        = 40,
                    Name           = "RaceTrackupdated"
                };
                context.Add(race);
                context.Add(trackupdated);
                await context.SaveChangesAsync();

                var RaceCreate = new RaceCreateDTO()
                {
                    Id           = race.Id,
                    NumberOfLaps = 5,
                    PlannedEnd   = new DateTime(1920, 11, 11),
                    PlannedStart = new DateTime(1920, 11, 11),
                    TrackId      = trackupdated.Id,
                    ActualEnd    = new DateTime(1221, 1, 1),
                    ActualStart  = new DateTime(2412, 2, 2)
                };
                await raceRepository.UpdateAsync(RaceCreate);

                Assert.Equal((await context.Races.FindAsync(race.Id)).Track, trackupdated);
            }
        }
Пример #2
0
        public async void UpdateAsync_given_race_updates_race()
        {
            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        = 4
            };

            var track2 = new Track()
            {
                Id             = 2,
                Name           = "Little Lane",
                LengthInMeters = 3000,
                MaxCars        = 5
            };

            var race = new Race()
            {
                Id           = 1,
                TrackId      = 1,
                Track        = track,
                NumberOfLaps = 2,
                ActualStart  = new DateTime(2015, 09, 28),
                PlannedEnd   = new DateTime(2017, 09, 28)
            };

            await _context.Tracks.AddAsync(track);

            await _context.Tracks.AddAsync(track2);

            await _context.Races.AddAsync(race);

            await _context.SaveChangesAsync();

            var newRace = new RaceCreateDTO()
            {
                Id           = 1,
                TrackId      = 2,
                NumberOfLaps = 5,
                PlannedStart = new DateTime(2015, 09, 28),
                PlannedEnd   = new DateTime(2017, 09, 28),
                ActualEnd    = new DateTime(2017, 09, 30)
            };

            using (var repository = new RaceRepository(_context))
            {
                await repository.UpdateAsync(newRace);

                var result = await _context.Races.FindAsync(1);

                Assert.Equal(2, result.TrackId);
                Assert.Equal(track2.Name, result.Track.Name);
                Assert.Equal(5, result.NumberOfLaps);
                Assert.Equal(new DateTime(2015, 09, 28), result.PlannedStart);
                Assert.Equal(new DateTime(2015, 09, 28), result.ActualStart);
                Assert.Equal(new DateTime(2017, 09, 28), result.PlannedEnd);
                Assert.Equal(new DateTime(2017, 09, 30), result.ActualEnd);
            }
        }