Beispiel #1
0
        public async Task TestCreateRace()
        {
            using (raceRepository)
            {
                var track = new Track()
                {
                    BestTime       = 121213123,
                    LengthInMeters = 123214,
                    MaxCars        = 50,
                    Name           = "RaceTrack"
                };
                context.Add(track);
                await context.SaveChangesAsync();

                var raceDTO = new RaceCreateDTO()
                {
                    ActualEnd    = new DateTime(1920, 11, 11),
                    ActualStart  = new DateTime(1920, 11, 11),
                    NumberOfLaps = 5,
                    PlannedEnd   = new DateTime(1920, 11, 11),
                    PlannedStart = new DateTime(1920, 11, 11),
                    TrackId      = track.Id
                };

                Assert.NotNull(await context.Races.FindAsync(await raceRepository.CreateAsync(raceDTO)));
            }
        }
        public async void CreateAsync_given_race_returns_raceid()
        {
            var race = default(Race);
            var dto  = new RaceCreateDTO
            {
                Id           = 1,
                TrackId      = 2,
                NumberOfLaps = 7
            };

            var mock = new Mock <ISlotCarContext>();

            mock.Setup(s => s.Races.Add(It.IsAny <Race>())).Callback <Race>(r => race = r);

            using (var repository = new RaceRepository(mock.Object))
            {
                await repository.CreateAsync(dto);
            }

            if (race != null)
            {
                Assert.Equal(2, race.TrackId);
                Assert.Equal(7, race.NumberOfLaps);
            }
            else
            {
                Assert.True(true);
            }
        }