Ejemplo n.º 1
0
        public async Task GetPageNoContentTestAsync(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 status = await page_controller.GetAsync(wikiURL, pageURL, ViewzApi.Controllers.PageContent.NoContent);

            if (page != null)
            {
                Assert.IsType <OkObjectResult>(status);
            }
            else
            {
                Assert.IsType <NotFoundObjectResult>(status);
            }
        }
Ejemplo n.º 2
0
        public async Task PatchWiki204TestAsync(string wikiURL)
        {
            string dbString = Guid.NewGuid().ToString();

            //ARRANGE
            using var context = InMemoryDbContextFactory.GetViewzDbContext(dbString);
            IMdToHtmlAndContentsFactory factory = new MdToHtmlAndContentsFactory();
            var wrepo           = new WikiRepositoryStoring(context, factory);
            var prepo           = new PageRepositoryStoring(context, factory);
            var wiki_controller = new WikiController(wrepo, prepo, w_logger);
            var wiki            = new ViewzApi.Models.Wiki()
            {
                PageName    = "I'm Hungry",
                Description = "This is a description"
            };

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

            //ACT
            var status = await wiki_controller.PatchAsync(wikiURL, wiki);

            if (WIKI != null)
            {
                //ASSERT
                Assert.IsType <NoContentResult>(status);
            }
            else
            {
                Assert.IsType <NotFoundResult>(status);
            }
        }
Ejemplo n.º 3
0
        public async Task PatchWiki400TestAsync(string wikiURL)
        {
            string dbString = Guid.NewGuid().ToString();

            //ARRANGE
            using var context = InMemoryDbContextFactory.GetViewzDbContext(dbString);
            IMdToHtmlAndContentsFactory factory = new MdToHtmlAndContentsFactory();
            var wrepo           = new WikiRepositoryStoring(context, factory);
            var prepo           = new PageRepositoryStoring(context, factory);
            var wiki_controller = new WikiController(wrepo, prepo, w_logger);

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

            //ACT
            var status = await wiki_controller.PatchAsync(wikiURL, new ViewzApi.Models.Wiki());

            if (WIKI != null)
            {
                //ASSERT
                Assert.IsType <BadRequestObjectResult>(status);
            }
            else
            {
                //ASSERT
                Assert.IsType <BadRequestObjectResult>(status);
            }
        }
Ejemplo n.º 4
0
        public async Task GetWikiTestAsync(string wikiURL)
        {
            string dbString = Guid.NewGuid().ToString();

            //ARRANGE
            using var context = InMemoryDbContextFactory.GetViewzDbContext(dbString);
            IMdToHtmlAndContentsFactory factory = new MdToHtmlAndContentsFactory();
            var wrepo           = new WikiRepositoryStoring(context, factory);
            var prepo           = new PageRepositoryStoring(context, factory);
            var wiki_controller = new WikiController(wrepo, prepo, w_logger);

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

            //ACT
            var status = await wiki_controller.GetAsync(wikiURL);

            if (wiki != null)
            {
                //ASSERT - status 200 (OK)
                Assert.IsType <OkObjectResult>(status);
            }
            else
            {
                //ASSERT - status 404 (OK)
                Assert.IsType <NotFoundResult>(status);
            }
        }
Ejemplo n.º 5
0
        public async Task PostWikiTestAsync(string wikiURL)
        {
            string dbString = Guid.NewGuid().ToString();

            //ARRANGE
            using var context = InMemoryDbContextFactory.GetViewzDbContext(dbString);
            IMdToHtmlAndContentsFactory factory = new MdToHtmlAndContentsFactory();
            var prepo           = new PageRepositoryStoring(context, factory);
            var wrepo           = new WikiRepositoryStoring(context, factory);
            var wiki_controller = new WikiController(wrepo, prepo, w_logger);

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

            var content = new PageHtmlContent();
            var W       = new ViewzApi.Models.Wiki()
            {
                Url         = wikiURL,
                Description = "",
                PageName    = wikiURL
            };

            var status = await wiki_controller.PostAsync(wikiURL, W);

            if (wiki == null)
            {
                //ASSERT
                Assert.IsType <CreatedAtActionResult>(status);
            }
            else
            {
                Assert.IsType <ConflictObjectResult>(status);
            }
        }
Ejemplo n.º 6
0
        public async Task PatchPage400TestAsync(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;
            }
            //ACT
            var status = await page_controller.PatchAsync(wikiURL, pageURL, new ViewzApi.Models.Page());

            //ASSERT - status 400 (Bad Request)
            Assert.IsType <BadRequestObjectResult>(status);
        }
Ejemplo n.º 7
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));
            }
        }
Ejemplo n.º 8
0
        public async Task GetPopWiki200TestAsync()
        {
            //ARRANGE
            string dbString = Guid.NewGuid().ToString();

            //ARRANGE
            using var context = InMemoryDbContextFactory.GetViewzDbContext(dbString);
            IMdToHtmlAndContentsFactory factory = new MdToHtmlAndContentsFactory();
            var prepo           = new PageRepositoryStoring(context, factory);
            var wrepo           = new WikiRepositoryStoring(context, factory);
            var wiki_controller = new WikiController(wrepo, prepo, w_logger);

            var status = await wiki_controller.GetAsync(5);

            //ACT
            //ASSERT
            Assert.IsType <OkObjectResult>(status);
        }
Ejemplo n.º 9
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);
            }
        }
Ejemplo n.º 10
0
        public async Task WikiGetWikiMDTestAsync(string wikiURL)
        {
            string dbString = Guid.NewGuid().ToString();

            //ARRANGE
            using var context = InMemoryDbContextFactory.GetViewzDbContext(dbString);
            IMdToHtmlAndContentsFactory factory = new MdToHtmlAndContentsFactory();
            var wrepo = new WikiRepositoryStoring(context, factory);
            var wiki  = await context.Wiki.Where(w => w.Url == wikiURL).SingleOrDefaultAsync();

            if (wiki != null)
            {
                await wrepo.GetWikiWithMDAsync(wikiURL);
            }
            else
            {
                await Assert.ThrowsAsync <WikiNotFoundException>(() => wrepo.GetWikiWithMDAsync(wikiURL));
            }
        }