public async Task CreateTodoItem_NotSucessfull_StatusCodeInternalServerError()
        {
            var factory = new ControllerFactory();

            var mockHandler = Mock.Of <IHandler>();

            Mock.Get(mockHandler).Setup(
                x => x.HandleCommand <CreateTodoItemCommand, CreateTodoItemCommandResult>(
                    It.IsAny <CreateTodoItemCommand>()))
            .ReturnsAsync(new CreateTodoItemCommandResult
            {
                Successfull = false,
            });

            var toCreate = new ViewModel.TodoItem.CreateView();

            factory.Services.Replace(ServiceDescriptor.Scoped(factory => mockHandler));

            var controller = factory.Create <TodoController>();

            var result = await controller.CreateTodoItem(1, toCreate);

            result.Should().BeOfType <StatusCodeResult>();
            ((StatusCodeResult)result).StatusCode.Should()
            .Be(StatusCodes.Status500InternalServerError);
        }
        public async Task CreateTodoItem_ValidRequest_OkObjectResult()
        {
            var factory = new ControllerFactory();

            var mockHandler = Mock.Of <IHandler>();

            Mock.Get(mockHandler).Setup(
                x => x.HandleCommand <CreateTodoItemCommand, CreateTodoItemCommandResult>(
                    It.IsAny <CreateTodoItemCommand>()))
            .ReturnsAsync(new CreateTodoItemCommandResult
            {
                Successfull = true,
                Data        = new ViewModel.TodoItem.CreatedView()
            });

            var toCreate = new ViewModel.TodoItem.CreateView();

            factory.Services.Replace(ServiceDescriptor.Scoped(factory => mockHandler));

            var controller = factory.Create <TodoController>();

            var result = await controller.CreateTodoItem(1, toCreate);

            result.Should().BeOfType <OkObjectResult>();
            ((OkObjectResult)result).Value.Should().BeOfType <ViewModel.TodoItem.CreatedView>();
        }
        public async Task CreateTodoItem_HandlerThrows_Rethrows()
        {
            var factory = new ControllerFactory();

            var mockHandler = Mock.Of <IHandler>();

            Mock.Get(mockHandler).Setup(
                x => x.HandleCommand <CreateTodoItemCommand, CreateTodoItemCommandResult>(
                    It.IsAny <CreateTodoItemCommand>()))
            .ThrowsAsync(new Exception());

            var toCreate = new ViewModel.TodoItem.CreateView();

            factory.Services.Replace(ServiceDescriptor.Scoped(factory => mockHandler));

            var controller = factory.Create <TodoController>();

            Func <Task> act = async() => await controller.CreateTodoItem(1, toCreate);

            await act.Should().ThrowAsync <Exception>();
        }