Beispiel #1
0
        public void UpdateNullReturnsBadRequest()
        {
            // Arrange
            var gymsRepo   = new Mock <IGymRepository>();
            var services   = new Mock <IPaginationUtilities>();
            var controller = new GymApiController(gymsRepo.Object, services.Object);

            // Act
            var putResponse = controller.Put(1, null);

            // Assert
            Assert.IsType(typeof(BadRequestObjectResult), putResponse);
        }
Beispiel #2
0
        public void UpdateValidGymNullRepoResultReturns404()
        {
            // Arrange
            var gym        = TestEntities.Gyms[0];
            var gymsRepo   = new Mock <IGymRepository>();
            var services   = new Mock <IPaginationUtilities>();
            var controller = new GymApiController(gymsRepo.Object, services.Object)
            {
                ControllerContext = { HttpContext = new DefaultHttpContext() }
            };

            //Act
            var putResponse = controller.Put(gym.Id, gym);

            //Assert
            Assert.IsType(typeof(JsonResult), putResponse);
            Assert.Equal(404, controller.Response.StatusCode);
        }
Beispiel #3
0
        public void UpdateValidGymWrongIdBadRequest()
        {
            // Arrange
            var gym      = TestEntities.Gyms[0];
            var gymsRepo = new Mock <IGymRepository>();

            gymsRepo.Setup(repo => repo.Edit(gym)).Returns(gym);
            var services   = new Mock <IPaginationUtilities>();
            var controller = new GymApiController(gymsRepo.Object, services.Object)
            {
                ControllerContext = { HttpContext = new DefaultHttpContext() }
            };

            // Act
            var putResponse = controller.Put(404, gym);

            // Assert
            Assert.IsType(typeof(BadRequestObjectResult), putResponse);
        }
Beispiel #4
0
        public void UpdateInvalidGymReturnsBadRequest()
        {
            // Arrange
            var gym      = TestEntities.Gyms[2];
            var gymsRepo = new Mock <IGymRepository>();

            gymsRepo.Setup(repo => repo.Get(gym.Id)).Returns(gym);
            gymsRepo.Setup(repo => repo.Edit(gym)).Returns(gym);
            var services   = new Mock <IPaginationUtilities>();
            var controller = new GymApiController(gymsRepo.Object, services.Object)
            {
                ControllerContext = { HttpContext = new DefaultHttpContext() }
            };

            controller.ModelState.AddModelError("", "Error");

            // Act
            var putResponse = controller.Put(gym.Id, gym);

            // Assert
            Assert.IsType(typeof(BadRequestObjectResult), putResponse);
        }