public async Task DeleteByIdAsync_ValidUserAndTripId_Successful() { // Arrange Seed(TripFlipDbContext, TripEntityToSeed); Seed(TripFlipDbContext, UserEntityToSeed); CurrentUserService = CreateCurrentUserServiceWithExistentUser(); Seed(TripFlipDbContext, TripSubscriberEntityToSeed); Seed(TripFlipDbContext, TripRolesToSeed); Seed(TripFlipDbContext, TripSubscriberAdminRoleEntityToSeed); TripService = new TripService( tripFlipDbContext: TripFlipDbContext, mapper: Mapper, currentUserService: CurrentUserService); int validTripId = 1; // Act await TripService.DeleteByIdAsync(validTripId); // Assert bool tripIsDeleted = TripFlipDbContext .Trips .Any(trip => trip.Id == validTripId) == false; Assert.IsTrue(tripIsDeleted); }
public async Task DeleteByIdAsync_GivenNonExistentTripId_ExceptionThrown() { // Arrange Seed(TripFlipDbContext, UserEntityToSeed); CurrentUserService = CreateCurrentUserServiceWithExistentUser(); TripService = new TripService( tripFlipDbContext: TripFlipDbContext, mapper: Mapper, currentUserService: CurrentUserService); int invalidTripId = 2; // Act & Assert await Assert.ThrowsExceptionAsync <NotFoundException>( () => TripService.DeleteByIdAsync(invalidTripId)); }
public async Task DeleteByIdAsync_CurrentUserNotAdmin_ExceptionThrown() { // Arrange Seed(TripFlipDbContext, TripEntityToSeed); Seed(TripFlipDbContext, UserEntityToSeed); CurrentUserService = CreateCurrentUserServiceWithExistentUser(); Seed(TripFlipDbContext, TripSubscriberEntityToSeed); TripService = new TripService( tripFlipDbContext: TripFlipDbContext, mapper: Mapper, currentUserService: CurrentUserService); int validTripId = 1; // Act & Assert await Assert.ThrowsExceptionAsync <ArgumentException>( () => TripService.DeleteByIdAsync(validTripId)); }