public async Task DeleteByIdAsync_GivenNotValidCurrentUser_ExceptionThrown( string displayName, ICurrentUserService currentUserService) { // Arrange Seed(TripFlipDbContext, NonExistentUser); Seed(TripFlipDbContext, NotRouteSubscriberUser); Seed(TripFlipDbContext, NotTripSubscriberUser); Seed(TripFlipDbContext, TripEntityToSeed); Seed(TripFlipDbContext, RouteEntityToSeed); Seed(TripFlipDbContext, ItemListEntityToSeed); Seed(TripFlipDbContext, TripSubscriberEntitiesToSeed); Seed(TripFlipDbContext, RouteSubscriberEntitiesToSeed); Seed(TripFlipDbContext, RouteRoleEntitiesToSeed); Seed(TripFlipDbContext, RouteSubscriberAdminRoleEntityToSeed); CurrentUserService = currentUserService; var itemListService = new ItemListService(TripFlipDbContext, Mapper, CurrentUserService); int existingItemListId = 1; // Act & Assert await Assert.ThrowsExceptionAsync <NotFoundException>(async() => await itemListService.DeleteByIdAsync(existingItemListId)); }
public async Task DeleteByIdAsync_ValidItemListIdAndCurrentUser_Successful() { // Arrange var validUserThatIsRouteAdmin = ValidUser; Seed(TripFlipDbContext, validUserThatIsRouteAdmin); Seed(TripFlipDbContext, TripEntityToSeed); Seed(TripFlipDbContext, RouteEntityToSeed); Seed(TripFlipDbContext, ItemListEntityToSeed); Seed(TripFlipDbContext, TripSubscriberEntitiesToSeed); Seed(TripFlipDbContext, RouteSubscriberEntitiesToSeed); Seed(TripFlipDbContext, RouteRoleEntitiesToSeed); Seed(TripFlipDbContext, RouteSubscriberAdminRoleEntityToSeed); CurrentUserService = CreateCurrentUserService( validUserThatIsRouteAdmin.Id, validUserThatIsRouteAdmin.Email); var itemListService = new ItemListService(TripFlipDbContext, Mapper, CurrentUserService); int existingItemListId = 1; // Act await itemListService.DeleteByIdAsync(existingItemListId); // Assert bool itemListIsDeleted = TripFlipDbContext .ItemLists .Any(itemList => itemList.Id == existingItemListId) == false; Assert.IsTrue(itemListIsDeleted); }
public async Task DeleteByIdAsync_GivenNonExistentItemListId_ExceptionThrown() { // Arrange var nonExistentItemListId = 1; var itemListService = new ItemListService( tripFlipDbContext: TripFlipDbContext, mapper: null, currentUserService: null); // Act & Assert await Assert.ThrowsExceptionAsync <NotFoundException>(async() => await itemListService.DeleteByIdAsync(nonExistentItemListId)); }
public async Task DeleteByIdAsync_GivenNotAdminCurrentUser_ExceptionThrown() { // Arrange var userThatIsRouteSubButNotAdmin = ValidUser; Seed(TripFlipDbContext, userThatIsRouteSubButNotAdmin); Seed(TripFlipDbContext, TripEntityToSeed); Seed(TripFlipDbContext, RouteEntityToSeed); Seed(TripFlipDbContext, ItemListEntityToSeed); Seed(TripFlipDbContext, TripSubscriberEntitiesToSeed); Seed(TripFlipDbContext, RouteSubscriberEntitiesToSeed); Seed(TripFlipDbContext, RouteRoleEntitiesToSeed); CurrentUserService = CreateCurrentUserService( userThatIsRouteSubButNotAdmin.Id, userThatIsRouteSubButNotAdmin.Email); var itemListService = new ItemListService(TripFlipDbContext, Mapper, CurrentUserService); int existingItemListId = 1; // Act & Assert await Assert.ThrowsExceptionAsync <ArgumentException>(async() => await itemListService.DeleteByIdAsync(existingItemListId)); }