コード例 #1
0
        public async Task GetAllByRouteIdAsync_GivenNonExistentRouteId_ExceptionThrown()
        {
            // Arrange
            var nonExistentRouteId = 1;

            var itemListService = new ItemListService(
                tripFlipDbContext: TripFlipDbContext,
                mapper: null,
                currentUserService: null);

            // Act & Assert
            await Assert.ThrowsExceptionAsync <NotFoundException>(async() =>
                                                                  await itemListService.GetAllByRouteIdAsync(
                                                                      routeId: nonExistentRouteId,
                                                                      searchString: null,
                                                                      paginationDto: null));
        }
コード例 #2
0
        public async Task GetAllByRouteIdAsync_ExistingRouteId_Successful()
        {
            // Arrange
            Seed(TripFlipDbContext, TripEntityToSeed);
            Seed(TripFlipDbContext, RouteEntityToSeed);
            Seed(TripFlipDbContext, ItemListEntityToSeed);

            var validRouteId = 1;

            var itemListService = new ItemListService(
                tripFlipDbContext: TripFlipDbContext,
                mapper: Mapper,
                currentUserService: null);

            var expectedItemListDto  = Mapper.Map <ItemListDto>(ItemListEntityToSeed);
            var expectedItemListDtos = new List <ItemListDto> {
                expectedItemListDto
            };

            var paginationDto = GetPaginationDto();

            var comparer = new ItemListDtoComparer();

            // Act
            var resultPagedList = await itemListService.GetAllByRouteIdAsync(
                routeId : validRouteId,
                searchString : null,
                paginationDto : paginationDto);

            var resultItemListDtos = resultPagedList.Items.ToList();

            // Assert
            int resultItemListDtosCount = resultItemListDtos.Count;

            Assert.AreEqual(resultItemListDtosCount, expectedItemListDtos.Count);

            for (int i = 0; i < resultItemListDtosCount; i++)
            {
                Assert.AreEqual(0,
                                comparer.Compare(resultItemListDtos[i], expectedItemListDtos[i]));
            }
        }