public void Should_Upload_Attachment() { //read document from specified path byte[] documentData = File.ReadAllBytes(ATTACHMENT_LOCAL_PATH); //upload attachment to redmine Upload attachment = redmineManager.UploadFile(documentData); //set attachment properties attachment.FileName = ATTACHMENT_NAME; attachment.Description = ATTACHMENT_DESCRIPTION; attachment.ContentType = ATTACHMENT_CONTENT_TYPE; //create list of attachments to be added to issue IList <Upload> attachments = new List <Upload>(); attachments.Add(attachment); Issue issue = new Issue(); issue.Project = new Project { Id = PROJECT_ID }; issue.Subject = ISSUE_SUBJECT; issue.Uploads = attachments; //create issue and attach document Issue issueWithAttachment = redmineManager.CreateObject <Issue>(issue); issue = redmineManager.GetObject <Issue>(issueWithAttachment.Id.ToString(), new NameValueCollection { { RedmineKeys.INCLUDE, RedmineKeys.ATTACHMENTS } }); Assert.IsNotNull(issue, "Get created issue returned null."); Assert.IsNotNull(issue.Attachments, "Attachments list is null."); CollectionAssert.AllItemsAreNotNull(issue.Attachments.ToList(), "Attachments list contains null items."); CollectionAssert.AllItemsAreInstancesOfType(issue.Attachments.ToList(), typeof(Attachment), "Attachments contains items of unexpected type."); Assert.IsTrue(issue.Attachments.Count == 1, "Number of attachments != 1"); Assert.IsTrue(issue.Attachments[0].FileName == ATTACHMENT_NAME, "Attachment name is not correct."); Assert.IsTrue(issue.Attachments[0].Description == ATTACHMENT_DESCRIPTION, "Attachment description is not correct."); Assert.IsTrue(issue.Attachments[0].ContentType == ATTACHMENT_CONTENT_TYPE, "Attachment content type is not correct."); }
/// <summary> /// Uploads the file asynchronous. /// </summary> /// <param name="redmineManager">The redmine manager.</param> /// <param name="data">The data.</param> /// <returns></returns> public static Task <Upload> UploadFileAsync(this RedmineManager redmineManager, byte[] data) { return(Task.Factory.StartNew(() => redmineManager.UploadFile(data), CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default)); }
/// <summary> /// Uploads the file asynchronous. /// </summary> /// <param name="redmineManager">The redmine manager.</param> /// <param name="data">The data.</param> /// <returns></returns> public static Task <Upload> UploadFileAsync(this RedmineManager redmineManager, byte[] data) { return(delegate { return redmineManager.UploadFile(data); }); }
public void RedmineAttachments_ShouldUploadAttachment() { //read document from specified path string documentPath = "E:\\uploadAttachment.txt"; byte[] documentData = File.ReadAllBytes(documentPath); //upload attachment to redmine Upload attachment = redmineManager.UploadFile(documentData); //set attachment properties attachment.FileName = "AttachmentUploaded.txt"; attachment.Description = "File uploaded using REST API"; attachment.ContentType = "text/plain"; //create list of attachments to be added to issue IList <Upload> attachments = new List <Upload>(); attachments.Add(attachment); //read document from specified path documentPath = "E:\\uploadAttachment1.txt"; documentData = File.ReadAllBytes(documentPath); //upload attachment to redmine Upload attachment1 = redmineManager.UploadFile(documentData); //set attachment properties attachment1.FileName = "AttachmentUploaded1.txt"; attachment1.Description = "Second file uploaded"; attachment1.ContentType = "text/plain"; attachments.Add(attachment1); Issue issue = new Issue(); issue.Project = new Project { Id = 10 }; issue.Tracker = new IdentifiableName { Id = 4 }; issue.Status = new IdentifiableName { Id = 5 }; issue.Priority = new IdentifiableName { Id = 8 }; issue.Subject = "Issue with attachments"; issue.Description = "Issue description..."; issue.Category = new IdentifiableName { Id = 11 }; issue.FixedVersion = new IdentifiableName { Id = 9 }; issue.AssignedTo = new IdentifiableName { Id = 8 }; issue.ParentIssue = new IdentifiableName { Id = 19 }; issue.CustomFields = new List <IssueCustomField>(); issue.CustomFields.Add(new IssueCustomField { Id = 13, Values = new List <CustomFieldValue> { new CustomFieldValue { Info = "Issue custom field completed" } } }); issue.IsPrivate = true; issue.EstimatedHours = 12; issue.StartDate = DateTime.Now; issue.DueDate = DateTime.Now.AddMonths(1); issue.Uploads = attachments; issue.Watchers = new List <Watcher>(); issue.Watchers.Add(new Watcher { Id = 8 }); issue.Watchers.Add(new Watcher { Id = 2 }); //create issue and attach document Issue issueWithAttachment = redmineManager.CreateObject <Issue>(issue); issue = redmineManager.GetObject <Issue>(issueWithAttachment.Id.ToString(), new NameValueCollection { { "include", "attachments" } }); Assert.IsTrue(issue.Attachments.Count == 2 && issue.Attachments[0].FileName == attachment.FileName); }
/// <summary> /// Uploads the file asynchronous. /// </summary> /// <param name="redmineManager">The redmine manager.</param> /// <param name="data">The data.</param> /// <returns></returns> public static Task <Upload> UploadFileAsync(this RedmineManager redmineManager, byte[] data) { return(Task.Factory.StartNew(() => redmineManager.UploadFile(data), TaskCreationOptions.LongRunning)); }
/// <summary> /// Uploads the file asynchronous. /// </summary> /// <param name="redmineManager">The redmine manager.</param> /// <param name="data">The data.</param> /// <returns></returns> public static Task <Upload> UploadFileAsync(this RedmineManager redmineManager, byte[] data) { return(Task.Factory.StartNew(() => redmineManager.UploadFile(data))); }