public ActionResult Edit()
 {
     var vm = new PostViewModel
     {
         Id = 500,
         Title = "Testing automapper",
         Body = "Did it work?",
         Tags = "Woodworking,Cooking"
     };
     return View(vm);
 }
 public ActionResult EditPost(PostViewModel vm)
 {
     Post post = new Post
     {
         Id = 1,
         Title = "Original title",
         Body = "Original body",
         Tags = new List<Tag>(
             new Tag[] {
                 new Tag {Id = 1, Name = "Expected"},
                 new Tag {Id = 2, Name = "To Be Overwritten"}
             })
     };
     Mapper.Map(vm, post);
     return View("Detail", post);
 }
        public void EditPost_Always_CreatesNewTagsWhenNotInTagListPassedToTheResolver()
        {
            // Arrange
            var vm = new PostViewModel { Tags = "z" };
            using (var controller = new HomeController())
            {
                // Act
                var result = controller.EditPost(vm) as ViewResult;

                // Assert
                var post = result.Model as Post;
                Assert.AreEqual(1, post.Tags.Count());
                Assert.AreEqual(0, post.Tags[0].Id);
                Assert.AreEqual("z", post.Tags[0].Name);
            }
        }
        public void EditPost_Always_UsesTagListPassedToTheResolver()
        {
            // Arrange
            var vm = new PostViewModel { Tags = "a,c,d" };
            using (var controller = new HomeController())
            {
                // Act
                var result = controller.EditPost(vm) as ViewResult;

                // Assert
                var post = result.Model as Post;
                Assert.AreEqual(3, post.Tags.Count());
                Assert.AreEqual(1, post.Tags[0].Id);
                Assert.AreEqual(3, post.Tags[1].Id);
                Assert.AreEqual(4, post.Tags[2].Id);
            }
        }