Exemplo n.º 1
0
        public async Task Add_should_call_repository_and_return_createdAtAction()
        {
            // given
            var pageRequest       = _fixture.Create <PageRequest>();
            int autoIncrementedId = 99;

            _pageRepositoryMock
            .AddNewPageAsync(Arg.Any <Page>())
            .Returns(c =>
            {
                var page = c.Arg <Page>();

                // the repository returns a new id (autoincremented)
                return(Task.FromResult(new Page()
                {
                    Id = autoIncrementedId,
                    Title = page.Title
                }));
            });

            // when
            ActionResult <PageResponse> actionResult = await _pagesController.Add(pageRequest);

            // then
            actionResult.ShouldBeCreatedAtActionResult();
            PageResponse pageResponse = actionResult.CreatedAtActionResultValue();

            pageResponse.ShouldNotBeNull("ActionResult's ViewModel was null");
            pageResponse.Id.ShouldBe(autoIncrementedId);
            pageResponse.Title.ShouldBe(pageRequest.Title);
        }
Exemplo n.º 2
0
        private List <Page> CreateTenPages(IPageRepository repository, List <Page> pages = null)
        {
            if (pages == null)
            {
                pages = _fixture.CreateMany <Page>(10).ToList();
            }

            var newPages = new List <Page>();

            foreach (Page page in pages)
            {
                page.Title += " some kind of £ encoding is <needed> for this src=\"i think\"";
                Page newPage = repository.AddNewPageAsync(page).GetAwaiter().GetResult();
                newPages.Add(newPage);
            }

            return(newPages);
        }
Exemplo n.º 3
0
        public async Task <ActionResult <PageResponse> > Add([FromBody] PageRequest pageRequest)
        {
            // TODO: add base62 ID, as Id in Marten is Hilo and starts at 1000 as the lo
            // TODO: fill createdon property
            // TODO: validate
            // http://www.anotherchris.net/csharp/friendly-unique-id-generation-part-2/
            Page page = _pageObjectsConverter.ConvertToPage(pageRequest);

            if (page == null)
            {
                return(NotFound());
            }

            Page newPage = await _pageRepository.AddNewPageAsync(page);

            PageResponse response = _pageObjectsConverter.ConvertToPageResponse(newPage);

            return(CreatedAtAction(nameof(Add), nameof(PagesController), response));
        }