public async Task GetById_WithCorrectId_ShouldReturnCrew() { var authService = new Mock <IAuthorizationHelper>(); using (var context = provider.GetService <TimingSiteContext>()) using (var controller = new HeadRaceTimingSite.Api.Controllers.CrewController(authService.Object, mapper, context)) { Competition competition = new Competition(); Crew dbCrew = new Crew { BroeCrewId = 1, Competition = competition }; competition.Crews.Add(dbCrew); competition.TimingPoints.Add(new TimingPoint()); context.Competitions.Add(competition); context.SaveChanges(); var result = await controller.GetById(1).ConfigureAwait(false); var okResult = result as OkObjectResult; Assert.IsNotNull(okResult, "Should be Ok Object"); Assert.AreEqual(200, okResult.StatusCode); HeadRaceTimingSite.Api.Resources.Crew crew = okResult.Value as HeadRaceTimingSite.Api.Resources.Crew; Assert.IsNotNull(crew, "Should be Crew"); Assert.AreEqual(1, crew.Id); } }
public async Task GetById_WithIncorrectId_ShouldReturn404() { var authService = new Mock <IAuthorizationHelper>(); using (var context = provider.GetService <TimingSiteContext>()) using (var controller = new HeadRaceTimingSite.Api.Controllers.CrewController(authService.Object, mapper, context)) { var result = await controller.GetById(1).ConfigureAwait(false); var notFoundResult = result as NotFoundResult; Assert.IsNotNull(notFoundResult); Assert.AreEqual(404, notFoundResult.StatusCode); } }