public async Task TestDeleteRace() { using (raceRepository) { var track = new Track() { BestTime = 121213123, LengthInMeters = 123214, MaxCars = 50, Name = "RaceTrack" }; var race = new Race() { 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), Track = track }; context.Tracks.Add(track); context.Races.Add(race); await context.SaveChangesAsync(); Assert.Equal((false, "Race was not found or hasnt started yet"), await raceRepository.DeleteAsync(race.Id)); } }
public async void DeleteAsync_given_raceid_deletes_race() { var race = new Race(); var mock = new Mock <ISlotCarContext>(); mock.Setup(m => m.Races.FindAsync(1)).ReturnsAsync(race); mock.Setup(m => m.Races.Remove(It.IsAny <Race>())).Callback <Race>(r => race = r); using (var repository = new RaceRepository(mock.Object)) { var result = await repository.DeleteAsync(1); Assert.True(result.ok); } mock.Verify(m => m.SaveChangesAsync(default(CancellationToken))); }