Exemplo n.º 1
0
        public async Task PostPageTestAsync(string wikiURL, string pageURL)
        {
            string dbString = Guid.NewGuid().ToString();

            //ARRANGE
            using var context = InMemoryDbContextFactory.GetViewzDbContext(dbString);
            IMdToHtmlAndContentsFactory factory = new MdToHtmlAndContentsFactory();
            var repo            = new PageRepositoryStoring(context, factory);
            var page_controller = new PageController(repo, p_logger);

            Wiki wiki = await context.Wiki.Where(w => w.Url == wikiURL).SingleOrDefaultAsync();

            Page page;

            if (wiki != null)
            {
                page = await context.Page.Where(p => (p.WikiId == wiki.Id && p.Url == pageURL)).SingleOrDefaultAsync();
            }
            else
            {
                page = null;
            }
            var model = new ViewzApi.Models.Page()
            {
                Content  = "# Header 1",
                Details  = new List <DataAccess.Storing.PageDetails>(),
                PageName = pageURL,
                Url      = pageURL
            };

            if (wiki != null && page == null)
            {
                Assert.IsType <CreatedAtActionResult>(await page_controller.PostAsync(wikiURL, pageURL, model));
            }
            else if (wiki == null)
            {
                Assert.IsType <NotFoundObjectResult>(await page_controller.PostAsync(wikiURL, pageURL, model));
            }
            else
            {
                // It should return Conflict, but because there is no unique constraints in in-memory db, it will throw a not found
                await Assert.ThrowsAsync <PageNotFoundException>(() => page_controller.PostAsync(wikiURL, pageURL, model));

                //Assert.IsType<ConflictObjectResult>(page_controller.Post(wikiURL, pageURL, model));
            }
        }
Exemplo n.º 2
0
        public async Task GoodPatchPageTestAsync(string wikiURL, string pageURL)
        {
            string dbString = Guid.NewGuid().ToString();

            //ARRANGE
            using var context = InMemoryDbContextFactory.GetViewzDbContext(dbString);
            IMdToHtmlAndContentsFactory factory = new MdToHtmlAndContentsFactory();
            var repo            = new PageRepositoryStoring(context, factory);
            var page_controller = new PageController(repo, p_logger);

            Wiki wiki = await context.Wiki.Where(w => w.Url == wikiURL).SingleOrDefaultAsync();

            Page page;

            if (wiki != null)
            {
                page = await context.Page.Where(p => (p.WikiId == wiki.Id && p.Url == pageURL)).SingleOrDefaultAsync();
            }
            else
            {
                page = null;
            }
            var model = new ViewzApi.Models.Page()
            {
                Content  = "# Header 1",
                Details  = new List <DataAccess.Storing.PageDetails>(),
                PageName = pageURL,
                Url      = pageURL
            };

            //ACT
            var status = await page_controller.PatchAsync(wikiURL, pageURL, model);

            if (wiki == null || page == null)
            {
                Assert.IsType <NotFoundObjectResult>(status);
            }
            else
            {
                //ASSERT - status 204 (No Content)
                Assert.IsType <NoContentResult>(status);
            }
        }