Example #1
0
 public void PostPosts_ShouldMapToCreate()
 {
     var post = new Post();
     "~/posts"
         .WithMethod(HttpVerbs.Post)
         .WithValue("post", post)
         .WithValue("authorId", 1)
         .ShouldMapTo<PostsController>(c => c.Create(post, 1));
 }
Example #2
0
 public void PutPost_ShouldMapToUpdate()
 {
     var post = new Post();
     "~/posts/{id}"
         .WithMethod(HttpVerbs.Put)
         .WithValue("post", post)
         .WithValue("authorId", 1)
         .ShouldMapTo<PostsController>(c => c.Update(post, 1));
 }
Example #3
0
        public ActionResult Create(Post post, int authorId)
        {
            if (ModelState.IsValid) {
                post.Author = repository.Find<Account>(x => x.Id == authorId);
                repository.Save(post);
                return RedirectToAction("Index");
            }

            return RedirectToAction("New");
        }
        public void Create_ShouldValidateThePost()
        {
            const int authorId = 1;
            var post = new Post ();
            controller.SetupContext(post);

            controller.Create(post, authorId);

            Assert.IsFalse(controller.ModelState.IsValid);
        }
        public void Edit_ShouldFindAndSetTheAuthor()
        {
            const int authorId = 1;
            var post = new Post();
            repository.Stub(p => p.Find<Account>(x => true)).IgnoreArguments().Return(new Account());
            repository.Stub(p => p.Save(post)).Return(post);

            var result = controller.Update(post, authorId);

            Assert.IsTrue(controller.ModelState.IsValid);
            Assert.That(result.View(), Is.EqualTo("Show"));
        }
Example #6
0
 public static IHtmlString PostSearchResult(this HtmlHelper html, Post post, string query)
 {
     var titleMatch = post.Title.Excerpt(query, 30).Highlight(query);
     var bodyMatch = post.Body.Excerpt(query, 30).Highlight(query);
     return new HtmlString(titleMatch + bodyMatch);
 }
Example #7
0
        public ActionResult Update(Post post, int authorId)
        {
            if (ModelState.IsValid)
            {
                post.Author = repository.Find<Account>(x => x.Id == authorId);
                repository.Save(post);
                return RedirectToAction("Show", post.Id);
            }

            ViewBag.Authors = repository.FindAll<Account>();
            var refreshedPost = repository.Find<Post>(x => x.Id == post.Id);

            return View("Edit", new { post = refreshedPost });
        }
        public void Edit_ShouldIncludeAuthorsInViewBagAndSetPost()
        {
            const int postId = 1;
            var post = new Post();
            var allAccounts = new List<Account>();
            repository.Stub(p => p.FindAll<Account>()).Return(allAccounts);
            repository.Stub(p => p.Find<Post>(x => true)).IgnoreArguments().Return(post);

            var result = (ViewResult)controller.Edit(postId);

            Assert.IsTrue(result.ViewBag.Authors.Equals(allAccounts));
            Assert.IsTrue(result.Model.Equals(post));
        }