public void PostIsMappedFromModelWithPublishingDateSameAsCreatedWhenNotSet()
        {
            var model = new PostEditModel { Title = "Post title", Tags = "music , movie , multiple words ; other separator", Created = DateTime.Now };
            var post = Mapper.Map<PostEditModel, Post>(model);

            Assert.That(post.Created, Is.EqualTo(model.Created));
            Assert.That(post.PublishFrom, Is.EqualTo(model.Created));
        }
        public void PostIsMappedFromModelWithPublishingDateWhenSet()
        {
            var model = new PostEditModel { Title = "Post title", Tags = "music , movie , multiple words ; other separator", Created = new DateTime(2009, 8, 7, 6, 5, 4, DateTimeKind.Local), PublishFrom = new DateTime(2009, 1, 2, 3, 4, 5, DateTimeKind.Local) };
            var post = Mapper.Map<PostEditModel, Post>(model);

            Assert.That(post.Created, Is.EqualTo(model.Created));
            Assert.That(post.PublishFrom, Is.EqualTo(model.PublishFrom));
            Assert.That(post.PublishFrom, Is.Not.EqualTo(model.Created));
        }
        public void PostIsMappedFromModelUsingConstructorButWithoutUpdatingPasswordWhenPasswordIsNotSet()
        {
            var model = new PostEditModel { Title = "Post title", Tags = "music , movie , multiple words ; other separator" };
            var post = Mapper.Map<PostEditModel, Post>(model);

            Assert.That(post.Tags, Has.Count.EqualTo(4));
            Assert.That(post.Tags[0].Name, Is.EqualTo("music"));
            Assert.That(post.Tags[2].Name, Is.EqualTo("multiple words"));
        }
Beispiel #4
0
        public ActionResult Edit(PostEditModel model)
        {
            if (ModelState.IsValid)
            {
                var post = Mapper.Map<PostEditModel, Post>(model);
                session.Save<Post>(post);
                return RedirectToAction("Index");
            }

            return View(model);
        }
Beispiel #5
0
        public void PostIsMappedFromModelUsingConstructor()
        {
            var model = new PostEditModel {Title = "The title", Tags = "music,movie", Body = "The body"};
            var post = Mapper.Map<PostEditModel, Post>(model);

            Assert.That(post.Title, Is.EqualTo(model.Title));
            Assert.That(post.Body, Is.EqualTo(model.Body));
            Assert.That(post.Comments, Is.Empty);
            Assert.That(post.Created, Is.Not.Null);
            Assert.That(post.Uri, Is.EqualTo(model.Title.ToUri()));
            Assert.That(post.Tags, Has.Count.EqualTo(2));
        }