Exemplo n.º 1
0
        public async Task GetByIdAsync_GivenNonExistentTripId_ExceptionThrown()
        {
            // Arrange
            Seed(TripFlipDbContext, TripEntityToSeed);

            int nonExistentTripId = 2;

            TripService = new TripService(
                tripFlipDbContext: TripFlipDbContext,
                mapper: Mapper,
                currentUserService: null);

            // Act & Assert
            await Assert.ThrowsExceptionAsync <NotFoundException>(
                () => TripService.GetByIdAsync(nonExistentTripId));
        }
        public async Task GetByIdAsync_ValidTripId_Successful()
        {
            // Arrange
            Seed(TripFlipDbContext, TripEntityToSeed);

            int validTripId = 1;

            TripService = new TripService(
                tripFlipDbContext: TripFlipDbContext,
                mapper: Mapper,
                currentUserService: null);

            var expectedTripDto = Mapper.Map <TripDto>(TripEntityToSeed);

            expectedTripDto.Id = validTripId;

            // Act
            var resultTripDto = await TripService.GetByIdAsync(validTripId);

            // Assert
            var tripDtoComparer = new TripDtoComparer();

            Assert.AreEqual(0, tripDtoComparer.Compare(resultTripDto, expectedTripDto));
        }