Esempio n. 1
0
        public ViewResult CreatePost(Post post)
        {
            ThrowExceptionWithNullArgument(post);

            repository.InsertPost(post);

            return View("CreatePost", post);
        }
        public void CreatePostIsSuccessfulWithValidData()
        {
            var post = new Post() { Title = "test", Content = "empty", Uri = "archive/2009/01/01/hello" };

            var result = controller.CreatePost(post) as ViewResult;

            fakePostRepository.Verify(x => x.InsertPost(post));
        }
        public bool Create()
        {
            var post = new Post { Title = title, Content = content, Uri = uri };

            var controller = new PostController();

            var result = controller.CreatePost(post) as ViewResult;

            var createdPost = (Post) result.ViewData.Model;

            return createdPost.ID > 0;
        }
        public void ShouldCreateAndRetrievePost()
        {
            var repository = new PostRepository(connection, transaction);

            var post = new Post{ Title = "test", Content = "empty", Uri = "archive/2009/01/01/hello" };

            repository.InsertPost(post);

            var retrievedPost = repository.GetPostByUri(post.Uri);

            Assert.AreEqual(retrievedPost.Title, post.Title);
            Assert.AreEqual(retrievedPost.Content, post.Content);
            Assert.AreEqual(retrievedPost.Uri, post.Uri);
        }
        public void RetrievePostWithValidUri()
        {
            var post = new Post() { Title = "test", Content = "empty", Uri = "archive/2009/01/01/hello" };
            fakePostRepository.Setup(x => x.GetPostByUri(post.Uri)).Returns(post);

            var result = controller.RetrievePostByUri(post.Uri) as ViewResult;

            var persistedPost = (Post)result.ViewData.Model;

            Assert.AreEqual(persistedPost.Title, post.Title);
            Assert.AreEqual(persistedPost.Content, post.Content);
            Assert.AreEqual(persistedPost.Uri, post.Uri);
            fakePostRepository.Verify(x => x.GetPostByUri(post.Uri));
        }
        private bool validateReturnedPost(Post post)
        {
            if (post.ID == 0)
                return false;

            if (post.Title != title)
                return false;

            if (post.Content != content)
                return false;

            if (post.Uri != uri)
                return false;

            return true;
        }
 public override void InsertPost(Post post)
 {
     insertWasCalled = true;
 }
Esempio n. 8
0
 private void ThrowExceptionWithNullArgument(Post post)
 {
     if (post == null)
         throw new ArgumentNullException("invalid post");
 }