public void ShouldErrorWhenCommunityNameExistsOnAdd()
        {
            var search = _communities.Where(a => a.Id == 1).ToList();

            _communityRepository = new Mock<ICommunityRepository>();
            _communityRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Community, bool>>>(), null, null))
                .Returns(search);

            var logic = new CommunityLogic(_communityRepository.Object);
            var result = logic.Add(new Common.Contracts.Community
            {
                Name = "lorem",
                Description = "fudge brownies"
            });

            Assert.NotNull(result.Error);
            Assert.AreEqual((int)Constants.Error.ValidationError, result.Error.Id);
            Assert.AreEqual("Community name lorem is already in use.", result.Error.Message);
        }
        public void ShouldThrowExceptionWhenCheckingCommunityNameFails()
        {
            var community = new Common.Contracts.Community
            {
                Name = "lorem",
                Description = "fudge brownies"
            };

            _communityRepository = new Mock<ICommunityRepository>();
            _communityRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Community, bool>>>(), null, null))
                .Throws(new Exception("Hooha!"));

            var logic = new CommunityLogic(_communityRepository.Object);

            Assert.Throws<BlogException>(() => logic.Add(community));
        }
        public void ShouldAddCommunity()
        {
            var community = new Community { Id = 1, Name = "lorem", Description = "fudge brownies" };

            _communityRepository = new Mock<ICommunityRepository>();
            _communityRepository.Setup(a => a.Add(It.IsAny<Community>())).Returns(community);
            _communityRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Community, bool>>>(), null, null))
                .Returns(new List<Community>());

            var logic = new CommunityLogic(_communityRepository.Object);
            var result = logic.Add(new Common.Contracts.Community
                                   {
                                       Name = "lorem",
                                       Description = "fudge brownies"
                                   });

            Assert.NotNull(result);
            Assert.IsNull(result.Error);
        }