public void Save_UpdatePost() { using (var fixture = new FixtureInit("http://localhost")) { //arrange var repository = new BlogPostsRepository(fixture.Setup.Context); var post = new BlogPost { Url = "Some-new-post", Title = "Some new post", Body = "<p>This is new post in blog</p>", CreatedBy = "AlexanderB", CreatedDate = DateTime.Now }; repository.Save(post); var blogPost = repository.BlogPosts.Where(p => p.Url == post.Url).Single(); // act blogPost.Title += "(updated)"; repository.Save(blogPost); //assert var updatedPost = repository.BlogPosts.Where(p => p.Url == post.Url).Single(); Assert.That(updatedPost.Title, Is.EqualTo("Some new post(updated)")); } }
public void Save(BlogPost blogPost) { if (blogPost.Id == 0 && _context.BlogPosts.WithUrl(blogPost.Url) != null) { throw new DuplicateKeyException(blogPost, "Blog post with the same URL already exists. Please correct blog post title."); } if (blogPost.Id == 0) { _context.BlogPosts.InsertOnSubmit(blogPost); } _context.SubmitChanges(); }
private static void SubmitTenBlogpostsToRepository(BlogPostsRepository repository) { for (var blog = 0; blog < 10; blog++) { var post = new BlogPost { Url = "Url-" + blog, Title = "Some new post: " + blog, Body = "<p>This is new post in blog</p>", CreatedBy = "AlexanderB", CreatedDate = (DateTime.Now.AddDays(blog)) }; repository.Save(post); } }
public void SaveBlogPost() { using (var fixture = new FixtureInit("http://localhost")) { //arrange var repository = new BlogPostsRepository(fixture.Setup.Context); var post = new BlogPost { Url = "Some-new-post", Title = "Some new post", Body = "<p>This is new post in blog</p>", CreatedBy = "AlexanderB", CreatedDate = DateTime.Now }; //act repository.Save(post); //assert Assert.That(post.Id, Is.GreaterThan(0)); } }
private static Mock<IBlogPostsRepository> CreateRepositoryMock(int blogPostsCount = 10) { var blogRepositoryMock = new Mock<IBlogPostsRepository>(); var posts = new List<BlogPost>(); for (var blog = 0; blog < blogPostsCount; blog++) { var post = new BlogPost { Url = "Url-" + blog, Title = "Some new post: " + blog, Body = "<p>This is new post in blog</p>", CreatedDate = (DateTime.Now.AddDays(blog)) }; posts.Add(post); } blogRepositoryMock.Setup(b => b.BlogPosts).Returns(posts.AsQueryable()); return blogRepositoryMock; }
public BlogPostProcessor(BlogPost post) { _post = post; }
public static string GetPostBody(BlogPost post) { var processor = new BlogPostProcessor(post); return processor.GetPostBody(); }
public void DeletePost() { using (var fixture = new FixtureInit("http://localhost")) { //arrange var repository = new BlogPostsRepository(fixture.Setup.Context); var post = new BlogPost { Url = "Some-new-post", Title = "Some new post", Body = "<p>This is new post in blog</p>", CreatedBy = "AlexanderB", CreatedDate = DateTime.Now }; repository.Save(post); //act repository.Delete(post); //assert var foundTask = repository.BlogPosts.WithId(post.Id); Assert.That(foundTask, Is.Null); } }
public void AddPost_Post_UrlForPost_Is_Created() { //arrange var blogRepository = new Mock<IBlogPostsRepository>(); var submittedPosts = new List<BlogPost>(); blogRepository.Setup(b => b.Save(It.IsAny<BlogPost>())).Callback((BlogPost p) => submittedPosts.Add(p)); var blogManagement = new BlogManagementController(blogRepository.Object); var model = new BlogPost { Title = "Hey Joe" }; //act var result = blogManagement.AddPost(model) as ViewResult; //post var post = submittedPosts.First(); Assert.That(model.Url, Is.EqualTo("hey-joe")); }
public void AddPost_Post_Url_Contains_No_Punctuation() { //arrange var blogRepository = new Mock<IBlogPostsRepository>(); var submittedPosts = new List<BlogPost>(); blogRepository.Setup(b => b.Save(It.IsAny<BlogPost>())) .Callback((BlogPost p) => { if (submittedPosts.Find(x => x.Url == p.Url) != null) { throw new Exception(); } submittedPosts.Add(p); } ); var blogManagement = new BlogManagementController(blogRepository.Object); var model = new BlogPost { Title = "Hey, Joe.!:;" }; //act var result = blogManagement.AddPost(model) as ViewResult; //post var post = submittedPosts.First(); Assert.That(model.Url, Is.EqualTo("hey-joe")); }
public void AddPost_Post_CreatedDate_Contains_HourMinutesSeconds() { //arrange var blogRepository = new Mock<IBlogPostsRepository>(); var submittedPosts = new List<BlogPost>(); blogRepository.Setup(b => b.Save(It.IsAny<BlogPost>())) .Callback((BlogPost p) => { if (submittedPosts.Find(x => x.Url == p.Url) != null) { throw new Exception(); } submittedPosts.Add(p); } ); var blogManagement = new BlogManagementController(blogRepository.Object); var model = new BlogPost { Title = "Hey Joe" }; //act var result = blogManagement.AddPost(model) as ViewResult; //post var post = submittedPosts.First(); Assert.That(post.CreatedDate, Is.Not.Null); Assert.That(post.CreatedDate.ToLongTimeString(), Is.Not.EqualTo("00:00:00")); }
public void AddPost_Post_NotAddPost_With_SameUrl() { //arrange var blogRepository = new Mock<IBlogPostsRepository>(); var submittedPosts = new List<BlogPost>(); blogRepository.Setup(b => b.Save(It.IsAny<BlogPost>())) .Callback((BlogPost p) => { if (submittedPosts.Find(x => x.Url == p.Url) != null) { throw new Exception(); } submittedPosts.Add(p); } ); var blogManagement = new BlogManagementController(blogRepository.Object); var model = new BlogPost { Title = "Hey Joe" }; //act var result = blogManagement.AddPost(model) as ViewResult; result = blogManagement.AddPost(model) as ViewResult; //post Assert.That(blogManagement.ModelState[""].Errors[0].ErrorMessage, Is.EqualTo("Post could not be added. Exception of type 'System.Exception' was thrown.")); }
partial void DeleteBlogPost(BlogPost instance);
partial void UpdateBlogPost(BlogPost instance);
partial void InsertBlogPost(BlogPost instance);