public async Task DeleteUserAsync_DeletesValidUserWhoBelongsToCollection() { // prepare the organization var testOrganizationId = Guid.NewGuid(); var testOrganization = new Core.Models.Table.Organization { Id = testOrganizationId, }; var testUserId = Guid.NewGuid(); var organizationUser = new Core.Models.Table.OrganizationUser { Id = testUserId, OrganizationId = testOrganizationId, }; _organizationUserRepository.GetByIdAsync(testUserId).Returns(organizationUser); // execute var collectionService = new CollectionService( _eventService, _organizationRepository, _organizationUserRepository, _collectionRepository, _userRepository, _mailService); var testCollection = new Core.Models.Table.Collection { OrganizationId = testOrganizationId }; await collectionService.DeleteUserAsync(testCollection, organizationUser.Id); // verify await _collectionRepository.Received().DeleteUserAsync(testCollection.Id, organizationUser.Id); }
public async Task DeleteUserAsync_ThrowsIfUserIsInvalid() { // prepare the organization var testOrganizationId = Guid.NewGuid(); var testOrganization = new Core.Models.Table.Organization { Id = testOrganizationId, }; var testUserId = Guid.NewGuid(); var nonOrganizationUser = new Core.Models.Table.OrganizationUser { Id = testUserId, OrganizationId = Guid.NewGuid(), }; _organizationUserRepository.GetByIdAsync(testUserId).Returns(nonOrganizationUser); // execute var collectionService = new CollectionService( _eventService, _organizationRepository, _organizationUserRepository, _collectionRepository, _userRepository, _mailService); var testCollection = new Core.Models.Table.Collection { OrganizationId = testOrganizationId }; // verify // invalid user await Assert.ThrowsAsync <NotFoundException>(() => collectionService.DeleteUserAsync(testCollection, Guid.NewGuid())); // user from other organization await Assert.ThrowsAsync <NotFoundException>(() => collectionService.DeleteUserAsync(testCollection, testUserId)); }