public void ShouldReturnEmptyListWhenGetViewCountFoundNoRecords()
        {
            _viewCountRepository = new Mock<IViewCountRepository>();
            _viewCountRepository.Setup(a => a.Find(It.IsAny<Expression<Func<ViewCount, bool>>>(), true))
                .Returns(new List<ViewCount>());

            _viewCountLogic = new ViewCountLogic(_viewCountRepository.Object);

            var result = _viewCountLogic.Get(1);

            Assert.NotNull(result);
            Assert.AreEqual(0, result.Count);
        }
        public void ShouldGetViewCounts()
        {
            var viewCount = _viewCount.Where(a => a.PostId == 1).ToList();
            _viewCountRepository = new Mock<IViewCountRepository>();
            _viewCountRepository.Setup(a => a.Find(It.IsAny<Expression<Func<ViewCount, bool>>>(), true))
                .Returns(viewCount);

            _viewCountLogic = new ViewCountLogic(_viewCountRepository.Object);

            var result = _viewCountLogic.Get(1);

            Assert.AreEqual(2, result.Count);
            Assert.AreEqual(1, result[0].PostId);
            Assert.AreEqual(1, result[1].PostId);
        }
        public void ShouldAddViewCount()
        {
            var viewCount = new ViewCount
            {
                Id = 4,
                PostId = 1,
                UserId = 1
            };

            _viewCountRepository = new Mock<IViewCountRepository>();
            _viewCountRepository.Setup(a => a.Add(It.IsAny<ViewCount>()))
                .Returns(viewCount);

            _viewCountLogic = new ViewCountLogic(_viewCountRepository.Object);

            var result = _viewCountLogic.Add(new Common.Contracts.ViewCount
            {
                PostId = 1,
                UserId = 1
            });

            Assert.NotNull(result);
            Assert.AreEqual(4, result.Id);
        }
        public void ShouldThrowExceptionWhenGetViewCountFails()
        {
            _viewCountRepository = new Mock<IViewCountRepository>();
            _viewCountRepository.Setup(a => a.Find(It.IsAny<Expression<Func<ViewCount, bool>>>(), true))
                .Throws(new Exception());

            _viewCountLogic = new ViewCountLogic(_viewCountRepository.Object);

            Assert.Throws<BlogException>(() => _viewCountLogic.Get(1));
        }
        public void ShouldThrowExceptionWhenAddViewCountFails()
        {
            _viewCountRepository = new Mock<IViewCountRepository>();
            _viewCountRepository.Setup(a => a.Add(It.IsAny<ViewCount>())).Throws(new Exception());

            _viewCountLogic = new ViewCountLogic(_viewCountRepository.Object);

            Assert.Throws<BlogException>(() => _viewCountLogic.Add(new Common.Contracts.ViewCount()));
        }