Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
            }
        }
Exemplo n.º 7
0
        public async Task GetHtmlTestNull()
        {
            var    factory  = new MdToHtmlAndContentsFactory();
            string md       = null;
            string EXPECTED = null;
            string ACTUAL   = await factory.GetHtml(md);

            Assert.Equal(EXPECTED, ACTUAL);
        }
Exemplo n.º 8
0
        public async Task GetHtmlTest()
        {
            var    factory  = new MdToHtmlAndContentsFactory();
            string md       = "# Header1 in\n## Header2 in\n### Header3 in\n#### Header4 out\n##### Header5 out\n###### Header6 out";
            string EXPECTED = "<h1>\n<a id=\"user-content-header1-in\" class=\"anchor\" href=\"#header1-in\" aria-hidden=\"true\"><span aria-hidden=\"true\" class=\"octicon octicon-link\"></span></a>Header1 in</h1>\n<h2>\n<a id=\"user-content-header2-in\" class=\"anchor\" href=\"#header2-in\" aria-hidden=\"true\"><span aria-hidden=\"true\" class=\"octicon octicon-link\"></span></a>Header2 in</h2>\n<h3>\n<a id=\"user-content-header3-in\" class=\"anchor\" href=\"#header3-in\" aria-hidden=\"true\"><span aria-hidden=\"true\" class=\"octicon octicon-link\"></span></a>Header3 in</h3>\n<h4>\n<a id=\"user-content-header4-out\" class=\"anchor\" href=\"#header4-out\" aria-hidden=\"true\"><span aria-hidden=\"true\" class=\"octicon octicon-link\"></span></a>Header4 out</h4>\n<h5>\n<a id=\"user-content-header5-out\" class=\"anchor\" href=\"#header5-out\" aria-hidden=\"true\"><span aria-hidden=\"true\" class=\"octicon octicon-link\"></span></a>Header5 out</h5>\n<h6>\n<a id=\"user-content-header6-out\" class=\"anchor\" href=\"#header6-out\" aria-hidden=\"true\"><span aria-hidden=\"true\" class=\"octicon octicon-link\"></span></a>Header6 out</h6>\n";
            string ACTUAL   = await factory.GetHtml(md);

            ACTUAL.Trim('\t');

            Assert.Equal(EXPECTED, ACTUAL);
        }
Exemplo n.º 9
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.º 10
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);
        }
Exemplo n.º 11
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);
            }
        }
Exemplo n.º 12
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));
            }
        }
Exemplo n.º 13
0
        public async Task GetHtmlAndContentsTest()
        {
            var    factory  = new MdToHtmlAndContentsFactory();
            string md       = "# Header1 in\n## Header2 in\n### Header3 in\n#### Header4 out\n##### Header5 out\n###### Header6 out";
            var    EXPECTED = new HtmlAndContents
            {
                PageHTML = "<h1>\n<a id=\"user-content-header1-in\" class=\"anchor\" href=\"#header1-in\" aria-hidden=\"true\"><span aria-hidden=\"true\" class=\"octicon octicon-link\"></span></a>Header1 in</h1>\n<h2>\n<a id=\"user-content-header2-in\" class=\"anchor\" href=\"#header2-in\" aria-hidden=\"true\"><span aria-hidden=\"true\" class=\"octicon octicon-link\"></span></a>Header2 in</h2>\n<h3>\n<a id=\"user-content-header3-in\" class=\"anchor\" href=\"#header3-in\" aria-hidden=\"true\"><span aria-hidden=\"true\" class=\"octicon octicon-link\"></span></a>Header3 in</h3>\n<h4>\n<a id=\"user-content-header4-out\" class=\"anchor\" href=\"#header4-out\" aria-hidden=\"true\"><span aria-hidden=\"true\" class=\"octicon octicon-link\"></span></a>Header4 out</h4>\n<h5>\n<a id=\"user-content-header5-out\" class=\"anchor\" href=\"#header5-out\" aria-hidden=\"true\"><span aria-hidden=\"true\" class=\"octicon octicon-link\"></span></a>Header5 out</h5>\n<h6>\n<a id=\"user-content-header6-out\" class=\"anchor\" href=\"#header6-out\" aria-hidden=\"true\"><span aria-hidden=\"true\" class=\"octicon octicon-link\"></span></a>Header6 out</h6>\n"
            };
            var contents = new Contents[3];

            contents[0] = new Contents()
            {
                Id      = "user-content-header1-in",
                Content = "Header1 in",
                Level   = 1
            };
            contents[1] = new Contents()
            {
                Id      = "user-content-header2-in",
                Content = "Header2 in",
                Level   = 2
            };
            contents[2] = new Contents()
            {
                Id      = "user-content-header3-in",
                Content = "Header3 in",
                Level   = 3
            };

            EXPECTED.Contents = (IEnumerable <Contents>)contents;
            var ACTUAL = await factory.GetHtmlAndContents(md);

            foreach (var(First, Second) in EXPECTED.Contents.Zip(ACTUAL.Contents))
            {
                Assert.Equal(First.Id, Second.Id);
                Assert.Equal(First.Content, Second.Content);
                Assert.Equal(First.Level, Second.Level);
            }

            Assert.Equal(EXPECTED.PageHTML, ACTUAL.PageHTML);
        }