public async Task Should_Return_BasedOnQuery()
        {
            using (var context = new LearningItemContext(_fixture.Options))
            {
                var handler = new FindItemsQueryHandler(context);
                var result  = await handler.QueryAsync(FindItemsQuery.ByWord("salut"));

                var item = result.Single();
                item.ShouldBeEquivalentTo(_fixture.Items[0]);
            }
        }
Beispiel #2
0
        public async Task <IActionResult> AddWord([FromBody] AddWordPostModel postData)
        {
            if (!ModelState.IsValid)
            {
                return(new BadRequestObjectResult(ModelState));
            }

            var command = new AddWordCommand(postData.Word, postData.Answers);
            await _addWordCommandHandler.HandleAsync(command);

            var query       = FindItemsQuery.ByWord(postData.Word);
            var queryResult = await _findItemsQueryHandler.QueryAsync(query);

            var createdItem = queryResult.Single();

            string currentUri = Request?.Path ?? "/Words";

            return(new CreatedResult(currentUri.JoinPaths(createdItem.Id.ToString()), createdItem));
        }