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); }
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); }