public void TrackTraits_SetTo_DriverResult() { // Arrange DriverResult driverResult = new DriverResult(); TrackTrait trackTrait1 = new TrackTrait { Trait = new Trait { QualyPace = 1 } }; TrackTrait trackTrait2 = new TrackTrait { Trait = new Trait { QualyPace = 2 } }; List <TrackTrait> trackTraits = new List <TrackTrait> { trackTrait1, trackTrait2 }; Weather weather = Weather.Sunny; // Act RaceService.SetTrackTraitMods(driverResult, trackTraits, weather); // Assert int expected = 3; // QualyMod should add up all QualyPace which results in an expected of 3 Assert.Equal(expected, driverResult.QualyMod); }
public async Task AddTraitToTrack(Track track, Trait trait) { TrackTrait newTrait = new TrackTrait { Track = track, Trait = trait }; await Context.AddAsync(newTrait); }
public async Task <IActionResult> RemoveTrait(int trackId, int traitId) { Track track = await Context.Tracks .Include(tr => tr.TrackTraits) .FirstAsync(t => t.Id == trackId); Trait trait = await Context.Traits .FirstAsync(tr => tr.TraitId == traitId); if (track == null || trait == null) { return(NotFound()); } TrackTrait removetrait = track.TrackTraits .First(trt => trt.TraitId == traitId); Context.Remove(removetrait); await Context.SaveChangesAsync(); return(RedirectToAction(nameof(TrackTraits), new { id = trackId })); }
public async Task <IActionResult> TrackTraits(int id, [Bind("TraitId")] int traitId) { Track track = await _tracks.GetTrackById(id); Trait trait = await Context.Traits.FirstAsync(tr => tr.TraitId == traitId); if (track is null || trait is null) { return(NotFound()); } TrackTrait newTrait = new TrackTrait { Track = track, Trait = trait }; DataService.Update(track); await Context.AddAsync(newTrait); await Context.SaveChangesAsync(); return(RedirectToAction(nameof(TrackTraits), new { id })); }