Esempio n. 1
0
        public void 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);
                context.SaveChanges();
                raceRepository.RemoveCarFromRace(car.Id, race.Id);

                var test = context.CarsInRace.Find(carInRace.CarId, carInRace.RaceId);

                Assert.Null(context.CarsInRace.Find(carInRace.CarId, carInRace.RaceId));
            }
        }
Esempio n. 2
0
        public void RemoveCarFromRace_given_carid_and_raceid_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"
            };

            _context.Cars.Add(car);
            _context.Races.Add(race);
            _context.SaveChanges();

            using (var repository = new RaceRepository(_context))
            {
                var result = repository.RemoveCarFromRace(1, 1);
                Assert.True(result.ok);
            }

            connection.Close();
        }