public IHttpActionResult Execute([FromBody] TodoFilterInput filter)
        {
            var presenter = CreatePresenter();

            _useCase.Execute(filter, presenter);

            return(presenter.Render());
        }
Exemple #2
0
        public void Execute(TodoFilterInput inputTo, IRespondWithSuccessOrError <List <TodoTo>, ErrorOutputMessage> presenter)
        {
            if (inputTo == null)
            {
                RepsondWithNullFilter(presenter);
                return;
            }

            var filteredCollection = FetchFilteredCollection(inputTo);

            presenter.Respond(filteredCollection);
        }
        public List <TodoTo> FetchFiltered(TodoFilterInput todoFilterInput)
        {
            if (todoFilterInput.IncludedCompleted)
            {
                return(FetchAll());
            }

            // todo : extract a predicate builder to better implement the filter logic
            var result = new List <TodoTo>();

            FetchIncompleteItems(result);
            return(result);
        }
        public void Execute_WhenFilteringIncludedCompletedFalse_ShouldReturnCollectionOfUncompletedItems()
        {
            //---------------Arrange-------------------
            var input = new TodoFilterInput {
                IncludedCompleted = false
            };
            var itemModels  = CreateTodoItems(10);
            var expected    = itemModels.Where(x => x.IsCompleted == false).ToList();
            var testContext = new FetchFilteredTodoUseCaseTestDataBuilder().WithItems(itemModels).Build();
            var usecase     = testContext.UseCase;
            var presenter   = new PropertyPresenter <List <TodoTo>, ErrorOutputMessage>();

            //---------------Act-------------------
            usecase.Execute(input, presenter);
            //---------------Assert-------------------
            AssertTodoItemsMatchExpected(expected, presenter.SuccessContent);
        }
Exemple #5
0
        public void Execute_WhenNoFilterArguments_ShouldReturnOk()
        {
            //---------------Arrange-------------------
            var requestUri = "todo/fetch";
            var args       = new TodoFilterInput()
            {
                IncludedCompleted = false
            };

            var useCase    = CreateFetchTodoCollectionUseCase();
            var testServer = new TestServerBuilder <FetchFilteredTodo>()
                             .WithInstanceRegistration <IFetchFilteredTodoUseCase>(useCase)
                             .Build();

            using (testServer)
            {
                var client = TestHttpClientFactory.CreateClient(testServer);
                //---------------Act-------------------
                var response = client.PostAsJsonAsync(requestUri, args).Result;
                //---------------Assert-------------------
                Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            }
        }
        public void FetchFiltered_WhenIncludeCompletedFalse_ShouldReturnUncompletedItems()
        {
            //---------------Arrange-------------------
            var input = new TodoFilterInput {
                IncludedCompleted = false
            };

            using (var wrapper = CreateTransactionalWrapper())
            {
                var entityCount  = 10;
                var itemEntities = CreateTodoItemEntityFrameworkEntities(entityCount);

                InsertTodoItems(itemEntities, wrapper);
                InsertComments(itemEntities, wrapper);
                var expected = CreateExpectedForFilter(wrapper);

                var todoItemRepository = CreateTodoItemRepository(wrapper);
                //---------------Act-------------------
                var result = todoItemRepository.FetchFiltered(input);
                //---------------Assert-------------------
                AssertTodoItemsMatchExpected(expected, result);
            }
        }
Exemple #7
0
 private List <TodoTo> FetchFilteredCollection(TodoFilterInput inputTo)
 {
     return(_repository.FetchFiltered(inputTo));
 }