Exemple #1
0
        public void CreatePostContentTest()
        {
            PostAuthoringController sut = new PostAuthoringController(
                _postRepo,
                _postModificationRepo,
                _userRepo,
                _redirectRepo,
                _securableRepo,
                _blogRepo,
                _mockSecurityHelper.Object,
                new DateTimeProvider(),
                _mockHttpContext.Object);

            var result = sut.Create(new Areas.Manage.Models.PostEditModel
            {
                Title       = "Test Title",
                Body        = "Test Body",
                Description = "Test Description",
                Reposted    = false
            }) as RedirectToRouteResult;

            Assert.IsNotNull(result);

            Assert.AreEqual("Index", result.RouteValues["action"]);
            Assert.AreEqual("Dashboard", result.RouteValues["controller"]);

            Assert.AreEqual(2, _postRepo.GetAll().Count());
            Assert.IsNull(_postRepo.GetAll().Last().Title);
            Assert.IsNull(_postRepo.GetAll().Last().Body);
            Assert.IsNull(_postRepo.GetAll().Last().Description);
            Assert.AreEqual("Test Title", _postRepo.GetAll().Last().DraftTitle);
            Assert.AreEqual("Test Body", _postRepo.GetAll().Last().DraftBody);
            Assert.AreEqual("Test Description", _postRepo.GetAll().Last().DraftDescription);
        }
Exemple #2
0
        public void CreatePostRepostedTest()
        {
            PostAuthoringController sut = new PostAuthoringController(
                _postRepo,
                _postModificationRepo,
                _userRepo,
                _redirectRepo,
                _securableRepo,
                _blogRepo,
                _mockSecurityHelper.Object,
                new MockDateTimeProvider(new DateTime(2013, 1, 2)),
                _mockHttpContext.Object);

            var result = sut.Create(new Areas.Manage.Models.PostEditModel
            {
                Title        = "Test Title",
                Body         = "Test Body",
                Description  = "Test Description",
                Reposted     = true,
                CanonicalUrl = "http://someotherblog.com/post"
            }) as RedirectToRouteResult;

            Assert.IsNotNull(result);

            Assert.AreEqual("Index", result.RouteValues["action"]);
            Assert.AreEqual("Dashboard", result.RouteValues["controller"]);

            Assert.AreEqual(2, _postRepo.GetAll().Count());
            Assert.AreEqual("http://someotherblog.com/post", _postRepo.GetAll().Last().Canonical);
        }
Exemple #3
0
        public void EditPostContentTest()
        {
            var postRepo = new SimpleRepository <Post>(new InMemoryRepositoryDataSource <Post>(new List <Post> {
                new Post {
                    Id          = 1,
                    Status      = PostStatus.Published,
                    Title       = "Test Title",
                    Description = "Test Description",
                    Body        = "Test Body",
                    Path        = "2013/04/9/some-other-post",
                    Posted      = new DateTime(2013, 4, 9),
                    Author      = new User {
                        Email = ""
                    },
                    BlogId = 1
                }
            }));

            PostAuthoringController sut = new PostAuthoringController(
                postRepo,
                _postModificationRepo,
                _userRepo,
                _redirectRepo,
                _securableRepo,
                _blogRepo,
                _mockSecurityHelper.Object,
                new DateTimeProvider(),
                _mockHttpContext.Object);

            var result = sut.Edit(1, new Areas.Manage.Models.PostEditModel
            {
                Title        = "New Title",
                Body         = "New Body",
                Description  = "New Description",
                Reposted     = true,
                CanonicalUrl = "http://blog.con/new-post"
            }) as RedirectToRouteResult;

            Assert.IsNotNull(result);

            Assert.AreEqual("Index", result.RouteValues["action"]);
            Assert.AreEqual("Dashboard", result.RouteValues["controller"]);

            Assert.AreEqual(1, postRepo.GetAll().Count());
            Assert.IsTrue(postRepo.GetAll().Last().HasDraftContent());
            Assert.AreEqual("Test Title", postRepo.GetAll().Last().Title);
            Assert.AreEqual("Test Body", postRepo.GetAll().Last().Body);
            Assert.AreEqual("Test Description", postRepo.GetAll().Last().Description);
            Assert.AreEqual("New Title", postRepo.GetAll().Last().DraftTitle);
            Assert.AreEqual("New Body", postRepo.GetAll().Last().DraftBody);
            Assert.AreEqual("New Description", postRepo.GetAll().Last().DraftDescription);
            Assert.AreEqual("http://blog.con/new-post", postRepo.GetAll().Last().Canonical);            //TODO Change this so that its also draft
        }
Exemple #4
0
        public void CannotEditPostWhenNotInCurrentBlog()
        {
            var postRepo = new SimpleRepository <Post>(new InMemoryRepositoryDataSource <Post>(new List <Post> {
                new Post {
                    Id          = 1,
                    Status      = PostStatus.Published,
                    Title       = "Test Title",
                    Description = "Test Description",
                    Body        = "Test Body",
                    Path        = "2013/04/9/some-other-post",
                    Posted      = new DateTime(2013, 4, 9),
                    Author      = new User {
                        Email = ""
                    },
                    BlogId = 2
                }
            }));

            PostAuthoringController sut = new PostAuthoringController(
                postRepo,
                _postModificationRepo,
                _userRepo,
                _redirectRepo,
                _securableRepo,
                _blogRepo,
                _mockSecurityHelper.Object,
                new DateTimeProvider(),
                _mockHttpContext.Object);

            try
            {
                sut.Edit(1, new Areas.Manage.Models.PostEditModel
                {
                    Title        = "New Title",
                    Body         = "New Body",
                    Description  = "New Description",
                    Reposted     = true,
                    CanonicalUrl = "http://blog.con/new-post"
                });
                Assert.Fail("Was expecting an exception when trying to edit");
            }
            catch { }

            Assert.AreEqual(1, postRepo.GetAll().Count());
            Assert.IsFalse(postRepo.GetAll().Last().HasDraftContent());
            Assert.AreEqual("Test Title", postRepo.GetAll().Last().Title);
            Assert.AreEqual("Test Body", postRepo.GetAll().Last().Body);
            Assert.AreEqual("Test Description", postRepo.GetAll().Last().Description);
            Assert.IsNull(postRepo.GetAll().Last().DraftTitle);
            Assert.IsNull(postRepo.GetAll().Last().DraftBody);
            Assert.IsNull(postRepo.GetAll().Last().DraftDescription);
            Assert.IsNull(postRepo.GetAll().Last().Canonical);
        }
        public void PublishPostIsPostModificationRecordCreatedDraftTest()
        {
            var postRepo = new SimpleRepository <Post>(new InMemoryRepositoryDataSource <Post>(new List <Post> {
                new Post {
                    Id               = 1,
                    Status           = PostStatus.Draft,
                    DraftTitle       = "Test Title",
                    DraftDescription = "Test Description",
                    DraftBody        = "Test Body",
                    Path             = "2013/04/9/some-other-post",
                    Posted           = new DateTime(2013, 4, 9),
                    Author           = new User {
                        Email = ""
                    },
                    BlogId = 1
                }
            }));

            PostAuthoringController sut = new PostAuthoringController(
                postRepo,
                _postModificationRepo,
                _userRepo,
                _redirectRepo,
                _securableRepo,
                _blogRepo,
                _mockSecurityHelper.Object,
                new MockDateTimeProvider(new DateTime(2013, 4, 27, 1, 2, 3)),
                _mockHttpContext.Object);

            var result = sut.ConfirmPublish(1, new ConfirmPublishModel()) as JsonResult;

            Assert.IsNotNull(result);

            // This requires [assembly: InternalsVisibleTo("StaticVoid.Blog.Site.Tests")] in StaticVoid.Blog.Site so that we can read anon types, needing this is kinda lame
            // dynamic should just jams it in there by itself. I mean heck the debugger can see it, why cant dynamic?
            // cf http://stackoverflow.com/questions/2630370/c-sharp-dynamic-cannot-access-properties-from-anonymous-types-declared-in-anot
            Assert.IsTrue(((dynamic)result.Data).success);

            Assert.AreEqual(1, postRepo.GetAll().Count());
            Assert.AreEqual(1, _postModificationRepo.GetAll().Count());
            Assert.AreEqual(new DateTime(2013, 4, 27, 1, 2, 3), _postModificationRepo.GetAll().First().Timestamp);
            Assert.IsFalse(_postModificationRepo.GetAll().First().TitleModified);
            Assert.IsFalse(_postModificationRepo.GetAll().First().DescriptionModified);
            Assert.IsFalse(_postModificationRepo.GetAll().First().BodyModified);
            Assert.IsTrue(_postModificationRepo.GetAll().First().StatusModified);
            Assert.AreEqual(PostStatus.Published, _postModificationRepo.GetAll().First().NewStatus);
            Assert.IsFalse(_postModificationRepo.GetAll().First().CannonicalModified);
        }
Exemple #6
0
        public void CannotUnPublishWhenNotInCurrentBlog()
        {
            var postRepo = new SimpleRepository <Post>(new InMemoryRepositoryDataSource <Post>(new List <Post> {
                new Post {
                    Id               = 1,
                    Status           = PostStatus.Published,
                    Title            = "Test Title",
                    DraftTitle       = "Draft Title",
                    Description      = "Test Description",
                    DraftDescription = "Draft Description",
                    Body             = "Test Body",
                    DraftBody        = "Draft Body",
                    Path             = "2013/04/9/some-other-post",
                    Posted           = new DateTime(2013, 4, 9),
                    Author           = new User {
                        Email = ""
                    },
                    BlogId = 2
                }
            }));

            PostAuthoringController sut = new PostAuthoringController(
                postRepo,
                _postModificationRepo,
                _userRepo,
                _redirectRepo,
                _securableRepo,
                _blogRepo,
                _mockSecurityHelper.Object,
                new DateTimeProvider(),
                _mockHttpContext.Object);

            try
            {
                sut.ConfirmUnPublish(1, new ConfirmPublishModel());
                Assert.Fail("Was expecting an exception when trying to edit");
            }
            catch { }

            // This requires [assembly: InternalsVisibleTo("StaticVoid.Blog.Site.Tests")] in StaticVoid.Blog.Site so that we can read anon types, needing this is kinda lame
            // dynamic should just jams it in there by itself. I mean heck the debugger can see it, why cant dynamic?
            // cf http://stackoverflow.com/questions/2630370/c-sharp-dynamic-cannot-access-properties-from-anonymous-types-declared-in-anot

            Assert.AreEqual(0, _postModificationRepo.GetAll().Count());
            Assert.AreEqual(PostStatus.Published, postRepo.GetAll().First().Status);
        }
        public void EditPostNoChangeDoesNotTriggerDraftStatus()
        {
            var postRepo = new SimpleRepository <Post>(new InMemoryRepositoryDataSource <Post>(new List <Post> {
                new Post {
                    Id          = 1,
                    Status      = PostStatus.Published,
                    Title       = "Test Title",
                    Description = "Test Description",
                    Body        = "Test Body",
                    Path        = "2013/04/9/some-other-post",
                    Posted      = new DateTime(2013, 4, 9),
                    Author      = new User {
                        Email = ""
                    },
                    BlogId = 1
                }
            }));

            PostAuthoringController sut = new PostAuthoringController(
                postRepo,
                _postModificationRepo,
                _userRepo,
                _redirectRepo,
                _blogRepo,
                _mockSecurityHelper.Object,
                new DateTimeProvider(),
                _mockHttpContext.Object);

            var result = sut.Edit(1, new Areas.Manage.Models.PostEditModel
            {
                Title       = "Test Title",
                Body        = "Test Body",
                Description = "Test Description",
                Reposted    = false,
            }) as RedirectToRouteResult;

            Assert.IsNotNull(result);

            Assert.AreEqual("Index", result.RouteValues["action"]);
            Assert.AreEqual("Dashboard", result.RouteValues["controller"]);

            Assert.AreEqual(1, postRepo.GetAll().Count());
            Assert.IsFalse(postRepo.GetAll().Last().HasDraftContent());
        }
Exemple #8
0
        public void CreatePostAuthorTest()
        {
            var userRepo = new SimpleRepository <Data.User>(new InMemoryRepositoryDataSource <Data.User>(new List <Data.User> {
                new Data.User {
                    Id = 1,
                    //ClaimedIdentifier = "zzz",
                    Email = "*****@*****.**"
                }
            }));

            PostAuthoringController sut = new PostAuthoringController(
                _postRepo,
                _postModificationRepo,
                userRepo,
                _redirectRepo,
                _securableRepo,
                _blogRepo,
                _mockSecurityHelper.Object,
                new MockDateTimeProvider(new DateTime(2013, 1, 2)),
                _mockHttpContext.Object);

            var result = sut.Create(new Areas.Manage.Models.PostEditModel
            {
                Title        = "Test Title",
                Body         = "Test Body",
                Description  = "Test Description",
                Reposted     = true,
                CanonicalUrl = "http://someotherblog.com/post"
            }) as RedirectToRouteResult;

            Assert.IsNotNull(result);

            Assert.AreEqual("Index", result.RouteValues["action"]);
            Assert.AreEqual("Dashboard", result.RouteValues["controller"]);

            Assert.AreEqual(2, _postRepo.GetAll().Count());
            Assert.AreEqual(1, _postRepo.GetAll().Last().AuthorId);
        }