Ejemplo n.º 1
0
        public PagesControllerTests()
        {
            _fixture = new Fixture();

            _pageRepositoryMock       = Substitute.For <IPageRepository>();
            _viewObjectsConverterMock = Substitute.For <IPageObjectsConverter>();

            _viewObjectsConverterMock
            .ConvertToPageResponse(Arg.Any <Page>())
            .Returns(c =>
            {
                var page = c.Arg <Page>();
                return(new PageResponse()
                {
                    Id = page.Id, Title = page.Title
                });
            });

            _viewObjectsConverterMock
            .ConvertToPage(Arg.Any <PageRequest>())
            .Returns(c =>
            {
                var pageRequest = c.Arg <PageRequest>();
                return(new Page()
                {
                    Id = pageRequest.Id,
                    Title = pageRequest.Title
                });
            });

            _pagesController = new PagesController(_pageRepositoryMock, _viewObjectsConverterMock);
        }
Ejemplo n.º 2
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));
        }