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 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)); }