public async Task DownloadAttachments(Jira jira) { // create an issue var summaryValue = "Test Summary with attachment " + _random.Next(int.MaxValue); var issue = new Issue(jira, "TST") { Type = "1", Summary = summaryValue, Assignee = "admin" }; issue.SaveChanges(); // upload multiple attachments File.WriteAllText("testfile1.txt", "Test File Content 1"); File.WriteAllText("testfile2.txt", "Test File Content 2"); issue.AddAttachment("testfile1.txt", "testfile2.txt"); // Get attachment metadata var attachments = await issue.GetAttachmentsAsync(CancellationToken.None); Assert.Equal(2, attachments.Count()); Assert.True(attachments.Any(a => a.FileName.Equals("testfile1.txt")), "'testfile1.txt' was not downloaded from server"); Assert.True(attachments.Any(a => a.FileName.Equals("testfile2.txt")), "'testfile2.txt' was not downloaded from server"); // download an attachment. var tempFile = Path.GetTempFileName(); var attachment = attachments.First(a => a.FileName.Equals("testfile1.txt")); attachment.Download(tempFile); Assert.Equal("Test File Content 1", File.ReadAllText(tempFile)); }
public void AddAttachment(string path, string issueID) { XMLParse _oWaXmlData = new XMLParse(); _oWaXmlData.LoadXML("../../Config/ApplicationSettings.xml"); jiraURL = _oWaXmlData.getData("settings/JiraCredentials", "URL"); jiraUsername = _oWaXmlData.getData("settings/JiraCredentials", "UserName"); jiraPassword = _oWaXmlData.getData("settings/JiraCredentials", "Password"); jiraConn = new Jira(jiraURL[0], jiraUsername[0], jiraPassword[0]); string jqlString = "project = PegasusCRM AND issuetype = Bug"; bool result = false; IEnumerable <Atlassian.Jira.Issue> jiraIssues = jiraConn.GetIssuesFromJql(jqlString); foreach (var issue in jiraIssues) { if (issue.Key.Value == issueID) { Issue foundissue = jiraConn.GetIssue(issueID); foundissue.AddAttachment(path); Console.WriteLine("Attachment Added Successfully"); foundissue.SaveChanges(); result = true; break; } } if (!result) { Console.WriteLine("Failed To Add Attachment"); } }
public async Task DownloadAttachmentDataAsync() { // create an issue var summaryValue = "Test Summary with attachment " + _random.Next(int.MaxValue); var issue = new Issue(_jira, "TST") { Type = "1", Summary = summaryValue, Assignee = "admin" }; issue.SaveChanges(); // upload attachment File.WriteAllText("testfile.txt", "Test File Content"); issue.AddAttachment("testfile.txt"); // Get attachment metadata var attachments = await issue.GetAttachmentsAsync(CancellationToken.None); Assert.Equal("testfile.txt", attachments.Single().FileName); // download attachment as byte array var bytes = await attachments.Single().DownloadDataAsync(); Assert.Equal(17, bytes.Length); }
public void UploadAndDownloadOfAttachments() { var summaryValue = "Test Summary with attachment " + _random.Next(int.MaxValue); var issue = new Issue(_jira, "TST") { Type = "1", Summary = summaryValue, Assignee = "admin" }; // create an issue, verify no attachments issue.SaveChanges(); Assert.Equal(0, issue.GetAttachments().Count); // upload multiple attachments File.WriteAllText("testfile1.txt", "Test File Content 1"); File.WriteAllText("testfile2.txt", "Test File Content 2"); issue.AddAttachment("testfile1.txt", "testfile2.txt"); var attachments = issue.GetAttachments(); Assert.Equal(2, attachments.Count); Assert.True(attachments.Any(a => a.FileName.Equals("testfile1.txt")), "'testfile1.txt' was not downloaded from server"); Assert.True(attachments.Any(a => a.FileName.Equals("testfile2.txt")), "'testfile2.txt' was not downloaded from server"); // download an attachment var tempFile = Path.GetTempFileName(); attachments.First(a => a.FileName.Equals("testfile1.txt")).Download(tempFile); Assert.Equal("Test File Content 1", File.ReadAllText(tempFile)); }
public static void addRanorexReport(Issue issue, string fileName) { Ranorex.Core.Reporting.TestReport.SaveReport(); Ranorex.Report.Zip(Ranorex.Core.Reporting.TestReport.ReportEnvironment, null, fileName); fileName = fileName.Replace(".rxlog", ".rxzlog"); issue.AddAttachment(fileName); }
public static void AttachScreenShot(Issue issue, Image img) { if (img != null) { issue.AddAttachment("screenshot.png", ConvertImage(img)); } issue.SaveChanges(); }
/// <summary>Добавляет файлы в задаче.</summary> /// <param name="form">Форма задачи.</param> /// <param name="issue">Задача jira.</param> public void AddFiles(CreateForm form, Issue issue) { form.Files?.ForEach( t => { using (var ms = new MemoryStream()) { t.CopyTo(ms); issue.AddAttachment(t.Name, ms.ToArray()); } } ); }
public static string updateDescription(Issue issue, JiraConfiguration config) { string descriptionString = ""; foreach (JiraDescriptionItem item in config.JiraDescription) { descriptionString += "\r\n " + item.text; if (item.isImageEntry()) { issue.AddAttachment(item.getValue()); descriptionString += "\r\n !" + Path.GetFileName(item.getValue()) + "!"; } } return(descriptionString); }
public void AddGetRemoveAttachmentsFromIssue(Jira jira) { var summaryValue = "Test Summary with attachment " + _random.Next(int.MaxValue); var issue = new Issue(jira, "TST") { Type = "1", Summary = summaryValue, Assignee = "admin" }; // create an issue, verify no attachments issue.SaveChanges(); Assert.Empty(issue.GetAttachmentsAsync().Result); // upload multiple attachments File.WriteAllText("testfile1.txt", "Test File Content 1"); File.WriteAllText("testfile2.txt", "Test File Content 2"); issue.AddAttachment("testfile1.txt", "testfile2.txt"); // verify all attachments can be retrieved. var attachments = issue.GetAttachmentsAsync().Result; Assert.Equal(2, attachments.Count()); Assert.True(attachments.Any(a => a.FileName.Equals("testfile1.txt")), "'testfile1.txt' was not downloaded from server"); Assert.True(attachments.Any(a => a.FileName.Equals("testfile2.txt")), "'testfile2.txt' was not downloaded from server"); // verify properties of an attachment var attachment = attachments.First(); Assert.Equal("admin", attachment.Author); Assert.Equal("admin", attachment.AuthorUser.DisplayName); Assert.NotNull(attachment.CreatedDate); Assert.True(attachment.FileSize > 0); Assert.NotEmpty(attachment.MimeType); // download an attachment var tempFile = Path.GetTempFileName(); attachments.First(a => a.FileName.Equals("testfile1.txt")).Download(tempFile); Assert.Equal("Test File Content 1", File.ReadAllText(tempFile)); // remove an attachment issue.DeleteAttachmentAsync(attachments.First()).Wait(); Assert.Single(issue.GetAttachmentsAsync().Result); }
public async Task DownloadAttachmentsAsync() { // create an issue var summaryValue = "Test Summary with attachment " + _random.Next(int.MaxValue); var issue = new Issue(_jira, "TST") { Type = "1", Summary = summaryValue, Assignee = "admin" }; issue.SaveChanges(); // upload multiple attachments File.WriteAllText("testfile1.txt", "Test File Content 1"); File.WriteAllText("testfile2.txt", "Test File Content 2"); issue.AddAttachment("testfile1.txt", "testfile2.txt"); // Get attachment metadata var attachments = await issue.GetAttachmentsAsync(CancellationToken.None); Assert.Equal(2, attachments.Count()); Assert.True(attachments.Any(a => a.FileName.Equals("testfile1.txt")), "'testfile1.txt' was not downloaded from server"); Assert.True(attachments.Any(a => a.FileName.Equals("testfile2.txt")), "'testfile2.txt' was not downloaded from server"); // download an attachment multiple times var tempFile = Path.GetTempFileName(); var attachment = attachments.First(a => a.FileName.Equals("testfile1.txt")); #if NET452 // Standard has a different behavior than Framework it throws an exception. It seems you are not allowed to do two concurrent operations with the client // System.NotSupportedException : WebClient does not support concurrent I/O operations. var task1 = attachment.DownloadAsync(tempFile); #endif var task2 = attachment.DownloadAsync(tempFile); await task2; #if NET452 Assert.True(task1.IsCanceled); #endif Assert.Equal("Test File Content 1", File.ReadAllText(tempFile)); }
public void can_save_new_issue() { Company company = new Company(); company.Name = "Test Company"; company.CreateAndFlush(); Issue issue = new Issue(); issue.Title = "Test issue"; issue.Type = IssueType.Defect; IssueNote note = new IssueNote(); note.Body = "Test note"; issue.AddNote(note); IssueChange change = new IssueChange(); change.PropertyName = "Test change"; issue.AddChange(change); IssueAttachment att = new IssueAttachment(); att.Body = new byte[10]; att.Title = "Test attachment"; issue.AddAttachment(att); Project project = new Project(); project.Company = company; project.AddIssue(issue); project.Name = "Test project"; project.CreateAndFlush(); using (SessionScope newScope = new SessionScope()) { Issue actual = Issue.Find(issue.Id); Assert.AreEqual("Test issue", actual.Title); Assert.AreEqual("Test note", actual.Notes[0].Body); Assert.AreEqual("Test change", actual.Changes[0].PropertyName); Assert.AreEqual("Test attachment", actual.Attachments[0].Title); } project.DeleteAndFlush(); company.DeleteAndFlush(); }
public ActionResult ReportBug(BugModel model, HttpPostedFileBase attachment) { JiraAuth jira = new JiraAuth(); Issue issue = jira.CreateIssue(model.ProjectKey); issue.Description = model.Description; issue.Summary = model.Summary; issue.Type = "Bug"; issue.SaveChanges(); if (attachment != null) { model.attachment = attachment; } if (model.attachment != null && model.attachment.ContentLength > 0) { MemoryStream target = new MemoryStream(); model.attachment.InputStream.CopyTo(target); byte[] data = target.ToArray(); issue.AddAttachment(Uri.EscapeDataString(model.attachment.FileName), data); } return(RedirectToAction("_ReportBug")); }