Beispiel #1
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);
        }
Beispiel #2
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
        }
Beispiel #3
0
        public void UnPublishPublishPostIsPublishedDraftContent()
        {
            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 = 1
                }
            }));

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

            var result = sut.ConfirmUnPublish(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(PostStatus.Unpublished, postRepo.GetAll().First().Status);
            Assert.AreEqual("Draft Title", postRepo.GetAll().First().DraftTitle);
            Assert.AreEqual("Draft Description", postRepo.GetAll().First().DraftDescription);
            Assert.AreEqual("Draft Body", postRepo.GetAll().First().DraftBody);
        }
        public void CantPublishPostWhenItIsntInTheCurrentBlog()
        {
            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 = 2
                }
            }));

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

            try
            {
                sut.ConfirmPublish(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(1, postRepo.GetAll().Count());
            Assert.AreEqual(0, _postModificationRepo.GetAll().Count());
            Assert.AreEqual(PostStatus.Draft, 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());
        }
        public void UnPublishPublishPostIsPublishedNoDraftContent()
        {
            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.ConfirmUnPublish(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(PostStatus.Unpublished, postRepo.GetAll().First().Status);
            Assert.AreEqual("Test Title", postRepo.GetAll().First().DraftTitle);
            Assert.AreEqual("Test Description", postRepo.GetAll().First().DraftDescription);
            Assert.AreEqual("Test Body", postRepo.GetAll().First().DraftBody);
        }
        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());
        }
Beispiel #8
0
 public CachedBlogTemplateRepositoryStorage(SimpleRepository <Data.BlogTemplate> baseRepo)
 {
     CachedBlogTemplates = baseRepo.GetAll().AsNoTracking().ToList();
 }
        public void CantPublishPostWhenItIsntInTheCurrentBlog()
        {
            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 = 2 
                }}));

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

            try
            {
                sut.ConfirmPublish(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(1, postRepo.GetAll().Count());
            Assert.AreEqual(0, _postModificationRepo.GetAll().Count());
            Assert.AreEqual(PostStatus.Draft, postRepo.GetAll().First().Status);
        }
 public CachedUserRepositoryStorage(SimpleRepository <Data.User> baseRepo)
 {
     CachedUsers = baseRepo.GetAll().AsNoTracking().ToList();
 }
Beispiel #11
0
        public IEnumerable <DataSet> GetAll()
        {
            var repo = new SimpleRepository <DataSet>(con);

            return(repo.GetAll());
        }
 public CachedPostRepositoryStorage(SimpleRepository <Data.Post> baseRepo, IRepository <Data.User> userRepo)
 {
     CachedPosts = baseRepo.GetAll().AsNoTracking().ToList();
     CachedPosts.ForEach((p) => { p.Author = userRepo.GetBy(a => a.Id == p.AuthorId); });
 }
        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,
                _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
        }
        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,
                _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);
        }
Beispiel #15
0
 public CachedStyleRepositoryStorage(SimpleRepository <Data.Style> baseRepo)
 {
     CachedStyles = baseRepo.GetAll().AsNoTracking().ToList();
 }
Beispiel #16
0
        public IEnumerable <AssetBundle> GetAll()
        {
            var repo = new SimpleRepository <AssetBundle>(con);

            return(repo.GetAll());
        }
Beispiel #17
0
        public IEnumerable <T> Get()
        {
            var repo = new SimpleRepository <T>(connectionFactory);

            return(repo.GetAll());
        }
 public CachedRedirectRepositoryStorage(SimpleRepository <Data.Redirect> baseRepo)
 {
     CachedRedirects = baseRepo.GetAll().AsNoTracking().ToList();
 }