public async Task DeleteByIdAsync_ValidData_Successful() { // Arrange. Seed(TripFlipDbContext, ValidUser); Seed(TripFlipDbContext, TripEntityToSeed); Seed(TripFlipDbContext, TripSubscriberEntitiesToSeed); Seed(TripFlipDbContext, TripSubscriberRoleEntitiesToSeed); Seed(TripFlipDbContext, RouteEntityToSeed); CurrentUserService = CreateCurrentUserService(ValidUser.Id, ValidUser.Email); var routeService = new RouteService(TripFlipDbContext, Mapper, CurrentUserService); int validRouteId = RouteEntityToSeed.Id; // Act. await routeService.DeleteByIdAsync(validRouteId); // Assert. bool routeIsDeleted = TripFlipDbContext .Routes .Any(route => route.Id == validRouteId) == false; Assert.IsTrue(routeIsDeleted); }
public async Task DeleteByIdAsync_NonExistentRouteId_ExceptionThrown() { // Arrange. var nonExistentRouteId = 1; var routeService = new RouteService( tripFlipDbContext: TripFlipDbContext, mapper: null, currentUserService: null); // Act & Assert. await Assert.ThrowsExceptionAsync <NotFoundException>(async() => await routeService.DeleteByIdAsync(nonExistentRouteId)); }
public async Task DeleteByIdAsync_CurrentUserNotTripAdmin_ExceptionThrown() { // Arrange. Seed(TripFlipDbContext, ValidUser); Seed(TripFlipDbContext, TripEntityToSeed); Seed(TripFlipDbContext, TripSubscriberEntitiesToSeed); Seed(TripFlipDbContext, RouteEntityToSeed); CurrentUserService = CreateCurrentUserService(ValidUser.Id, ValidUser.Email); var routeService = new RouteService(TripFlipDbContext, Mapper, CurrentUserService); int validRouteId = RouteEntityToSeed.Id; // Act & Assert. await Assert.ThrowsExceptionAsync <ArgumentException>(async() => await routeService.DeleteByIdAsync(validRouteId)); }
public async Task DeleteByIdAsync_InvalidCurrentUser_ExceptionThrown( string displayName, ICurrentUserService currentUserService) { Seed(TripFlipDbContext, NonExistentUser); Seed(TripFlipDbContext, NotTripSubscriberUser); Seed(TripFlipDbContext, TripEntityToSeed); Seed(TripFlipDbContext, RouteEntityToSeed); Seed(TripFlipDbContext, TripSubscriberEntitiesToSeed); CurrentUserService = currentUserService; var routeService = new RouteService(TripFlipDbContext, Mapper, CurrentUserService); int validRouteId = RouteEntityToSeed.Id; // Act & Assert. await Assert.ThrowsExceptionAsync <NotFoundException>(async() => await routeService.DeleteByIdAsync(validRouteId), displayName); }