Exemplo n.º 1
0
        public void TestUpdate()
        {
            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);
            context.SaveChanges();
            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)
            };

            raceRepository.Update(RaceCreate);
            Assert.Equal(context.Races.Find(race.Id).Track, trackupdated);
        }
Exemplo n.º 2
0
        public void Update_Race_From_Race_Create_DTO()
        {
            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)
            };

            _context.Tracks.Add(track);
            _context.Tracks.Add(track2);
            _context.Races.Add(race);
            _context.SaveChanges();

            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))
            {
                repository.Update(newRace);
                var result = _context.Races.Find(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);
            }
        }