public void GetGymByWrongIdReturns404() { // 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 response = controller.Get(20000); // Assert Assert.IsType(typeof(JsonResult), response); Assert.Equal(404, controller.Response.StatusCode); }
public void GetAllReturnsJsonResult() { // Arrange var gymsRepo = new Mock <IGymRepository>(); var services = new Mock <IPaginationUtilities>(); gymsRepo.Setup(repo => repo.GetAll()).Returns(TestEntities.Gyms); services.Setup(service => service.Filter <Gym>(TestEntities.Gyms, "", null)).Returns(TestEntities.Gyms); services.Setup(service => service.Sort <Gym>(TestEntities.Gyms, "", "", null)).Returns(TestEntities.Gyms); services.Setup(service => service.Partition <Gym>(TestEntities.Gyms, 0, 0)).Returns(TestEntities.Gyms); var controller = new GymApiController(gymsRepo.Object, services.Object) { ControllerContext = { HttpContext = new DefaultHttpContext() } }; // Act var response = controller.Get(); // Assert Assert.IsType(typeof(ObjectResult), response); Assert.NotNull(((ObjectResult)response).Value); }
public void GetGymByValidIdReturnsGym() { // 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 response = controller.Get(gym.Id); //Assert Assert.IsType(typeof(ObjectResult), response); Assert.IsType(typeof(Gym), ((ObjectResult)response).Value); var actualGym = (Gym)((ObjectResult)response).Value; Assert.Equal(gym, actualGym); }