Пример #1
0
        public void TestPut_ReturnsBadRequestResultWhenIdsAreNotEqual()
        {
            var toggle = new Toggle();
            var mockOfIUpdateToggleCommand = new MockOfIUpdateToggleCommand();
            var togglesController          = new TogglesController(null, null, null, mockOfIUpdateToggleCommand.Object, null);

            IActionResult result = togglesController.Put(Guid.NewGuid(), toggle);

            Assert.IsInstanceOf <BadRequestObjectResult>(result);
        }
Пример #2
0
        public void TestPut()
        {
            var toggle = new Toggle();
            var mockOfIUpdateToggleCommand = new MockOfIUpdateToggleCommand();
            var togglesController          = new TogglesController(null, null, null, mockOfIUpdateToggleCommand.Object, null);

            IActionResult result = togglesController.Put(toggle.Id, toggle);

            Assert.IsInstanceOf <OkObjectResult>(result);
        }
Пример #3
0
        public void TestPut_ReturnsBadRequestResultWhenModelStateIsInvalid()
        {
            var toggle = new Toggle();
            var mockOfIUpdateToggleCommand = new MockOfIUpdateToggleCommand();
            var togglesController          = new TogglesController(null, null, null, mockOfIUpdateToggleCommand.Object, null);

            this.ChangeModelStateToBeInvalid(togglesController);

            IActionResult result = togglesController.Put(toggle.Id, toggle);

            Assert.IsInstanceOf <BadRequestObjectResult>(result);
        }
Пример #4
0
        public void TestPut_ReturnsBadRequestResultWhenEntityValidationException()
        {
            var toggle = new Toggle();
            var mockOfIUpdateToggleCommand = new MockOfIUpdateToggleCommand();

            mockOfIUpdateToggleCommand.SetupToThrowException(
                new EntityValidationException(""));
            var togglesController = new TogglesController(null, null, null, mockOfIUpdateToggleCommand.Object, null);

            IActionResult result = togglesController.Put(toggle.Id, toggle);

            Assert.IsInstanceOf <BadRequestObjectResult>(result);
        }
Пример #5
0
        public void TestPut_ReturnsNotFoundResultWhenEntityNotFoundException()
        {
            var toggle = new Toggle();
            var mockOfIUpdateToggleCommand = new MockOfIUpdateToggleCommand();

            mockOfIUpdateToggleCommand.SetupToThrowException(
                new EntityNotFoundException(typeof(Toggle), toggle.Id.ToString()));
            var togglesController = new TogglesController(null, null, null, mockOfIUpdateToggleCommand.Object, null);

            IActionResult result = togglesController.Put(toggle.Id, toggle);

            Assert.IsInstanceOf <NotFoundObjectResult>(result);
        }
Пример #6
0
    public void PutToggleValue()
    {
        const string toggleName  = "toggle2";
        const bool   toggleValue = true;

        _commandHandler
        .Setup(handler => handler
               .Execute(It.Is <UpdateToggleValue>(c => c.ToggleName.Equals(toggleName) &&
                                                  c.ToggleValue.Equals(toggleValue))))
        .Verifiable();

        IActionResult result = _controller.Put(toggleName, toggleValue);

        _commandHandler
        .Verify(handler => handler
                .Execute(It.Is <UpdateToggleValue>(c => c.ToggleName.Equals(toggleName) &&
                                                   c.ToggleValue.Equals(toggleValue))));

        Assert.IsType <OkResult>(result);

        var okResult = result as OkResult;

        Assert.NotNull(okResult);
        Assert.Equal(200, okResult.StatusCode);
    }