public async Task GetAllByFilterAsync_WhenGetAllAsyncFilterTakeAndSkipAre3AndBlogsExistInTheDataStore_ThenReturnNext4To6Blogs() { // Arrange IList <Blog> blogList = _blogBuilder.BuildBlogs; _mockBlogRepository .Setup(r => r.GetAllAsync()) .ReturnsAsync(blogList); int expectedResult = 3; _getAllFilterInput = new GetAllByFilterInput(skip: 3, take: 3); // Act var actualResult = await new BlogService(_mockBlogRepository.Object).GetAllByFilterAsync(_getAllFilterInput); // Assert actualResult.Count.ShouldBe(expectedResult); actualResult.Single(four => four.BlogId == 4).ShouldNotBeNull(); actualResult.Single(five => five.BlogId == 5).ShouldNotBeNull(); actualResult.Single(six => six.BlogId == 6).ShouldNotBeNull(); }
public async Task GetAllByFilterAsync_WhenGetAllAsyncFilterSkipIs0AndTakeIs3AndBlogsExistInTheDataStore_ThenReturnFirst3Blogs() { // Arrange IList <Blog> blogList = _blogBuilder.BuildBlogs; _mockBlogRepository = _blogRepositoryBuilder.BuildBlogRepositoryMock; _mockBlogRepository .Setup(r => r.GetAllAsync()) .ReturnsAsync(blogList); int expectedResult = 3; _getAllFilterInput = new GetAllByFilterInput(skip: 0, take: 3); // Act var actualResult = await new BlogService(_mockBlogRepository.Object).GetAllByFilterAsync(_getAllFilterInput); // Assert actualResult.Count.ShouldBe(expectedResult); actualResult.Single(first => first.BlogId == 1).ShouldNotBeNull(); actualResult.Single(second => second.BlogId == 2).ShouldNotBeNull(); actualResult.Single(third => third.BlogId == 3).ShouldNotBeNull(); }
public void GetAllByFilterAsync_WhenGetAllAsyncFilterIsNull_ThenThrowBusinessException() { // Arrange _getAllFilterInput = null; // Act & Assert Assert.ThrowsAsync <BusinessException>(async() => await _blogService.GetAllByFilterAsync(_getAllFilterInput)); }
public async Task <IList <Blog> > GetAllByFilterAsync(GetAllByFilterInput getAllByFilterInput) { if (getAllByFilterInput == null) { // TODO: Add logger for exception message throw new BusinessException($"Business exception occurred with message : {nameof(getAllByFilterInput)} is cannot be null"); } IList <Blog> blogList = await _blogRepository.GetAllAsync(); return(blogList.Skip(getAllByFilterInput.Skip).Take(getAllByFilterInput.Take).ToList()); }
public async Task <ActionResult> Index(GetAllByFilterInput input) { if (input == null) { input = new GetAllByFilterInput(); } // This will always be a constant input.Take = ushort.Parse(AppSettings[SmartBloggerConsts.NumberBlogsToLoad]); IList <Blog> blogs = await _blogService.GetAllByFilterAsync(input); var blogListViewModel = new BlogListViewModel { Blogs = blogs }; return(View(blogListViewModel)); }
public async Task GetAllByFilterAsync_WhenGetAllAsyncFilterSkipAndTakeValuesAre0AndBlogsExistInTheDataStore_ThenReturn0Blogs() { // Arrange IList <Blog> blogList = _blogBuilder.BuildBlogs; _mockBlogRepository = _blogRepositoryBuilder.BuildBlogRepositoryMock; _mockBlogRepository .Setup(r => r.GetAllAsync()) .ReturnsAsync(blogList); int expectedResult = 0; _getAllFilterInput = new GetAllByFilterInput(skip: 0, take: 0); // Act var actualResult = await new BlogService(_mockBlogRepository.Object).GetAllByFilterAsync(_getAllFilterInput); // Assert actualResult.Count.ShouldBe(expectedResult); }
public async Task GetAllByFilterAsync_WhenGetAllAsyncFilterSkipIs9AndTake3AndBlogsExistInTheDataStore_ThenReturn10thBlog() { // Arrange IList <Blog> blogList = _blogBuilder.BuildBlogs; _mockBlogRepository .Setup(r => r.GetAllAsync()) .ReturnsAsync(blogList); int expectedResult = 1; _getAllFilterInput = new GetAllByFilterInput(skip: 9, take: 1); // Act var actualResult = await new BlogService(_mockBlogRepository.Object).GetAllByFilterAsync(_getAllFilterInput); // Assert actualResult.Count.ShouldBe(expectedResult); actualResult.Single(ten => ten.BlogId == 10).ShouldNotBeNull(); }