예제 #1
0
        public async Task SaveAsync_RespectsMaxNumberOfCollectionsPerOrganization()
        {
            // prepare the organization
            var testOrganizationId = Guid.NewGuid();
            var testOrganization   = new Models.Table.Organization
            {
                Id = testOrganizationId,
            };

            _organizationRepository.GetByIdAsync(testOrganizationId).Returns(testOrganization);
            _collectionRepository.GetCountByOrganizationIdAsync(testOrganizationId).Returns(2);

            // execute
            var collectionService = new CollectionService(
                _eventService,
                _organizationRepository,
                _organizationUserRepository,
                _collectionRepository,
                _userRepository,
                _mailService);

            var testCollection = new Models.Table.Collection {
                OrganizationId = testOrganizationId
            };

            // verify & expect exception to be thrown
            var ex = await Assert.ThrowsAsync <BadRequestException>(() => collectionService.SaveAsync(testCollection));

            Assert.Equal("You have reached the maximum number of collections (2) for this organization.",
                         ex.Message);
        }
예제 #2
0
        public async Task SaveAsync_DefaultCollectionId_CreatesCollectionInTheRepository()
        {
            // prepare the organization
            var testOrganizationId = Guid.NewGuid();
            var testOrganization   = new Models.Table.Organization
            {
                Id = testOrganizationId,
            };

            _organizationRepository.GetByIdAsync(testOrganizationId).Returns(testOrganization);

            var collectionService = new CollectionService(
                _eventService,
                _organizationRepository,
                _organizationUserRepository,
                _collectionRepository,
                _userRepository,
                _mailService);

            // execute
            var testCollection = new Models.Table.Collection
            {
                OrganizationId = testOrganizationId,
            };
            await collectionService.SaveAsync(testCollection);

            // verify
            await _collectionRepository.Received().CreateAsync(testCollection);
        }
예제 #3
0
        public async Task DeleteUserAsync_DeletesValidUserWhoBelongsToCollection()
        {
            // prepare the organization
            var testOrganizationId = Guid.NewGuid();
            var testOrganization   = new Models.Table.Organization
            {
                Id = testOrganizationId,
            };
            var testUserId       = Guid.NewGuid();
            var organizationUser = new 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 Models.Table.Collection {
                OrganizationId = testOrganizationId
            };
            await collectionService.DeleteUserAsync(testCollection, organizationUser.Id);

            // verify
            await _collectionRepository.Received().DeleteUserAsync(testCollection.Id, organizationUser.Id);
        }
예제 #4
0
        public async Task DeleteUserAsync_ThrowsIfUserIsInvalid()
        {
            // prepare the organization
            var testOrganizationId = Guid.NewGuid();
            var testOrganization   = new Models.Table.Organization
            {
                Id = testOrganizationId,
            };
            var testUserId          = Guid.NewGuid();
            var nonOrganizationUser = new 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 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));
        }