public async Task GetBookingsAsync_NoRestrictions_Success() { // Arrange paginatedBookings.Data = expectedBookings; paginatedBookings.Counts = new PaginatedCountModel(paging, expectedBookings.Count()); moqService.Setup(x => x.GetBookingsAsync(It.IsAny <PagingModel>())).ReturnsAsync(paginatedBookings); // Act var response = await controller.GetBookingsAsync(paging) as ObjectResult; var actualPaginatedBookings = response.Value as PaginatedModel <Booking>; // Assert moqService.VerifyAll(); Assert.IsInstanceOfType(response, typeof(OkObjectResult)); Assert.IsInstanceOfType(actualPaginatedBookings, typeof(PaginatedModel <Booking>)); Assert.AreEqual(expectedBookings, actualPaginatedBookings.Data); Assert.IsNotNull(actualPaginatedBookings.Counts); Assert.AreEqual(paging, actualPaginatedBookings.Counts.Paging); Assert.AreEqual(expectedBookings.Count(), actualPaginatedBookings.Counts.Total); }
public async Task GetBookingsAsync_WhenHasData() { // Create test data and setup the mock object before the call IEnumerable <Booking> bookings = Booking.GenerateTestData(); _mockBookingService.Setup(o => o.GetBookingsAsync(It.IsAny <CancellationToken>())).Returns(Task.FromResult(bookings)); BookingsController controller = new BookingsController(_mockBookingService.Object); // Make the call var result = await controller.GetBookingsAsync(CancellationToken.None); // Validate the outcome Assert.NotNull(result); Assert.IsType <OkObjectResult>(result); }