Пример #1
0
        public void UpdatePost_TitleIsUpdated_UpdateSlug()
        {
            IFileSystem      testFileSystem   = new FakeFileSystem();
            BlogDataStore    testDataStore    = new BlogDataStore(new FakeFileSystem());
            SlugGenerator    slugGenerator    = new SlugGenerator(testDataStore);
            ExcerptGenerator excerptGenerator = new ExcerptGenerator();

            Post post = new Post()
            {
                Slug     = "Title",
                IsPublic = true,
                PubDate  = DateTimeOffset.Now,
            };

            testDataStore.SavePost(post);

            EditedPostModel editedPost = new EditedPostModel()
            {
                Title = "Edited Title",
            };

            EditModel model = new EditModel(testDataStore, slugGenerator, excerptGenerator);

            model.OnPostPublish(post.Id, true);
            testDataStore.UpdatePost(post, post.IsPublic);

            Assert.True(testFileSystem.FileExists($"BlogFiles\\Posts\\{post.PubDate.ToFileTime()}_{post.Id}.xml"));
            Post result = testDataStore.CollectPostInfo($"BlogFiles\\Posts\\{post.PubDate.ToFileTime()}_{post.Id}.xml");

            Assert.Equal("Edited-Title", post.Slug);
        }
Пример #2
0
        public void UpdatePost_PreviouslyPublishedDraftToPublished_DoNotUpdatePubDate()
        {
            var testDataStore    = new BlogDataStore(new FakeFileSystem());
            var slugGenerator    = new SlugGenerator(testDataStore);
            var excerptGenerator = new ExcerptGenerator(140);

            var post = new Post {
                Title    = "Title",
                Slug     = "Title",
                IsPublic = false,
                PubDate  = new DateTimeOffset(new DateTime(1997, 7, 3), TimeSpan.Zero),
            };

            testDataStore.SavePost(post);

            var testEditModel = new EditModel(testDataStore, slugGenerator, excerptGenerator);

            testEditModel.PageContext = new PageContext();
            testEditModel.EditedPost  = new EditModel.EditedPostModel {
                Title   = "Edited Title",
                Excerpt = "Excerpt",
            };

            testEditModel.OnPostPublish(post.Id.ToString("N"), true);

            post = testDataStore.GetPost(post.Id.ToString("N"));

            Assert.Equal(new DateTimeOffset(new DateTime(1997, 7, 3), TimeSpan.Zero), post.PubDate);
        }
Пример #3
0
        public void UpdatePost_PreviouslyPublishedDraftToPublished_TitleIsUpdated_UpdateSlug()
        {
            var testDataStore    = new BlogDataStore(new FakeFileSystem());
            var slugGenerator    = new SlugGenerator(testDataStore);
            var excerptGenerator = new ExcerptGenerator(140);

            var post = new Post {
                Title    = "Title",
                Slug     = "Title",
                IsPublic = false,
            };

            testDataStore.SavePost(post);

            var testEditModel = new EditModel(testDataStore, slugGenerator, excerptGenerator);

            testEditModel.PageContext = new PageContext();
            testEditModel.EditedPost  = new EditModel.EditedPostModel {
                Title   = "Edited Title",
                Excerpt = "Excerpt",
            };

            testEditModel.OnPostPublish(post.Id.ToString("N"), true);

            post = testDataStore.GetPost(post.Id.ToString("N"));

            Assert.Equal("Edited-Title", post.Slug);
        }
Пример #4
0
        public void UpdatePost_PublishedToPublished_TitleIsUpdated_UpdateSlug()
        {
            BlogDataStore    testDataStore    = new BlogDataStore(new FakeFileSystem());
            SlugGenerator    slugGenerator    = new SlugGenerator(testDataStore);
            ExcerptGenerator excerptGenerator = new ExcerptGenerator(140);

            Post post = new Post {
                Title    = "Title",
                Slug     = "Title",
                IsPublic = true,
                PubDate  = DateTimeOffset.Now,
            };

            testDataStore.SavePost(post);

            EditModel testEditModel = new EditModel(testDataStore, slugGenerator, excerptGenerator);

            testEditModel.PageContext = new PageContext();
            testEditModel.EditedPost  = new EditModel.EditedPostModel {
                Title   = "Edited Title",
                Excerpt = "Excerpt",
            };

            testEditModel.OnPostPublish(post.Id.ToString("N"), true);

            post = testDataStore.GetPost(post.Id.ToString("N"));

            Assert.Equal("Edited-Title", post.Slug);
        }