コード例 #1
0
        public void ShouldGetCommunityId()
        {
            var communitySearch = new Community
                                  {
                                      Id = 1,
                                      LeaderUserId = 1,
                                      Leader = _members.FirstOrDefault(a => a.UserId == 1),
                                      Members = _members.ToList(),
                                      Posts = new List<Post> { new Post { PostId = 1 } }
                                  };

            _communityRepository = new Mock<ICommunityRepository>();
            _communityRepository.Setup(a => a.Get(It.IsAny<int>())).Returns(communitySearch);
            _communityRepository.Setup(a => a.GetMemberCountByCommunity(It.IsAny<int>())).Returns(5);

            var logic = new CommunityLogic(_communityRepository.Object);
            var result = logic.Get(1);

            Assert.NotNull(result);
            Assert.NotNull(result.Posts);
            Assert.IsNull(result.Error);
            Assert.AreEqual(5, result.MemberCount);
        }
コード例 #2
0
        public void ShouldDeleteCommunity()
        {
            var community = new Community { Id = 1, Name = "lorem", Description = "fudge brownies" };

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

            var logic = new CommunityLogic(_communityRepository.Object);
            var result = logic.Delete(1);

            Assert.IsTrue(result);
        }
コード例 #3
0
        public void ShouldThrowExceptionWhenDeletingCommunityFails()
        {
            var community = new Community { Id = 1, Name = "lorem", Description = "fudge brownies" };

            _communityRepository = new Mock<ICommunityRepository>();
            _communityRepository.Setup(a => a.Delete(It.IsAny<Community>())).Throws(new Exception("Hooha!"));
            _communityRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Community, bool>>>(), false))
                .Returns(new List<Community> { community });

            var logic = new CommunityLogic(_communityRepository.Object);

            Assert.Throws<BlogException>(() => logic.Delete(1));
        }
コード例 #4
0
        public void ShouldUpdateCommunity()
        {
            var community = new Community { Id = 1, Name = "lorem", Description = "fudge brownies" };

            _communityRepository = new Mock<ICommunityRepository>();
            _communityRepository.Setup(a => a.Edit(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.Update(new Common.Contracts.Community
            {
                Id = 1,
                Name = "lorem",
                Description = "fudge brownies"
            });

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