Пример #1
0
        public void ShouldThrowExceptionWhenUpdatePostHasMoreThanOneVideo()
        {
            #region Variables

            var param = new Common.Contracts.Post
            {
                PostContents = new List<Common.Contracts.PostContent>
                               {
                                   new Common.Contracts.PostContent
                                   {
                                       Media = new Common.Contracts.Media
                                               {
                                                   MediaType = "video/mp4"
                                               }
                                   },
                                   new Common.Contracts.PostContent
                                   {
                                       Media = new Common.Contracts.Media
                                               {
                                                   MediaType = "video/avi"
                                               }
                                   }
                               },
                Tags = null,
                PostTitle = "Foo",
                PostMessage = "Lorem Ipsum Dolor",
                User = new Common.Contracts.User { Id = 1, UserName = "******" }
            };

            #endregion

            _postRepository = new Mock<IPostRepository>();
            _postContentRepository = new Mock<IPostContentRepository>();
            _mediaRepository = new Mock<IMediaRepository>();

            _postsLogic = new PostsLogic(_postRepository.Object, _postContentRepository.Object,
                _mediaRepository.Object);

            Assert.Throws<BlogException>(() => _postsLogic.UpdatePost(param));
        }
Пример #2
0
        public void ShouldThrowExceptionWhenUpdatePostFails()
        {
            #region Variables

            var param = new Common.Contracts.Post
            {
                PostContents = null,
                Tags = null,
                PostTitle = "Foo",
                PostMessage = "Lorem Ipsum Dolor",
                User = new Common.Contracts.User { Id = 1, UserName = "******" }
            };

            #endregion

            _postRepository = new Mock<IPostRepository>();
            _postRepository.Setup(a => a.Edit(It.IsAny<Post>())).Throws(new Exception());

            _postContentRepository = new Mock<IPostContentRepository>();
            _mediaRepository = new Mock<IMediaRepository>();

            _postsLogic = new PostsLogic(_postRepository.Object, _postContentRepository.Object,
                _mediaRepository.Object);

            Assert.Throws<BlogException>(() => _postsLogic.UpdatePost(param));
        }
Пример #3
0
        public void ShouldSetPostContentsToNullWhenEmptyOnPostCleanUp()
        {
            var param = new Common.Contracts.Post
            {
                PostContents = null
            };

            _postRepository = new Mock<IPostRepository>();
            _postContentRepository = new Mock<IPostContentRepository>();
            _mediaRepository = new Mock<IMediaRepository>();

            _postsLogic = new PostsLogic(_postRepository.Object, _postContentRepository.Object,
                _mediaRepository.Object);

            var result = _postsLogic.PostCleanUp(param);

            Assert.IsNotNull(result);
            Assert.IsNull(result.PostContents);
        }
Пример #4
0
        public void ShouldUpdatePost()
        {
            #region Variables

            var dbResult = new Post
            {
                PostId = 3,
                PostLikes = null,
                PostContents = _postContents.Where(a => a.PostId == 1).ToList(),
                Comments = null,
                Tags = _tags.Where(a => a.TagId != 3).ToList(),
                PostTitle = "Foo",
                PostMessage = "Lorem Ipsum Dolor",
                UserId = 1,
                User = new User { UserId = 1, UserName = "******" }
            };
            var param = new Common.Contracts.Post
            {
                PostContents = new List<Common.Contracts.PostContent>
                {
                    new Common.Contracts.PostContent
                    {
                        Id = 1,
                        PostContentTitle = "Foo",
                        PostContentText = "Lorem Ipsum Dolor",
                        PostId = 1,
                        Media = new Common.Contracts.Media()
                    },
                    new Common.Contracts.PostContent
                    {
                        Id = 2,
                        PostContentTitle = "Bar",
                        PostContentText = "Lorem Ipsum Dolor",
                        PostId = 1,
                        Media = new Common.Contracts.Media()
                    }
                },
                Tags = new List<Common.Contracts.Tag>
                {
                    new Common.Contracts.Tag
                    {
                        TagId = 1,
                        TagName = "lorem"
                    },
                    new Common.Contracts.Tag
                    {
                        TagId = 2,
                        TagName = "ipsum"
                    }
                },
                PostTitle = "Foo",
                PostMessage = "Lorem Ipsum Dolor",
                User = new Common.Contracts.User { Id = 1, UserName = "******" }
            };

            #endregion

            _postRepository = new Mock<IPostRepository>();
            _postRepository.Setup(a => a.Edit(It.IsAny<Post>())).Returns(new Post { PostId = 3 });
            _postRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Post, bool>>>(),
                It.IsAny<Func<IQueryable<Post>, IOrderedQueryable<Post>>>(), It.IsAny<string>()))
                .Returns(new List<Post> { dbResult });

            var postContents = _postContents.Where(a => a.PostId == 1).ToList();
            _postContentRepository = new Mock<IPostContentRepository>();
            _postContentRepository.Setup(a => a.Find(It.IsAny<Expression<Func<PostContent, bool>>>(), true))
                .Returns(postContents);

            
            _mediaRepository = new Mock<IMediaRepository>();

            _postsLogic = new PostsLogic(_postRepository.Object, _postContentRepository.Object,
                _mediaRepository.Object);

            var result = _postsLogic.UpdatePost(param);

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Id);
        }
Пример #5
0
        public void ShouldSetCommunitiesToListPostWhenNullOnPostCleanUp()
        {
            var param = new Common.Contracts.Post
            {
                Communities = null
            };

            _postRepository = new Mock<IPostRepository>();
            _postContentRepository = new Mock<IPostContentRepository>();
            _mediaRepository = new Mock<IMediaRepository>();

            _postsLogic = new PostsLogic(_postRepository.Object, _postContentRepository.Object,
                _mediaRepository.Object);

            var result = _postsLogic.PostCleanUp(param);

            Assert.IsNotNull(result);
            Assert.IsInstanceOf(typeof(List<Common.Contracts.Community>), result.Communities);
        }