Пример #1
0
        public async Task When_creating_a_toggle_the_response_location_is_set()
        {
            _mediator
            .Send(Arg.Any <CreateToggleRequest>())
            .Returns(_response);

            var result = (CreatedResult)await _controller.Post(new TogglePostRequest());

            result.ShouldSatisfyAllConditions(
                () => result.Location.ShouldBe("/toggles/id/" + _response.Toggle.ID),
                () => result.Value.ShouldBe(_response.Toggle)
                );
        }
Пример #2
0
        public void TestPost()
        {
            var toggle = new Toggle();
            var mockOfICreateToggleCommand = new MockOfICreateToggleCommand();
            var togglesController          = new TogglesController(null, null, mockOfICreateToggleCommand.Object, null, null);

            IActionResult result = togglesController.Post(toggle);

            Assert.IsInstanceOf <CreatedResult>(result);
        }
Пример #3
0
        public void TestPost_ReturnsBadRequestResultWhenModelStateIsInvalid()
        {
            var toggle = new Toggle();
            var mockOfICreateToggleCommand = new MockOfICreateToggleCommand();
            var togglesController          = new TogglesController(null, null, mockOfICreateToggleCommand.Object, null, null);

            this.ChangeModelStateToBeInvalid(togglesController);

            IActionResult result = togglesController.Post(toggle);

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

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

        var result = _controller.Post(toggleName, toggleValue);

        _commandHandler.Verify(handler => handler.Execute(It.Is <CreateToggle>(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);
    }
Пример #5
0
        public void TestPost_ReturnsNotFoundResultWhenEntityNotFoundException()
        {
            var toggle = new Toggle();
            var mockOfICreateToggleCommand = new MockOfICreateToggleCommand();

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

            IActionResult result = togglesController.Post(toggle);

            Assert.IsInstanceOf <NotFoundObjectResult>(result);
        }
Пример #6
0
        public void TestPost_ReturnsBadRequestResultWhenEntityValidationException()
        {
            var toggle = new Toggle();
            var mockOfICreateToggleCommand = new MockOfICreateToggleCommand();

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

            IActionResult result = togglesController.Post(toggle);

            Assert.IsInstanceOf <BadRequestObjectResult>(result);
        }