public void AddNullReturnsBadRequest() { // Arrange var gymsRepo = new Mock <IGymRepository>(); var services = new Mock <IPaginationUtilities>(); var controller = new GymApiController(gymsRepo.Object, services.Object) { ControllerContext = { HttpContext = new DefaultHttpContext() } }; // Act var postResponse = controller.Post(null); // Assert Assert.IsType(typeof(BadRequestObjectResult), postResponse); }
public void AddInvalidGymReturnsBadRequest() { // Arrange var gym = TestEntities.Gyms[2]; var gymsRepo = new Mock <IGymRepository>(); var services = new Mock <IPaginationUtilities>(); var controller = new GymApiController(gymsRepo.Object, services.Object) { ControllerContext = { HttpContext = new DefaultHttpContext() } }; controller.ModelState.AddModelError("", "Error"); // Act var postResponse = controller.Post(gym); // Assert Assert.IsType(typeof(BadRequestObjectResult), postResponse); }
public void AddValidGymReturnsObjectResult() { // Arrange var gym = TestEntities.Gyms[0]; var gymsRepo = new Mock <IGymRepository>(); gymsRepo.Setup(repo => repo.Get(gym.Id)).Returns(gym); var services = new Mock <IPaginationUtilities>(); var controller = new GymApiController(gymsRepo.Object, services.Object) { ControllerContext = { HttpContext = new DefaultHttpContext() } }; // Act var postResponse = controller.Post(gym); // Assert Assert.IsType(typeof(CreatedAtRouteResult), postResponse); Assert.IsType(typeof(Gym), ((ObjectResult)postResponse).Value); var actualGym = (Gym)((ObjectResult)postResponse).Value; Assert.Equal(gym, actualGym); }