public void CreateSportOkSportsController() { sportServicesMock.Setup(s => s.CreateSport(It.IsAny <SportDTO>())); ILoginServices login = new LoginServicesMock(mariano); var httpContext = new DefaultHttpContext(); httpContext.Request.Headers["Authorization"] = ""; var controllerContext = new ControllerContext() { HttpContext = httpContext, }; var controller = new SportsController(login, sportServicesMock.Object, encounterServicesMock.Object, encounterQueryServices.Object, positionServicesMock.Object, teamServicesMock.Object) { ControllerContext = controllerContext, }; SportDTO footballIn = new SportDTO() { Name = "Futbol" }; var result = controller.CreateSport(footballIn); sportServicesMock.Verify(s => s.CreateSport(It.IsAny <SportDTO>()), Times.AtMostOnce); var createdResult = result as CreatedAtRouteResult; var footballOut = createdResult.Value as SportDTO; Assert.IsNotNull(createdResult); Assert.AreEqual("GetSport", createdResult.RouteName); Assert.AreEqual(201, createdResult.StatusCode); Assert.AreEqual(footballIn.Name, footballOut.Name); }
public void CreateSportAlreadyExistsSportsController() { sportServicesMock.Setup(s => s.CreateSport(It.IsAny <SportDTO>())).Throws(new ServicesException()); ILoginServices login = new LoginServicesMock(rodolfo); var httpContext = new DefaultHttpContext(); httpContext.Request.Headers["Authorization"] = ""; var controllerContext = new ControllerContext() { HttpContext = httpContext, }; var controller = new SportsController(login, sportServicesMock.Object, encounterServicesMock.Object, encounterQueryServices.Object, positionServicesMock.Object, teamServicesMock.Object) { ControllerContext = controllerContext, }; SportDTO footballIn = new SportDTO() { Name = "Futbol" }; var result = controller.CreateSport(footballIn); sportServicesMock.Verify(s => s.CreateSport(It.IsAny <SportDTO>()), Times.AtMostOnce); var createdResult = result as BadRequestObjectResult; Assert.IsNotNull(createdResult); Assert.AreEqual(400, createdResult.StatusCode); }