Inheritance: DataModel
Ejemplo n.º 1
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");
 }
Ejemplo n.º 2
0
        public void UpdateForSave_ShouldSetModifiedTime()
        {
            var dataModel = new Post();

            var theDate = DateTime.Now;
            dataModel.UpdateForSave(theDate);

            Assert.That(dataModel.ModifiedDate, Is.EqualTo(theDate));
        }
Ejemplo n.º 3
0
        public void UpdateForSave_ShouldSetCreatedTime_WhenIdNotSet()
        {
            var dataModel = new Post();

            var theDate = DateTime.Now;
            dataModel.UpdateForSave(theDate);

            Assert.That(dataModel.CreatedDate, Is.EqualTo(theDate));
        }
        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"));
        }
Ejemplo n.º 6
0
        public ActionResult Update(Post post, int authorId)
        {
            if (ModelState.IsValid) {
                post.Author = new Account { 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));
        }