public async Task GetByCrew_WithCorrectId_ShouldReturnCorrectResults() { using (var context = provider.GetService <TimingSiteContext>()) using (var controller = new HeadRaceTimingSite.Api.Controllers.ResultController(mapper, context)) { TimingPoint timingPoint = new TimingPoint(1); Crew dbCrew = new Crew { CrewId = 1, BroeCrewId = 123456 }; dbCrew.Results.Add(new Result(timingPoint, new TimeSpan(10, 0, 0))); dbCrew.Competition = new Competition(); dbCrew.Competition.TimingPoints.Add(timingPoint); context.Crews.Add(dbCrew); context.SaveChanges(); var result = await controller.GetByCrew(123456).ConfigureAwait(false); var okResult = result as OkObjectResult; Assert.IsNotNull(okResult, "Should return Ok"); Assert.AreEqual(200, okResult.StatusCode); List <HeadRaceTimingSite.Api.Resources.Result> results = okResult.Value as List <HeadRaceTimingSite.Api.Resources.Result>; Assert.IsNotNull(results, "Should return List<Result>"); Assert.AreEqual(1, results.Count); Assert.AreEqual(new TimeSpan(10, 0, 0), results[0].TimeOfDay); } }
public async Task GetByCrew_WithIncorrectId_ShouldReturn404() { using (var context = provider.GetService <TimingSiteContext>()) using (var controller = new HeadRaceTimingSite.Api.Controllers.ResultController(mapper, context)) { var result = await controller.GetByCrew(1).ConfigureAwait(false); var notFoundResult = result as NotFoundResult; Assert.IsNotNull(notFoundResult); Assert.AreEqual(404, notFoundResult.StatusCode); } }