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

            var store = new TestableStore();

            var entry = new Entry
            {
                Id = "entries/123",
                Title = "foo"
            };

            using (var entriesController = new EntriesController(store))
            {
                using (var session = store.OpenSession())
                {
                    session.Store(entry);
                    session.SaveChanges();

                    RavenControllerTestHelper.SetSessionOnController(entriesController, session);

                    string uniquePart = entry.Id.Replace(Entry.IdPrefix, "");

                    var actionResult = entriesController.Edit(uniquePart);
                    var entryEditModel = ControllerTestHelper.GetModelInActionResult<EntryEditModel>(actionResult);

                    Assert.Equal(entry.Title, entryEditModel.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 void Search_returns_only_distinct_results()
        {
            var store = new TestableStore();

            var duplicatedTag = "alpha";

            var testTags = new[] { duplicatedTag, duplicatedTag, "beta" }.ToList();

            using (var tagsController = new TagsController(store))
            {
                using (var session = store.OpenSession())
                {
                    var entry = new Entry { Tags = new Collection<string>(testTags) };
                    session.Store(entry);
                    session.SaveChanges();

                    RavenControllerTestHelper.SetSessionOnController(tagsController, session);

                    var actionResult = tagsController.Search("alpha");
                    var tags = GetTagsFromResult(actionResult);

                    Assert.Equal(1, tags.Count());
                    Assert.Equal(duplicatedTag, tags.First());
                }
            }
        }
        public void Menu_gets_all_pages_in_database()
        {
            Mapper.Reset();
            AutoMapperConfig.RegisterMappings();

            var store = new TestableStore();

            int pagesCount = 2;

            using (var navigationController = new NavigationController(store))
            {
                using (var session = store.OpenSession())
                {
                    PersistTestPages(session, pagesCount);

                    RavenControllerTestHelper.SetSessionOnController(navigationController, session);

                    var actionResult = navigationController.Menu();
                    var pageViewModels = ControllerTestHelper.GetModelInActionResult<IEnumerable<PageViewModel>>(actionResult);

                    for (int i = 0; i < pagesCount; i++)
                    {
                        Assert.True(pageViewModels.Any(vm => vm.Id == Page.IdPrefix + i));
                    }
                }
            }

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

            var store = new TestableStore();

            int pagesCount = 2;

            using (var navigationController = new NavigationController(store))
            {
                using (var session = store.OpenSession())
                {
                    PersistTestPages(session, pagesCount);

                    RavenControllerTestHelper.SetSessionOnController(navigationController, session);

                    var actionResult = navigationController.Menu();
                    var pageViewModels = ControllerTestHelper.GetModelInActionResult<IEnumerable<PageViewModel>>(actionResult);

                    var firstPageViewModel = pageViewModels.First();
                    Assert.Equal(Page.HomePage.Id, firstPageViewModel.Id);
                }
            }

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

            var store = new TestableStore();

            int entryCount = 2;

            using (var entriesDashboardController = new EntriesDashboardController(store))
            {
                using (var session = store.OpenSession())
                {
                    PersistTestEntries(session, entryCount, true);

                    RavenControllerTestHelper.SetSessionOnController(entriesDashboardController, session);

                    var queryModel = GetDefaultQueryModel();

                    var actionResult = entriesDashboardController.Fetch(queryModel);
                    var entryEditModels = GetEntryEditModelsFromResult(actionResult);

                    Assert.Empty(entryEditModels);
                }
            }
        }
        public void Widgets_in_database_are_produced_by_factory()
        {
            var conventions = new DocumentConvention
            {
                FindTypeTagName = type =>
                                  {
                                      if (typeof(Widget).IsAssignableFrom(type))
                                      {
                                          return Widget.IdPrefix.TrimSuffix("/");
                                      }
                                      return DocumentConvention.DefaultTypeTagName(type);
                                  }
            };

            var testableStore = new TestableStore(conventions);

            var fooWidget = new CustomWidget { Markup = "foo" };
            var barWidget = new CustomWidget { Markup = "bar" };

            using (var session = testableStore.OpenSession())
            {
                session.Store(fooWidget);
                session.Store(barWidget);
                session.SaveChanges();

                var widgetFactory = new WidgetFactory(session);
                var widgets = widgetFactory.GetWidgets();

                Assert.Contains(fooWidget, widgets);
                Assert.Contains(barWidget, widgets);
            }
        }
        public void Existing_database_entry_slug_remains_unchanged()
        {
            Mapper.Reset();
            AutoMapperConfig.RegisterMappings();

            var testableStore = new TestableStore();

            var entry = new Entry
            {
                Slug = "foo-title"
            };

            using (var session = testableStore.OpenSession())
            {
                session.Store(entry);
                session.SaveChanges();

                var entryEditModel = new EntryEditModel
                {
                    Id = entry.Id,
                    Title = "Bar Title"
                };

                var entryEditModelToEntryMapper = new EntryEditModelToEntryMapper(session);
                entryEditModelToEntryMapper.Map(entry, entryEditModel);

                Assert.Equal(entry.Slug, entry.Slug);
            }

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

            var store = new TestableStore();

            var entry = new Entry
            {
                Id = "entries/123",
                Title = "foo"
            };

            using (var entriesController = new EntriesController(store))
            {
                using (var session = store.OpenSession())
                {
                    session.Store(entry);
                    session.SaveChanges();

                    RavenControllerTestHelper.SetSessionOnController(entriesController, session);

                    entriesController.Delete(entry.Id);

                    var entryLoaded = session.Load<Entry>(entry.Id);
                    Assert.True(entryLoaded.Deleted);
                }
            }

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

            var store = new TestableStore();

            int pagesCount = 2;

            using (var pagesDashboardController = new PagesDashboardController(store))
            {
                using (var session = store.OpenSession())
                {
                    PersistTestPages(session, pagesCount);

                    RavenControllerTestHelper.SetSessionOnController(pagesDashboardController, session);

                    var queryModel = GetDefaultQueryModel();

                    var actionResult = pagesDashboardController.Fetch(queryModel);
                    var pageEditModels = GetPageEditModelsFromResult(actionResult);

                    for (int i = 0; i < pagesCount; i++)
                    {
                        Assert.True(pageEditModels.Any(editModel => editModel.Id == Page.IdPrefix + i));
                    }
                }
            }
        }
예제 #11
0
        public void Entry_not_in_database_returns_null()
        {
            var testableStore = new TestableStore();

            using (var session = testableStore.OpenSession())
            {
                var entryFactory = new EntryFactory(session);
                var entry = entryFactory.CreateFromSlug("non-existent");

                Assert.Null(entry);
            }
        }
        public void Search_results_include_searched_term()
        {
            var store = new TestableStore();

            using (var tagsController = new TagsController(store))
            {
                using (var session = store.OpenSession())
                {
                    RavenControllerTestHelper.SetSessionOnController(tagsController, session);

                    var actionResult = tagsController.Search("blah");
                    var tags = GetTagsFromResult(actionResult);

                    Assert.Equal(1, tags.Count());
                    Assert.Equal("blah", tags.First());
                }
            }
        }
        public void Entry_deleted_flag_is_correctly_mapped()
        {
            Mapper.Reset();
            AutoMapperConfig.RegisterMappings();

            var entry = new Entry
            {
                Deleted = true
            };

            var store = new TestableStore();

            using (var session = store.OpenSession())
            {
                var entryViewModel = GetMappedEntryViewModel(session, entry);

                Assert.Equal(true, entryViewModel.Deleted);
            }

            Mapper.Reset();
        }
예제 #14
0
        public void Non_published_entry_in_database_is_not_returned_by_its_slug()
        {
            var testableStore = new TestableStore();

            string slug = "foo-slug";

            var testEntry = new Entry
            {
                Slug = slug,
                Published = false
            };

            using (var session = testableStore.OpenSession())
            {
                session.Store(testEntry);
                session.SaveChanges();

                var entryReturned = GetEntryUsingFactory(session, slug);

                Assert.Null(entryReturned);
            }
        }
예제 #15
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);
            }
        }
        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();
        }
예제 #17
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 Entry_LastModifiedAtUtc_is_correctly_mapped()
        {
            Mapper.Reset();
            AutoMapperConfig.RegisterMappings();

            var lastModifiedAtUtc = DateTimeOffset.UtcNow;

            var entry = new Entry
            {
                LastModifiedAtUtc = lastModifiedAtUtc
            };

            var store = new TestableStore();

            using (var session = store.OpenSession())
            {
                var entryViewModel = GetMappedEntryViewModel(session, entry);

                Assert.Equal(lastModifiedAtUtc, entryViewModel.LastModifiedAtUtc);
            }

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

            string id = "entries/123";

            var entry = new Entry
            {
                Id = id
            };

            var store = new TestableStore();

            using (var session = store.OpenSession())
            {
                var entryViewModel = GetMappedEntryViewModel(session, entry);

                Assert.Equal(id, entryViewModel.Id);
            }

            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 Last_modified_date_updates()
        {
            Mapper.Reset();
            AutoMapperConfig.RegisterMappings();

            var testableStore = new TestableStore();

            var entryEditModel = new EntryEditModel
            {
                LastModifiedAtUtc = DateTimeOffset.MinValue
            };

            using (var session = testableStore.OpenSession())
            {
                var entry = new Entry();

                var entryEditModelToEntryMapper = new EntryEditModelToEntryMapper(session);
                entryEditModelToEntryMapper.Map(entry, entryEditModel);

                Assert.NotEqual(entryEditModel.LastModifiedAtUtc, entry.LastModifiedAtUtc);
            }

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

            string slug = "foo-bar-baz";

            var entry = new Entry
            {
                Slug = slug
            };

            var store = new TestableStore();

            using (var session = store.OpenSession())
            {
                var entryViewModel = GetMappedEntryViewModel(session, entry);

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

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

            var testableStore = new TestableStore();

            var entryEditModel = new EntryEditModel();
            entryEditModel.Title = "Foo Title";

            string expectedSlug = "foo-title";

            using (var session = testableStore.OpenSession())
            {
                var entry = new Entry();

                var entryEditModelToEntryMapper = new EntryEditModelToEntryMapper(session);
                entryEditModelToEntryMapper.Map(entry, entryEditModel);

                Assert.Equal(expectedSlug, entry.Slug);
            }

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

            var tags = new Collection<string>(new[] { "iphone", "android" });

            var entry = new Entry
            {
                Tags = tags
            };

            var store = new TestableStore();

            using (var session = store.OpenSession())
            {
                var entryViewModel = GetMappedEntryViewModel(session, entry);

                Assert.Equal(tags, entryViewModel.Tags);
            }

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

            var testableStore = new TestableStore();

            var pubDate = DateTimeOffset.MinValue;

            using (var session = testableStore.OpenSession())
            {
                var entryEditModel = new EntryEditModel
                {
                    PublishedAtUtc = pubDate
                };

                var entry = new Entry();

                var entryEditModelToEntryMapper = new EntryEditModelToEntryMapper(session);
                entryEditModelToEntryMapper.Map(entry, entryEditModel);

                Assert.Equal(pubDate, entry.PublishedAtUtc);
            }

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

            var store = new TestableStore();

            int entryCount = 30;

            using (var entriesDashboardController = new EntriesDashboardController(store))
            {
                using (var session = store.OpenSession())
                {
                    PersistTestEntries(session, entryCount);

                    RavenControllerTestHelper.SetSessionOnController(entriesDashboardController, session);

                    var queryModel = GetDefaultQueryModel();

                    var actionResult = entriesDashboardController.Fetch(queryModel);
                    var entryEditModels = GetEntryEditModelsFromResult(actionResult);

                    Assert.Equal(queryModel.PageSize, entryEditModels.Count());
                }
            }
        }
        public void Save_persists_valid_entry_to_database()
        {
            Mapper.Reset();
            AutoMapperConfig.RegisterMappings();

            var store = new TestableStore();

            using (var entriesController = new EntriesController(store))
            {
                using (var session = store.OpenSession())
                {
                    RavenControllerTestHelper.SetSessionOnController(entriesController, session);
                    entriesController.Save(new EntryEditModel() { Title = "foo" });

                    var savedEntry = session.Query<Entry>()
                        .FirstOrDefault(e => e.Title == "foo");

                    Assert.NotNull(savedEntry);
                }
            }

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

            string id = "foo/123";

            var store = new TestableStore();

            using (var pagesController = new PagesController(store))
            {
                using (var session = store.OpenSession())
                {
                    RavenControllerTestHelper.SetSessionOnController(pagesController, session);
                    pagesController.Save(new PageEditModel() { Id = id, Title = "foo" });
                }
            }

            Assert.True(store.Contains(id));

            Mapper.Reset();
        }
예제 #30
0
        public void Published_entry_in_database_is_successfully_returned_by_its_slug()
        {
            var testableStore = new TestableStore();

            string slug = "foo-slug";
            string title = "Foo Title";

            var testEntry = new Entry
            {
                Slug = slug,
                Title = title,
                Published = true
            };

            using (var session = testableStore.OpenSession())
            {
                session.Store(testEntry);
                session.SaveChanges();

                var entryReturned = GetEntryUsingFactory(session, slug);

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