public void Edit_pulls_page_from_database_and_creates_viewmodel()
        {
            Mapper.Reset();
            AutoMapperConfig.RegisterMappings();

            var store = new TestableStore();

            var page = new Page
            {
                Id = "pages/123",
                Title = "foo"
            };

            using (var pagesController = new PagesController(store))
            {
                using (var session = store.OpenSession())
                {
                    session.Store(page);
                    session.SaveChanges();

                    RavenControllerTestHelper.SetSessionOnController(pagesController, session);

                    string uniquePart = page.Id.Replace(Page.IdPrefix, "");

                    var actionResult = pagesController.Edit(uniquePart);
                    var pageEditModel = ControllerTestHelper.GetModelInActionResult<PageEditModel>(actionResult);

                    Assert.Equal(page.Title, pageEditModel.Title);
                }
            }

            Mapper.Reset();
        }
        public void Delete_sets_page_deleted()
        {
            Mapper.Reset();
            AutoMapperConfig.RegisterMappings();

            var store = new TestableStore();

            var page = new Page
            {
                Id = "pages/123",
                Title = "foo"
            };

            using (var pagesController = new PagesController(store))
            {
                using (var session = store.OpenSession())
                {
                    session.Store(page);
                    session.SaveChanges();

                    RavenControllerTestHelper.SetSessionOnController(pagesController, session);

                    pagesController.Delete(page.Id);

                    var pageLoaded = session.Load<Page>(page.Id);
                    Assert.True(pageLoaded.Deleted);
                }
            }

            Mapper.Reset();
        }
        public PageEditModel Map(Page page)
        {
            var pageEditModel = Mapper.Map<PageEditModel>(page);

            pageEditModel.PossibleHtmlColors = this.GetPossibleHtmlColors(page.HtmlColor);

            return pageEditModel;
        }
Пример #4
0
        public ActionResult New()
        {
            var page = new Page();

            var mapper = new PageToPageEditModelMapper(this.session);
            var pageEditModel = mapper.Map(page);

            return this.View("Edit", pageEditModel);
        }
        public PageViewModel Map(Page page, bool includeEntries = true)
        {
            var pageViewModel = Mapper.Map<PageViewModel>(page);

            pageViewModel.DisqusShortname = DisqusShortname;

            if (includeEntries)
            {
                this.PopulateEntries(pageViewModel);
            }

            return pageViewModel;
        }
Пример #6
0
        public void PageFactory_can_get_page_from_database_by_slug()
        {
            var store = new TestableStore();

            string slug = "foo-bar-baz";

            var page = new Page
            {
                Id = "pages/123",
                Slug = slug
            };

            using (var session = store.OpenSession())
            {
                session.Store(page);
                session.SaveChanges();

                var pageLoaded = GetPageForSlug(session, slug);

                Assert.Equal(page.Id, pageLoaded.Id);
            }
        }
Пример #7
0
        public void Deleted_pages_are_not_returned()
        {
            var store = new TestableStore();

            string slug = "foo-bar-baz";

            var page = new Page
            {
                Id = "pages/123",
                Slug = slug,
                Deleted = true
            };

            using (var session = store.OpenSession())
            {
                session.Store(page);
                session.SaveChanges();

                var pageLoaded = GetPageForSlug(session, slug);

                Assert.Null(pageLoaded);
            }
        }
        public void Page_title_is_correctly_mapped()
        {
            Mapper.Reset();
            AutoMapperConfig.RegisterMappings();

            string title = "foo";

            var page = new Page
            {
                Title = title
            };

            var store = new TestableStore();

            using (var session = store.OpenSession())
            {
                var pageViewModel = GetMappedPageViewModel(session, page);

                Assert.Equal(title, pageViewModel.Title);
            }

            Mapper.Reset();
        }
        public void Page_slug_is_correctly_mapped()
        {
            Mapper.Reset();
            AutoMapperConfig.RegisterMappings();

            string slug = "foo-bar-baz";

            var page = new Page
            {
                Slug = slug
            };

            var store = new TestableStore();

            using (var session = store.OpenSession())
            {
                var pageViewModel = GetMappedPageViewModel(session, page);

                Assert.Equal(slug, pageViewModel.Slug);
            }

            Mapper.Reset();
        }
        public void Page_html_color_is_correctly_mapped()
        {
            Mapper.Reset();
            AutoMapperConfig.RegisterMappings();

            string color = "#ff0000";

            var page = new Page
            {
                HtmlColor = color
            };

            var store = new TestableStore();

            using (var session = store.OpenSession())
            {
                var pageViewModel = GetMappedPageViewModel(session, page);

                Assert.Equal(color, pageViewModel.HtmlColor);
            }

            Mapper.Reset();
        }
        private static PageViewModel GetMappedPageViewModel(IDocumentSession session, Page page)
        {
            var testableUrlHelperFactory = new TestableUrlHelperFactory();
            var urlHelper = testableUrlHelperFactory.Create();

            var pageToPageViewModelMapper = new PageToPageViewModelMapper(session, urlHelper);
            return pageToPageViewModelMapper.Map(page);
        }
Пример #12
0
        private void SaveCategoryAsPage(Category category)
        {
            var random = new Random();

            var page = new Page
            {
                Title = category.Name,
                Slug = category.Slug,
                HtmlColor = HtmlColor.AllColors[random.Next(0, HtmlColor.AllColors.Length)].HexColor,
                LastModifiedAtUtc = DateTimeOffset.UtcNow
            };

            this.session.Store(page);
        }