Пример #1
0
        public void Add(Post element)
        {
            element.PublishDate = DateTime.Now; //ToDo Abstract with interface

            _dataContext.Posts.Add(element);
            _dataContext.SaveChanges();
        }
Пример #2
0
        public void Delete(Post element)
        {
            var post = _dataContext.Posts.SingleOrDefault(p => p.Id == element.Id);
            _dataContext.Posts.Remove(post);

            _dataContext.SaveChanges();
        }
Пример #3
0
        public void Content_FailModelValidationIfContentIsMissing()
        {
            var sut = new Post { PublishDate = new DateTime(2013, 2, 4), Content = null, Title = TitleValue, Author = AuthorValue };

            int errorCount = Mother.ValidateModel(sut).Count;

            Assert.AreEqual(1, errorCount);
        }
Пример #4
0
        public void Content_GenerateTheCorrectErrorMessageIfContentIsMissing()
        {
            var sut = new Post { PublishDate = new DateTime(2013, 2, 4), Content = null, Title = TitleValue, Author = AuthorValue };

            IList<ValidationResult> result = Mother.ValidateModel(sut);
            string errorMessage = result[0].ErrorMessage;

            Assert.AreEqual("Content is required", errorMessage);
        }
Пример #5
0
        public ActionResult Create(Post post)
        {
            if (ModelState.IsValid)
            {
                PostRepository.Add(post);
                return RedirectToAction("Index");
            }

            return View(post);
        }
Пример #6
0
 public void Update(Post post)
 {
     _dataContext.SetModified(post);
     _dataContext.SaveChanges();
 }
Пример #7
0
        public ViewResult Create()
        {
            var post = new Post {Author = User.Identity.Name};

            return View(post);
        }
Пример #8
0
        public void ModeratedCommentCount_Return0IfPostCommentsAreNull()
        {
            var sut = new Post
                {
                    Comments = null,
                };

            int result = sut.ModeratedCommentCount;

            Assert.AreEqual(0, result);
        }
Пример #9
0
        public void Title_GenerateTheCorrectErrorMessageIfTitleIsAnEmptyString()
        {
            var sut = new Post { PublishDate = new DateTime(2013, 2, 4), Content = ContentValue, Title = string.Empty, Author = AuthorValue };

            IList<ValidationResult> result = Mother.ValidateModel(sut);
            string errorMessage = result[0].ErrorMessage;

            Assert.AreEqual("Title is required", errorMessage);
        }
Пример #10
0
        public void Title_FailModelValidationIfTitleIsAnEmptyString()
        {
            var sut = new Post { PublishDate = _publishedDate, Content = ContentValue, Title = string.Empty, Author = AuthorValue };

            int errorCount = Mother.ValidateModel(sut).Count;

            Assert.AreEqual(1, errorCount);
        }
Пример #11
0
        public void ModeratedCommentCount_ReturnTheCorrectCountForModeratedComments()
        {
            var sut = new Post
                {
                    Comments = new List<Comment>
                        {
                            new Comment{HasBeenModerated = true},
                            new Comment{HasBeenModerated = true},
                            new Comment {HasBeenModerated = false},
                        }
                };

            int result = sut.ModeratedCommentCount;

            Assert.AreEqual(2, result);
        }