public async Task AddArtifactsToCollectionAsync_AllParametersAreValid_Success()
        {
            // Arrange

            // Act
            await _collectionRepository.AddArtifactsToCollectionAsync(CollectionId, new List <int> {
                1, 2, 3
            }, UserId);
        }
Ejemplo n.º 2
0
        public async Task <AddArtifactsToCollectionResult> AddArtifactsToCollectionAsync(
            int collectionId, IEnumerable <int> artifactIds, int userId)
        {
            if (collectionId < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(collectionId));
            }

            if (userId < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(userId));
            }

            AddArtifactsToCollectionResult result = null;

            Func <IDbTransaction, long, Task> action = async(transaction, transactionId) =>
            {
                var collection = await ValidateCollectionAsync(collectionId, userId, transaction);

                var artifactIdsToAdd    = artifactIds.ToList();
                var accessibleArtifacts = await GetAccessibleArtifactsAsync(artifactIdsToAdd, userId, transaction);

                var validArtifacts   = accessibleArtifacts.Where(i => CanAddArtifactToCollection(i, collection)).ToList();
                var validArtifactIds = validArtifacts.Select(a => a.HolderId);

                var addedCount = await _collectionsRepository.AddArtifactsToCollectionAsync(
                    collection.Id, validArtifactIds, userId, transaction);

                result = new AddArtifactsToCollectionResult
                {
                    AddedCount = addedCount,
                    Total      = artifactIdsToAdd.Count
                };
            };

            await _sqlHelper.RunInTransactionAsync(ServiceConstants.RaptorMain, action);

            return(result);
        }