public async Task ShouldSearchFiles()
        {
            /// Arrange
            var request = new FileTransferSearchRequest {
                Limit = 20, SearchString = "*"
            };

            /// Act
            FileTransferSearchResult result = await _client.Transfers.SearchFilesAsync(request);

            /// Assert
            Assert.NotNull(result);
            Assert.True(result.Results.Count >= 1);
        }
        /// <summary>Searches files of a given transfer ID.</summary>
        /// <param name="transferId">The transfer ID.</param>
        /// <param name="limit">The maximum number of search results.</param>
        /// <returns>The result.</returns>
        public async Task <FileTransferSearchResult> SearchFilesByTransferIdAsync(string transferId, int limit = 20)
        {
            var request = new FileTransferSearchRequest()
            {
                Limit        = limit,
                SearchString = "*",
                Filter       = new TermFilter
                {
                    Field = "transferId",
                    Term  = transferId
                }
            };

            return(await SearchFilesAsync(request).ConfigureAwait(false));
        }
        public static async Task <string> GetRandomFileTransferIdAsync(PictureparkClient client, int limit)
        {
            string fileTransferId             = string.Empty;
            FileTransferSearchRequest request = new FileTransferSearchRequest()
            {
                Limit = limit
            };
            FileTransferSearchResult result = await client.Transfers.SearchFilesAsync(request);

            if (result.Results.Count > 0)
            {
                int randomNumber = new Random().Next(0, result.Results.Count);
                fileTransferId = result.Results.Skip(randomNumber).First().Id;
            }

            return(fileTransferId);
        }
        public async Task ShouldUpdateFile()
        {
            string contentId = await _fixture.GetRandomContentIdAsync(".jpg -0030_JabLtzJl8bc", 20);

            // Create transfer
            var filePaths = new List <string>
            {
                Path.Combine(_fixture.ExampleFilesBasePath, "0030_JabLtzJl8bc.jpg")
            };
            var    directoryPath        = Path.GetDirectoryName(filePaths.First());
            string transferName         = nameof(ShouldUpdateFile) + "-" + new Random().Next(1000, 9999);
            var    createTransferResult = await _client.Transfers.CreateAndWaitForCompletionAsync(transferName, filePaths.Select(Path.GetFileName).ToList());

            // Upload file
            var uploadOptions = new UploadOptions
            {
                SuccessDelegate = Console.WriteLine,
                ErrorDelegate   = Console.WriteLine
            };

            await _client.Transfers.UploadFilesAsync(createTransferResult.Transfer, filePaths, uploadOptions);

            // Search filetransfers to get id
            var request = new FileTransferSearchRequest()
            {
                Limit = 20, SearchString = "*", Filter = new TermFilter {
                    Field = "transferId", Term = createTransferResult.Transfer.Id
                }
            };
            FileTransferSearchResult result = await _client.Transfers.SearchFilesAsync(request);

            Assert.Equal(result.TotalResults, 1);

            var updateRequest = new ContentFileUpdateRequest
            {
                ContentId      = contentId,
                FileTransferId = result.Results.First().Id
            };

            var businessProcess = await _client.Contents.UpdateFileAsync(contentId, updateRequest);

            var waitResult = await _client.BusinessProcesses.WaitForCompletionAsync(businessProcess.Id);

            Assert.True(waitResult.HasLifeCycleHit);
        }
        public async Task ShouldDeleteFiles()
        {
            // TODO: Fix ShouldDeleteFiles unit test

            /// Arrange
            var transferName = new Random().Next(1000, 9999).ToString();
            var files        = new List <string>
            {
                Path.Combine(_fixture.ExampleFilesBasePath, "0030_JabLtzJl8bc.jpg")
            };

            var createTransferResult = await _client.Transfers.CreateAndWaitForCompletionAsync(transferName, files);

            var searchRequest = new FileTransferSearchRequest
            {
                Limit        = 20,
                SearchString = "*",
                Filter       = new TermFilter {
                    Field = "transferId", Term = createTransferResult.Transfer.Id
                }
            };

            var fileParameter = new FileParameter(new MemoryStream(new byte[] { 1, 2, 3 }));
            await _client.Transfers.UploadFileAsync(createTransferResult.Transfer.Id, "foobar", fileParameter);

            FileTransferSearchResult searchResult = await _client.Transfers.SearchFilesAsync(searchRequest);

            /// Act
            var request = new FileTransferDeleteRequest
            {
                TransferId      = createTransferResult.Transfer.Id,
                FileTransferIds = new List <string> {
                    searchResult.Results.ToList()[0].Id
                }
            };

            await _client.Transfers.DeleteFilesAsync(request);

            /// Assert
            await Assert.ThrowsAsync <ApiException>(async() => await _client.Transfers.GetAsync(createTransferResult.Transfer.Id)); // TODO: TransferClient.GetAsync: Should correctly throw NotFoundException
        }
Exemple #6
0
        private async Task <(CreateTransferResult, string fileId)> CreateFileTransferAsync()
        {
            var transferName = new Random().Next(1000, 9999).ToString();
            var files        = new FileLocations[]
            {
                Path.Combine(_fixture.ExampleFilesBasePath, "0030_JabLtzJl8bc.jpg")
            };

            var createTransferResult = await _client.Transfer.CreateAndWaitForCompletionAsync(transferName, files).ConfigureAwait(false);

            await _client.Transfer.UploadFilesAsync(createTransferResult.Transfer, files, new UploadOptions()).ConfigureAwait(false);

            var searchRequest = new FileTransferSearchRequest
            {
                Limit        = 1,
                SearchString = "*",
                Filter       = FilterBase.FromExpression <FileTransfer>(i => i.TransferId, createTransferResult.Transfer.Id)
            };
            var searchResult = await _client.Transfer.SearchFilesAsync(searchRequest).ConfigureAwait(false);

            var fileId = searchResult.Results.ToList()[0].Id;

            return(createTransferResult, fileId);
        }