예제 #1
0
        public void ShouldThrowExceptionWhenGetCommunityByIdFails()
        {
            _communityRepository = new Mock<ICommunityRepository>();
            _communityRepository.Setup(a => a.Get(It.IsAny<int>())).Throws(new Exception("Hooha!"));

            var logic = new CommunityLogic(_communityRepository.Object);

            Assert.Throws<BlogException>(() => logic.Get(1));
        }
예제 #2
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);
        }
예제 #3
0
        public void ShouldReturnErrorWhenGetCommunityIdFoundNoRecords()
        {
            _communityRepository = new Mock<ICommunityRepository>();
            _communityRepository.Setup(a => a.Get(It.IsAny<int>())).Returns((Community)null);

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

            Assert.NotNull(result.Error);
            Assert.AreEqual((int)Constants.Error.RecordNotFound, result.Error.Id);
            Assert.AreEqual("Cannot find community with Id 1", result.Error.Message);
        }