예제 #1
0
        public async Task GetSitemap_RandomId()
        {
            var repository = new SiteRepository(SessionFactory, new ContentServiceFactory(_contentFactory));
            var siteMap    = await repository.GetSitemap(Guid.NewGuid()).ConfigureAwait(false);

            Assert.AreEqual(0, siteMap.Count);
        }
예제 #2
0
        public async Task SaveGetContent()
        {
            var repository = new SiteRepository(SessionFactory, new ContentServiceFactory(_contentFactory));
            var internalId = Guid.NewGuid().ToString("N");
            var site       = new Site
            {
                Description = $"Site description {internalId}",
                InternalId  = internalId,
                Title       = $"Title {internalId}",
                IsDefault   = true,
                SiteTypeId  = "MySiteContent"
            };
            var content = new MySiteContent
            {
                Header = "<p>Lorem ipsum</p>",
                Footer = "<p>Tellus Ligula</p>"
            };
            await repository.Save(site).ConfigureAwait(false);

            var siteId = site.Id;
            await repository.SaveContent(siteId, content).ConfigureAwait(false);

            var contentId = content.Id;
            var retrieved = await repository.GetContentById <MySiteContent>(contentId).ConfigureAwait(false);

            Assert.AreNotEqual(Guid.Empty, retrieved.Id);
            Assert.AreEqual(content.Header, retrieved.Header);
            Assert.AreEqual(content.Footer, retrieved.Footer);
        }
예제 #3
0
        public async Task Delete_WithRandomId()
        {
            var repository = new SiteRepository(SessionFactory, new ContentServiceFactory(_contentFactory));
            await repository.Delete(Guid.NewGuid()).ConfigureAwait(false);

            // Nothing to assert. Should ignore the request without throwing exception.
        }
예제 #4
0
        public async Task GetAll_ForNonExistentSite()
        {
            var siteId     = Guid.NewGuid();
            var repository = new SiteRepository(SessionFactory, new ContentServiceFactory(_contentFactory));
            var sites      = await repository.GetAll().ConfigureAwait(false);

            Assert.AreEqual(0, sites.Count(s => s.Id == siteId));
        }
예제 #5
0
        public async Task GetById_WithRandomId()
        {
            var someId     = Guid.NewGuid();
            var repository = new SiteRepository(SessionFactory, new ContentServiceFactory(_contentFactory));
            var retrieved  = await repository.GetById(someId).ConfigureAwait(false);

            Assert.Null(retrieved);
        }
예제 #6
0
        public async Task GetSitemap_NoPages()
        {
            var repository = new SiteRepository(SessionFactory, new ContentServiceFactory(_contentFactory));
            var siteId     = await MakeSite().ConfigureAwait(false);

            var siteMap = await repository.GetSitemap(siteId, false).ConfigureAwait(false);

            Assert.AreEqual(0, siteMap.Count);
        }
예제 #7
0
        public async Task SaveContent_PublishedOnly()
        {
            var repository = new SiteRepository(SessionFactory, new ContentServiceFactory(_contentFactory));
            var internalId = Guid.NewGuid().ToString("N");
            var siteId     = await MakeSite().ConfigureAwait(false);

            var ex = Assert.ThrowsAsync <ArgumentNullException>(async() => await repository.SaveContent <MySiteContent>(siteId, null).ConfigureAwait(false));

            Assert.AreEqual("Parameter 'content' cannot be null. [Location 201226-2334] (Parameter 'content')", ex.Message);
        }
예제 #8
0
        private async Task DeleteAllSites()
        {
            var repository = new SiteRepository(SessionFactory, new ContentServiceFactory(_contentFactory));
            var sites      = await repository.GetAll().ConfigureAwait(false);

            var listOfTasks = new List <Task>();

            foreach (var site in sites)
            {
                listOfTasks.Add(repository.Delete(site.Id));
            }
            await Task.WhenAll(listOfTasks).ConfigureAwait(false);
        }
        private async Task <Site> MakeSite()
        {
            var siteInternalId    = $"{Guid.NewGuid()}";
            var siteRepository    = new SiteRepository(SessionFactory, new ContentServiceFactory(_contentFactory));
            var siteModelToCreate = new Site
            {
                InternalId  = siteInternalId,
                Description = "Site 42",
                Title       = "Title 42",
            };
            await siteRepository.Save(siteModelToCreate).ConfigureAwait(false);

            return(await siteRepository.GetByInternalId(siteInternalId).ConfigureAwait(false));
        }
예제 #10
0
        private async Task <Guid> MakeSite()
        {
            var repository = new SiteRepository(SessionFactory, new ContentServiceFactory(_contentFactory));
            var internalId = Guid.NewGuid().ToString("N");
            var site       = new Site
            {
                Description = $"Site description {internalId}",
                InternalId  = internalId,
                Title       = $"Title {internalId}",
                IsDefault   = true,
                SiteTypeId  = "MySiteContent",
                Hostnames   = "mysite.com"
            };
            await repository.Save(site).ConfigureAwait(false);

            return(site.Id);
        }
예제 #11
0
        public async Task GetDefault_NoDefault()
        {
            var internalId = Guid.NewGuid().ToString("N");
            var site       = new Site
            {
                Description = $"Site description {internalId}",
                InternalId  = internalId,
                Title       = $"Title {internalId}",
                IsDefault   = false
            };
            var repository = new SiteRepository(SessionFactory, new ContentServiceFactory(_contentFactory));
            await repository.Save(site).ConfigureAwait(false);

            var defaultSite = await repository.GetDefault().ConfigureAwait(false);

            Assert.IsNull(defaultSite);
        }
예제 #12
0
        public async Task Delete()
        {
            var internalId = Guid.NewGuid().ToString("N");
            var site       = new Site
            {
                Description = $"Site description {internalId}",
                InternalId  = internalId,
                Title       = $"Title {internalId}"
            };
            var repository = new SiteRepository(SessionFactory, new ContentServiceFactory(_contentFactory));
            await repository.Save(site).ConfigureAwait(false);

            await repository.Delete(site.Id).ConfigureAwait(false);

            var sites = await repository.GetAll().ConfigureAwait(false);

            Assert.AreEqual(0, sites.Count(s => s.Id == site.Id));
        }
예제 #13
0
        public async Task SaveContent_CanHandleContentNull()
        {
            var repository = new SiteRepository(SessionFactory, new ContentServiceFactory(_contentFactory));
            var internalId = Guid.NewGuid().ToString("N");
            var site       = new Site
            {
                Description = $"Site description {internalId}",
                InternalId  = internalId,
                Title       = $"Title {internalId}",
                IsDefault   = true,
                SiteTypeId  = "MySiteContent"
            };
            await repository.Save(site).ConfigureAwait(false);

            var siteId = site.Id;
            var ex     = Assert.ThrowsAsync <ArgumentNullException>(async() => await repository.SaveContent <MySiteContent>(siteId, null).ConfigureAwait(false));

            Assert.AreEqual("Parameter 'content' cannot be null. [Location 201226-2334] (Parameter 'content')", ex.Message);
        }
예제 #14
0
        public async Task GetDefault_WithExistingDefault()
        {
            var internalId = Guid.NewGuid().ToString("N");
            var site       = new Site
            {
                Description = $"Site description {internalId}",
                InternalId  = internalId,
                Title       = $"Title {internalId}",
                IsDefault   = true
            };
            var repository = new SiteRepository(SessionFactory, new ContentServiceFactory(_contentFactory));
            await repository.Save(site).ConfigureAwait(false);

            var siteId      = site.Id;
            var defaultSite = await repository.GetDefault().ConfigureAwait(false);

            Assert.AreEqual(siteId, defaultSite.Id);
            Assert.IsTrue(defaultSite.IsDefault);
        }
예제 #15
0
        public async Task GetById_ExistingSite()
        {
            var internalId = Guid.NewGuid().ToString("N");
            var site       = new Site
            {
                Description = $"Site description {internalId}",
                InternalId  = internalId,
                Title       = $"Title {internalId}"
            };
            var repository = new SiteRepository(SessionFactory, new ContentServiceFactory(_contentFactory));
            await repository.Save(site).ConfigureAwait(false);

            var siteId = site.Id;

            Assert.AreNotEqual(Guid.Empty, siteId);
            var retrieved = await repository.GetById(siteId).ConfigureAwait(false);

            Assert.AreEqual(internalId, retrieved.InternalId);
        }
예제 #16
0
        public async Task GetSitemap()
        {
            var repository = new SiteRepository(SessionFactory, new ContentServiceFactory(_contentFactory));
            var siteId     = await MakeSite().ConfigureAwait(false);

            _ = await MakePage(siteId).ConfigureAwait(false);

            var anotherPage = await MakePage(siteId).ConfigureAwait(false);

            anotherPage.Published = null;
            var pageRepository = new PageRepository(SessionFactory, new ContentServiceFactory(_contentFactory), Module.Mapper);
            await pageRepository.Save(anotherPage).ConfigureAwait(false);

            var siteMap = await repository.GetSitemap(siteId, true).ConfigureAwait(false);

            Assert.AreEqual(1, siteMap.Count);
            var siteMapIncludingNonPublished = await repository.GetSitemap(siteId, false).ConfigureAwait(false);

            Assert.AreEqual(2, siteMapIncludingNonPublished.Count);
        }