public async Task ReturnsEmptyIfPageTooLarge() { var fixture = new Fixture(); var testShifts = fixture.CreateMany <Shift>(20); var expectedShifts = Enumerable.Empty <ShiftSummary>(); var shiftServiceMock = new Mock <IShiftService>(MockBehavior.Strict); shiftServiceMock.Setup(s => s.GetAllShifts(AuthenticationHelperMock.GoodUserId)).ReturnsAsync(testShifts); var shiftService = shiftServiceMock.Object; var function = new GetAllShifts(shiftService, AuthenticationHelperMock.GetAuthenticationHelper()); var request = new DefaultHttpRequest(new DefaultHttpContext()); request.Headers.Add("Authorization", AuthenticationHelperMock.GoodHeader); request.QueryString = new QueryString($"?page=10"); var result = await function.Run(request, NullLogger.Instance); result.Should().BeOfType <OkObjectResult>() .Which.Value.Should().BeEquivalentTo(expectedShifts); request.HttpContext.Response.Headers["X-Total-Count"].Should().BeEquivalentTo(new[] { testShifts.Count().ToString() }); }
public async Task ReturnsSpecifiedIfPageAndCountSpecified() { const int count = 5; const int page = 2; var fixture = new Fixture(); var testShifts = fixture.CreateMany <Shift>(20); var expectedShifts = testShifts.OrderByDescending(s => s.Date).Skip(count * page).Take(count).Select(s => new ShiftSummary { CrewMate = s.CrewMate, Date = s.Date, Duration = s.Duration, Event = s.Event, Id = s.Id, Location = s.Location, LoggedCalls = s.Jobs?.Count ?? 0, Role = s.Role }); var shiftServiceMock = new Mock <IShiftService>(MockBehavior.Strict); shiftServiceMock.Setup(s => s.GetAllShifts(AuthenticationHelperMock.GoodUserId)).ReturnsAsync(testShifts); var shiftService = shiftServiceMock.Object; var function = new GetAllShifts(shiftService, AuthenticationHelperMock.GetAuthenticationHelper()); var request = new DefaultHttpRequest(new DefaultHttpContext()); request.Headers.Add("Authorization", AuthenticationHelperMock.GoodHeader); request.QueryString = new QueryString($"?count={count}&page={page}"); var result = await function.Run(request, NullLogger.Instance); result.Should().BeOfType <OkObjectResult>() .Which.Value.Should().BeEquivalentTo(expectedShifts); request.HttpContext.Response.Headers["X-Total-Count"].Should().BeEquivalentTo(new[] { testShifts.Count().ToString() }); }