예제 #1
0
        public async Task TestAttachment()
        {
            const string filename    = "test.txt";
            const string testContent = "Testing 1 2 3";
            var          attachment  = await _jiraApi.AttachAsync("FEATURE-746", testContent, filename);

            Assert.NotNull(attachment);
            Assert.StartsWith("text/plain", attachment.MimeType);

            if (attachment.ThumbnailUri != null)
            {
                var attachmentThumbnail = await _jiraApi.GetAttachmentThumbnailAsAsync <Bitmap>(attachment);

                Assert.NotNull(attachmentThumbnail);
                Assert.True(attachmentThumbnail.Width > 0);
            }

            var returnedContent = await _jiraApi.GetAttachmentContentAsAsync <string>(attachment);

            Assert.Equal(testContent, returnedContent);

            bool hasBeenRemoved = false;
            var  issue          = await _jiraApi.GetIssueAsync("FEATURE-746");

            foreach (var attachment2Delete in issue.Fields.Attachments.Where(x => x.Filename == filename))
            {
                Log.Info().WriteLine("Deleting {0} from {1}", attachment2Delete.Filename, attachment2Delete.Created);
                await _jiraApi.DeleteAttachmentAsync(attachment2Delete);

                hasBeenRemoved = true;
            }

            Assert.True(hasBeenRemoved);
        }
예제 #2
0
        /// <summary>
        ///     Do the actual uploading, return the attachment object(s)
        /// </summary>
        protected override async Task ProcessRecordAsync()
        {
            if (!Path.IsPathRooted(Filepath))
            {
                var currentDirectory = CurrentProviderLocation("FileSystem").ProviderPath;
                Filepath = Path.Combine(currentDirectory, Filepath);
            }

            if (!File.Exists(Filepath))
            {
                throw new FileNotFoundException($"Couldn't find file {Filepath}");
            }
            using (var stream = File.OpenRead(Filepath))
            {
                var attachment = await JiraApi.AttachAsync(IssueKey, stream, Filename, ContentType);

                WriteObject(attachment);
            }
        }