public void Should_Update_Issue() { const string UPDATED_ISSUE_ID = "98"; const string UPDATED_ISSUE_SUBJECT = "Issue updated subject"; const string UPDATED_ISSUE_DESCRIPTION = null; const int UPDATED_ISSUE_PROJECT_ID = 9; const int UPDATED_ISSUE_TRACKER_ID = 3; const int UPDATED_ISSUE_PRIORITY_ID = 8; const int UPDATED_ISSUE_CATEGORY_ID = 18; const int UPDATED_ISSUE_ASSIGNED_TO_ID = 2; const int UPDATED_ISSUE_PARENT_ISSUE_ID = 91; const int UPDATED_ISSUE_CUSTOM_FIELD_ID = 13; const string UPDATED_ISSUE_CUSTOM_FIELD_VALUE = "Another custom field completed"; const int UPDATED_ISSUE_ESTIMATED_HOURS = 23; const string UPDATED_ISSUE_NOTES = "A lot is changed"; const bool UPDATED_ISSUE_PRIVATE_NOTES = true; DateTime?updatedIssueStartDate = default(DateTime?); var updatedIssueDueDate = DateTime.Now.AddMonths(1); var issue = fixture.RedmineManager.GetObject <Issue>(UPDATED_ISSUE_ID, new NameValueCollection { { RedmineKeys.INCLUDE, $"{RedmineKeys.CHILDREN},{RedmineKeys.ATTACHMENTS},{RedmineKeys.RELATIONS},{RedmineKeys.CHANGE_SETS},{RedmineKeys.JOURNALS},{RedmineKeys.WATCHERS}" } }); issue.Subject = UPDATED_ISSUE_SUBJECT; issue.Description = UPDATED_ISSUE_DESCRIPTION; issue.StartDate = updatedIssueStartDate; issue.DueDate = updatedIssueDueDate; issue.Project = IdentifiableName.Create(UPDATED_ISSUE_PROJECT_ID); issue.Tracker = IdentifiableName.Create(UPDATED_ISSUE_TRACKER_ID); issue.Priority = IdentifiableName.Create(UPDATED_ISSUE_PRIORITY_ID); issue.Category = IdentifiableName.Create(UPDATED_ISSUE_CATEGORY_ID); issue.AssignedTo = IdentifiableName.Create(UPDATED_ISSUE_ASSIGNED_TO_ID); issue.ParentIssue = IdentifiableName.Create(UPDATED_ISSUE_PARENT_ISSUE_ID); var icf = (IssueCustomField)IdentifiableName.Create(UPDATED_ISSUE_CUSTOM_FIELD_ID); icf.Values = new List <CustomFieldValue> { new CustomFieldValue { Info = UPDATED_ISSUE_CUSTOM_FIELD_VALUE } }; issue.CustomFields?.Add(icf); issue.EstimatedHours = UPDATED_ISSUE_ESTIMATED_HOURS; issue.Notes = UPDATED_ISSUE_NOTES; issue.PrivateNotes = UPDATED_ISSUE_PRIVATE_NOTES; fixture.RedmineManager.UpdateObject(UPDATED_ISSUE_ID, issue); var updatedIssue = fixture.RedmineManager.GetObject <Issue>(UPDATED_ISSUE_ID, new NameValueCollection { { RedmineKeys.INCLUDE, $"{RedmineKeys.CHILDREN},{RedmineKeys.ATTACHMENTS},{RedmineKeys.RELATIONS},{RedmineKeys.CHANGE_SETS},{RedmineKeys.JOURNALS},{RedmineKeys.WATCHERS}" } }); Assert.NotNull(updatedIssue); Assert.True(issue.Subject.Equals(updatedIssue.Subject), "Issue subject is invalid."); }
public void Should_Update_Group() { const string UPDATED_GROUP_ID = "58"; const string UPDATED_GROUP_NAME = "Best Developers"; const int UPDATED_GROUP_USER_ID = 2; var group = fixture.RedmineManager.GetObject <Group>(UPDATED_GROUP_ID, new NameValueCollection { { RedmineKeys.INCLUDE, RedmineKeys.USERS } }); group.Name = UPDATED_GROUP_NAME; group.Users.Add((GroupUser)IdentifiableName.Create(UPDATED_GROUP_USER_ID)); fixture.RedmineManager.UpdateObject(UPDATED_GROUP_ID, group); var updatedGroup = fixture.RedmineManager.GetObject <Group>(UPDATED_GROUP_ID, new NameValueCollection { { RedmineKeys.INCLUDE, RedmineKeys.USERS } }); Assert.NotNull(updatedGroup); Assert.True(updatedGroup.Name.Equals(UPDATED_GROUP_NAME), "Group name was not updated."); Assert.NotNull(updatedGroup.Users); // Assert.True(updatedGroup.Users.Find(u => u.Id == UPDATED_GROUP_USER_ID) != null, //"User was not added to group."); }
private static Project CreateTestProjectWithAllPropertiesSet() { var project = new Project { Name = "Redmine Net Api Project Test All Properties", Description = "This is a test project.", Identifier = "rnaptap", HomePage = "www.redminetest.com", IsPublic = true, InheritMembers = true, EnabledModules = new List <ProjectEnabledModule> { new ProjectEnabledModule { Name = "issue_tracking" }, new ProjectEnabledModule { Name = "time_tracking" } }, Trackers = new List <ProjectTracker> { (ProjectTracker)IdentifiableName.Create <ProjectTracker>(1), (ProjectTracker)IdentifiableName.Create <ProjectTracker>(2) } }; return(project); }
public async Task Should_Create_User() { var user = new User { Login = "******", FirstName = "userTestFirstName", LastName = "userTestLastName", Email = "*****@*****.**", Password = "******", AuthenticationModeId = 1, MustChangePassword = false }; var icf = (IssueCustomField)IdentifiableName.Create(4); icf.Values = new List <CustomFieldValue> { new CustomFieldValue { Info = "userTestCustomField:" + DateTime.UtcNow } }; user.CustomFields = new List <IssueCustomField>(); user.CustomFields.Add(icf); var createdUser = await fixture.RedmineManager.CreateObjectAsync(user); Assert.Equal(user.Login, createdUser.Login); Assert.Equal(user.Email, createdUser.Email); }
public void Should_Create_Time_Entry() { const int NEW_TIME_ENTRY_ISSUE_ID = 18; const int NEW_TIME_ENTRY_PROJECT_ID = 9; var newTimeEntryDate = DateTime.Now; const int NEW_TIME_ENTRY_HOURS = 1; const int NEW_TIME_ENTRY_ACTIVITY_ID = 16; const string NEW_TIME_ENTRY_COMMENTS = "Added time entry on project"; var timeEntry = new TimeEntry { Issue = IdentifiableName.Create(NEW_TIME_ENTRY_ISSUE_ID), Project = IdentifiableName.Create(NEW_TIME_ENTRY_PROJECT_ID), SpentOn = newTimeEntryDate, Hours = NEW_TIME_ENTRY_HOURS, Activity = IdentifiableName.Create(NEW_TIME_ENTRY_ACTIVITY_ID), Comments = NEW_TIME_ENTRY_COMMENTS }; var savedTimeEntry = fixture.RedmineManager.CreateObject(timeEntry); Assert.NotNull(savedTimeEntry); Assert.NotNull(savedTimeEntry.Issue); Assert.True(savedTimeEntry.Issue.Id == NEW_TIME_ENTRY_ISSUE_ID, "Issue id is invalid."); Assert.NotNull(savedTimeEntry.Project); Assert.True(savedTimeEntry.Project.Id == NEW_TIME_ENTRY_PROJECT_ID, "Project id is invalid."); Assert.NotNull(savedTimeEntry.SpentOn); Assert.True(DateTime.Compare(savedTimeEntry.SpentOn.Value.Date, newTimeEntryDate.Date) == 0, "Date is invalid."); Assert.True(savedTimeEntry.Hours == NEW_TIME_ENTRY_HOURS, "Hours value is not valid."); Assert.NotNull(savedTimeEntry.Activity); Assert.True(savedTimeEntry.Activity.Id == NEW_TIME_ENTRY_ACTIVITY_ID, "Activity id is invalid."); Assert.NotNull(savedTimeEntry.Comments); Assert.True(savedTimeEntry.Comments.Equals(NEW_TIME_ENTRY_COMMENTS), "Coments value is invalid."); }
private static Project CreateTestProjectWithParentSet(int parentId) { var project = new Project { Name = "Redmine Net Api Project With Parent Set", Identifier = "rnapwps", Parent = IdentifiableName.Create <IdentifiableName>(parentId) }; return(project); }
public void Should_Upload_Attachment() { const string ATTACHMENT_LOCAL_PATH = "uploadAttachment.pages"; const string ATTACHMENT_NAME = "AttachmentUploaded.txt"; const string ATTACHMENT_DESCRIPTION = "File uploaded using REST API"; const string ATTACHMENT_CONTENT_TYPE = "text/plain"; const int PROJECT_ID = 9; const string ISSUE_SUBJECT = "Issue with attachments"; //read document from specified path var documentData = System.IO.File.ReadAllBytes(AppDomain.CurrentDomain.BaseDirectory + ATTACHMENT_LOCAL_PATH); //upload attachment to redmine var attachment = fixture.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); var issue = new Issue { Project = IdentifiableName.Create <IdentifiableName>(PROJECT_ID), Subject = ISSUE_SUBJECT, Uploads = attachments }; //create issue and attach document var issueWithAttachment = fixture.RedmineManager.CreateObject(issue); issue = fixture.RedmineManager.GetObject <Issue>(issueWithAttachment.Id.ToString(), new NameValueCollection { { RedmineKeys.INCLUDE, RedmineKeys.ATTACHMENTS } }); Assert.NotNull(issue); Assert.NotNull(issue.Attachments); Assert.True(issue.Attachments.Count == 1, "Number of attachments ( " + issue.Attachments.Count + " ) != 1"); var firstAttachment = issue.Attachments[0]; Assert.True(firstAttachment.FileName == ATTACHMENT_NAME, "Attachment name is invalid."); Assert.True(firstAttachment.Description == ATTACHMENT_DESCRIPTION, "Attachment description is invalid."); Assert.True(firstAttachment.ContentType == ATTACHMENT_CONTENT_TYPE, "Attachment content type is invalid."); }
public void Should_Create_IssueCategory() { var issueCategory = new IssueCategory { Name = NEW_ISSUE_CATEGORY_NAME, AssignTo = IdentifiableName.Create <IdentifiableName>(NEW_ISSUE_CATEGORY_ASIGNEE_ID) }; var savedIssueCategory = fixture.RedmineManager.CreateObject(issueCategory, PROJECT_ID); createdIssueCategoryId = savedIssueCategory.Id.ToString(); Assert.NotNull(savedIssueCategory); Assert.True(savedIssueCategory.Name.Equals(NEW_ISSUE_CATEGORY_NAME), "Saved issue category name is invalid."); }
private static Project CreateTestProjectWithInvalidTrackersId() { var project = new Project { Name = "Redmine Net Api Project Test Invalid Trackers", Identifier = "rnaptit", Trackers = new List <ProjectTracker> { (ProjectTracker)IdentifiableName.Create <ProjectTracker>(999999), (ProjectTracker)IdentifiableName.Create <ProjectTracker>(999998) } }; return(project); }
public void Should_Update_Project_Membership() { const string UPDATED_PROJECT_MEMBERSHIP_ID = "143"; const int UPDATED_PROJECT_MEMBERSHIP_ROLE_ID = 4; var pm = fixture.RedmineManager.GetObject <ProjectMembership>(UPDATED_PROJECT_MEMBERSHIP_ID, null); pm.Roles.Add((MembershipRole)IdentifiableName.Create <MembershipRole>(UPDATED_PROJECT_MEMBERSHIP_ROLE_ID)); fixture.RedmineManager.UpdateObject(UPDATED_PROJECT_MEMBERSHIP_ID, pm); var updatedPm = fixture.RedmineManager.GetObject <ProjectMembership>(UPDATED_PROJECT_MEMBERSHIP_ID, null); Assert.NotNull(updatedPm); Assert.NotNull(updatedPm.Roles); //Assert.True(updatedPm.Roles.Find(r => r.Id == UPDATED_PROJECT_MEMBERSHIP_ROLE_ID) != null, // string.Format("Role with id {0} was not found in roles list.", UPDATED_PROJECT_MEMBERSHIP_ROLE_ID)); }
public void Should_Add_Group() { const string NEW_GROUP_NAME = "Developers1"; const int NEW_GROUP_USER_ID = 8; var group = new Group(); group.Name = NEW_GROUP_NAME; group.Users = new List <GroupUser> { (GroupUser)IdentifiableName.Create(NEW_GROUP_USER_ID) }; Group savedGroup = null; var exception = (RedmineException)Record.Exception(() => savedGroup = fixture.RedmineManager.CreateObject(group)); Assert.Null(exception); Assert.NotNull(savedGroup); Assert.True(group.Name.Equals(savedGroup.Name), "Group name is not valid."); }
public void Should_Update_IssueCategory() { const string ISSUE_CATEGORY_NAME_TO_UPDATE = "Category updated"; const int ISSUE_CATEGORY_ASIGNEE_ID_TO_UPDATE = 2; var issueCategory = fixture.RedmineManager.GetObject <IssueCategory>(createdIssueCategoryId, null); issueCategory.Name = ISSUE_CATEGORY_NAME_TO_UPDATE; issueCategory.AssignTo = IdentifiableName.Create <IdentifiableName>(ISSUE_CATEGORY_ASIGNEE_ID_TO_UPDATE); fixture.RedmineManager.UpdateObject(createdIssueCategoryId, issueCategory); var updatedIssueCategory = fixture.RedmineManager.GetObject <IssueCategory>(createdIssueCategoryId, null); Assert.NotNull(updatedIssueCategory); Assert.True(updatedIssueCategory.Name.Equals(ISSUE_CATEGORY_NAME_TO_UPDATE), "Issue category name was not updated."); Assert.NotNull(updatedIssueCategory.AssignTo); Assert.True(updatedIssueCategory.AssignTo.Id == ISSUE_CATEGORY_ASIGNEE_ID_TO_UPDATE, "Issue category asignee was not updated."); }
public void Should_Add_Project_Membership() { const int NEW_PROJECT_MEMBERSHIP_USER_ID = 2; const int NEW_PROJECT_MEMBERSHIP_ROLE_ID = 5; var pm = new ProjectMembership { User = IdentifiableName.Create <IdentifiableName>(NEW_PROJECT_MEMBERSHIP_USER_ID), Roles = new List <MembershipRole> { (MembershipRole)IdentifiableName.Create <MembershipRole>(NEW_PROJECT_MEMBERSHIP_ROLE_ID) } }; var createdPm = fixture.RedmineManager.CreateObject(pm, PROJECT_IDENTIFIER); Assert.NotNull(createdPm); Assert.True(createdPm.User.Id == NEW_PROJECT_MEMBERSHIP_USER_ID, "User is invalid."); Assert.NotNull(createdPm.Roles); //Assert.True(createdPm.Roles.Exists(r => r.Id == NEW_PROJECT_MEMBERSHIP_ROLE_ID), // string.Format("Role id {0} does not exist.", NEW_PROJECT_MEMBERSHIP_ROLE_ID)); }
public void Should_Clone_Issue() { const string ISSUE_TO_CLONE_SUBJECT = "Issue to clone"; const int ISSUE_TO_CLONE_CUSTOM_FIELD_ID = 13; const string ISSUE_TO_CLONE_CUSTOM_FIELD_VALUE = "Issue to clone custom field value"; const int CLONED_ISSUE_CUSTOM_FIELD_ID = 13; const string CLONED_ISSUE_CUSTOM_FIELD_VALUE = "Cloned issue custom field value"; var icfc = (IssueCustomField)IdentifiableName.Create(ISSUE_TO_CLONE_CUSTOM_FIELD_ID); icfc.Values = new List <CustomFieldValue> { new CustomFieldValue { Info = ISSUE_TO_CLONE_CUSTOM_FIELD_VALUE } }; var issueToClone = new Issue { Subject = ISSUE_TO_CLONE_SUBJECT, CustomFields = new List <IssueCustomField>() { icfc } }; var clonedIssue = (Issue)issueToClone.Clone(); var icf = (IssueCustomField)IdentifiableName.Create(CLONED_ISSUE_CUSTOM_FIELD_ID); icf.Values = new List <CustomFieldValue> { new CustomFieldValue { Info = CLONED_ISSUE_CUSTOM_FIELD_VALUE } }; clonedIssue.CustomFields.Add(icf); Assert.True(issueToClone.CustomFields.Count != clonedIssue.CustomFields.Count); }
public void Should_Update_Time_Entry() { const string UPDATED_TIME_ENTRY_ID = "31"; const int UPDATED_TIME_ENTRY_ISSUE_ID = 18; const int UPDATED_TIME_ENTRY_PROJECT_ID = 9; const int UPDATED_TIME_ENTRY_HOURS = 3; const int UPDATED_TIME_ENTRY_ACTIVITY_ID = 17; const string UPDATED_TIME_ENTRY_COMMENTS = "Time entry updated"; var updatedTimeEntryDate = DateTime.Now.AddDays(-2); var timeEntry = fixture.RedmineManager.GetObject <TimeEntry>(UPDATED_TIME_ENTRY_ID, null); timeEntry.Project = IdentifiableName.Create(UPDATED_TIME_ENTRY_PROJECT_ID); timeEntry.Issue = IdentifiableName.Create(UPDATED_TIME_ENTRY_ISSUE_ID); timeEntry.SpentOn = updatedTimeEntryDate; timeEntry.Hours = UPDATED_TIME_ENTRY_HOURS; timeEntry.Comments = UPDATED_TIME_ENTRY_COMMENTS; if (timeEntry.Activity == null) { timeEntry.Activity = IdentifiableName.Create(UPDATED_TIME_ENTRY_ACTIVITY_ID); } fixture.RedmineManager.UpdateObject(UPDATED_TIME_ENTRY_ID, timeEntry); var updatedTimeEntry = fixture.RedmineManager.GetObject <TimeEntry>(UPDATED_TIME_ENTRY_ID, null); Assert.NotNull(updatedTimeEntry); Assert.True(updatedTimeEntry.Project.Id == timeEntry.Project.Id, "Time entry project was not updated."); Assert.True(updatedTimeEntry.Issue.Id == timeEntry.Issue.Id, "Time entry issue was not updated."); Assert.True( updatedTimeEntry.SpentOn != null && timeEntry.SpentOn != null && DateTime.Compare(updatedTimeEntry.SpentOn.Value.Date, timeEntry.SpentOn.Value.Date) == 0, "Time entry spent on field was not updated."); Assert.True(updatedTimeEntry.Hours == timeEntry.Hours, "Time entry hours was not updated."); Assert.True(updatedTimeEntry.Comments.Equals(timeEntry.Comments), "Time entry comments was not updated."); }
public void Should_Add_Issue() { const bool NEW_ISSUE_IS_PRIVATE = true; const int NEW_ISSUE_PROJECT_ID = 9; const int NEW_ISSUE_TRACKER_ID = 3; const int NEW_ISSUE_STATUS_ID = 6; const int NEW_ISSUE_PRIORITY_ID = 9; const int NEW_ISSUE_CATEGORY_ID = 18; const int NEW_ISSUE_FIXED_VERSION_ID = 9; const int NEW_ISSUE_ASSIGNED_TO_ID = 8; const int NEW_ISSUE_PARENT_ISSUE_ID = 96; const int NEW_ISSUE_CUSTOM_FIELD_ID = 13; const int NEW_ISSUE_ESTIMATED_HOURS = 12; const int NEW_ISSUE_FIRST_WATCHER_ID = 2; const int NEW_ISSUE_SECOND_WATCHER_ID = 8; const string NEW_ISSUE_CUSTOM_FIELD_VALUE = "Issue custom field completed"; const string NEW_ISSUE_SUBJECT = "Issue created using Rest API"; const string NEW_ISSUE_DESCRIPTION = "Issue description..."; var newIssueStartDate = DateTime.Now; var newIssueDueDate = DateTime.Now.AddDays(10); var icf = (IssueCustomField)IdentifiableName.Create(NEW_ISSUE_CUSTOM_FIELD_ID); icf.Values = new List <CustomFieldValue> { new CustomFieldValue { Info = NEW_ISSUE_CUSTOM_FIELD_VALUE } }; var issue = new Issue { Project = IdentifiableName.Create(NEW_ISSUE_PROJECT_ID), Tracker = IdentifiableName.Create(NEW_ISSUE_TRACKER_ID), Status = IdentifiableName.Create(NEW_ISSUE_STATUS_ID), Priority = IdentifiableName.Create(NEW_ISSUE_PRIORITY_ID), Subject = NEW_ISSUE_SUBJECT, Description = NEW_ISSUE_DESCRIPTION, Category = IdentifiableName.Create(NEW_ISSUE_CATEGORY_ID), FixedVersion = IdentifiableName.Create(NEW_ISSUE_FIXED_VERSION_ID), AssignedTo = IdentifiableName.Create(NEW_ISSUE_ASSIGNED_TO_ID), ParentIssue = IdentifiableName.Create(NEW_ISSUE_PARENT_ISSUE_ID), CustomFields = new List <IssueCustomField> { icf }, IsPrivate = NEW_ISSUE_IS_PRIVATE, EstimatedHours = NEW_ISSUE_ESTIMATED_HOURS, StartDate = newIssueStartDate, DueDate = newIssueDueDate, Watchers = new List <Watcher> { (Watcher)IdentifiableName.Create(NEW_ISSUE_FIRST_WATCHER_ID), (Watcher)IdentifiableName.Create(NEW_ISSUE_SECOND_WATCHER_ID) } }; var savedIssue = fixture.RedmineManager.CreateObject(issue); Assert.NotNull(savedIssue); Assert.True(issue.Subject.Equals(savedIssue.Subject), "Issue subject is invalid."); Assert.NotEqual(issue, savedIssue); }
private static void UpdateBasedOnExcelFile(List <IssueItem> issuesInRedmineProject, List <StatItem> statItems, bool allWithinDirectory) { //********************************************************************************************************/ //read data from Excel List <string> filesToProcess = null; if (allWithinDirectory) { filesToProcess = Directory.EnumerateFiles(MOM_FILES_DIR, "*.xlsx").ToList(); } else { filesToProcess = new List <string>(); filesToProcess.Add(MOM_FILE_PATH); } foreach (string singleXSLXfile in filesToProcess) { var xlsx = new LinqToExcel.ExcelQueryFactory(singleXSLXfile); output.WriteLine("File: {0}", singleXSLXfile); foreach (string tabName in xlsx.GetWorksheetNames()) { output.WriteLine("--------------------------------------------"); output.WriteLine("Processing of {0}...", tabName); output.WriteLine("--------------------------------------------"); StatItem statItem = new StatItem(tabName); statItem.Env = tabName; var query = from row in xlsx.Worksheet(tabName) let item = new { ProblemID = row["Problem ID"].Cast <string>(), ProblemCode = row["Problem Code"].Cast <string>(), MessageId = row["Message ID"].Cast <string>(), EventCode = row["Event Code"].Cast <string>(), Details = row["Details"].Cast <string>(), SenderCode = row["Sender Code"].Cast <string>(), } select item; IdentifiableName p = IdentifiableName.Create <Project>(Consts.PROJECT_NAMES.MOM.PROBLEMS); foreach (var itemFromExcel in query) { //look for the item in RM var redmineIssue = issuesInRedmineProject.Where(issueFromRedmine => issueFromRedmine.Env == tabName && issueFromRedmine.ProblemId == itemFromExcel.ProblemID).FirstOrDefault(); if (redmineIssue != null && string.IsNullOrEmpty(redmineIssue.SenderCode)) { if (!string.IsNullOrEmpty(itemFromExcel.SenderCode)) { var issue = RMManegerService.RMManager.GetObject <Issue>(redmineIssue.Id.ToString(), null); issue.Subject = issue.Subject + string.Format(" - {0}", itemFromExcel.SenderCode); RMManegerService.RMManager.UpdateObject(redmineIssue.Id.ToString(), issue); redmineIssue.SenderCode = itemFromExcel.SenderCode; statItem.Updated++; // string subject = redmineIssue.sub //string subject = string.Format("{0} - {1} - {2} - {3} - {4}", tabName, itemFromExcel.ProblemID, itemFromExcel.EventCode, itemFromExcel.ProblemCode, itemFromExcel.SenderCode); } else { statItem.NotUpdated++; } } else { statItem.NotUpdated++; } } statItems.Add(statItem); } } }
private static void ProcessExcelFile(List <IssueItem> issuesInRedmineProject, List <StatItem> statItems, List <string> envsNotExistingInConfigs) { //********************************************************************************************************/ //read data from Excel var xlsx = new LinqToExcel.ExcelQueryFactory(MOM_FILE_PATH); foreach (string tabName in xlsx.GetWorksheetNames()) { output.WriteLine("--------------------------------------------"); output.WriteLine("Processing of {0}...", tabName); output.WriteLine("--------------------------------------------"); MOMEnvSettings momEnvSettings = null; if (!MOM_ENV_SETTINGS.TryGetValue(tabName, out momEnvSettings)) { output.WriteLine("No MOMEnvSettings for {0}", tabName); envsNotExistingInConfigs.Add(tabName); //output.ReadKey(); } else { output.WriteLine("Start processing: {0}", tabName); StatItem statItem = new StatItem(); statItem.Env = tabName; var query = from row in xlsx.Worksheet(tabName) let item = new { ProblemID = row["Problem ID"].Cast <string>(), ProblemCode = row["Problem Code"].Cast <string>(), MessageId = row["Message ID"].Cast <string>(), EventCode = row["Event Code"].Cast <string>(), Details = row["Details"].Cast <string>(), SenderCode = row["Sender Code"].Cast <string>(), } select item; IdentifiableName p = IdentifiableName.Create <Project>(Consts.PROJECT_NAMES.MOM.PROBLEMS); foreach (var itemFromExcel in query) { string subject = string.Format("{0} - {1} - {2} - {3} - {4}", tabName, itemFromExcel.ProblemID, itemFromExcel.EventCode, itemFromExcel.ProblemCode, itemFromExcel.SenderCode); //check if such the item exists in the Redmine project var redmineIssue = issuesInRedmineProject.Where(issueFromRedmine => issueFromRedmine.Env == tabName && issueFromRedmine.ProblemId == itemFromExcel.ProblemID); if (redmineIssue.Count() == 0) { string details = string.Format("{0}\r\nMessage link: {1}\r\nProblem link: {2}", itemFromExcel.Details, momEnvSettings.GetMessageLink(itemFromExcel.MessageId), momEnvSettings.GetProblemLink(itemFromExcel.MessageId)); var newIssue = new Issue { Subject = subject, Project = p, Description = details }; RMManegerService.RMManager.CreateObject(newIssue); //add a new item to local cached items from redmine IssueItem item = new IssueItem(); item.Env = tabName; item.ProblemId = itemFromExcel.ProblemID; issuesInRedmineProject.Add(item); statItem.Added++; } else { output.WriteLine("Issue exists! {0}", subject); statItem.AlreadyExisted++; } } statItems.Add(statItem); } } }
public async Task Should_Upload_Attachment() { //read document from specified path var documentPath = AppDomain.CurrentDomain.BaseDirectory + "/uploadAttachment.pages"; var documentData = System.IO.File.ReadAllBytes(documentPath); //upload attachment to redmine var attachment = await fixture.RedmineManager.UploadFileAsync(documentData); //set attachment properties attachment.FileName = "uploadAttachment.pages"; 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); var icf = (IssueCustomField)IdentifiableName.Create(13); icf.Values = new List <CustomFieldValue> { new CustomFieldValue { Info = "Issue custom field completed" } }; var issue = new Issue { Project = IdentifiableName.Create(9), Tracker = IdentifiableName.Create(3), Status = IdentifiableName.Create(6), Priority = IdentifiableName.Create(9), Subject = "Issue with attachments", Description = "Issue description...", Category = IdentifiableName.Create(18), FixedVersion = IdentifiableName.Create(9), AssignedTo = IdentifiableName.Create(8), ParentIssue = IdentifiableName.Create(96), CustomFields = new List <IssueCustomField> { icf }, IsPrivate = true, EstimatedHours = 12, StartDate = DateTime.Now, DueDate = DateTime.Now.AddMonths(1), Uploads = attachments, Watchers = new List <Watcher> { (Watcher)IdentifiableName.Create(8), (Watcher)IdentifiableName.Create(2) } }; //create issue and attach document var issueWithAttachment = await fixture.RedmineManager.CreateObjectAsync(issue); issue = await fixture.RedmineManager.GetObjectAsync <Issue>(issueWithAttachment.Id.ToString(), new NameValueCollection { { "include", "attachments" } }); Assert.NotNull(issue); Assert.IsType <Issue>(issue); Assert.True(issue.Attachments.Count == 1, "Attachments count != 1"); Assert.True(issue.Attachments[0].FileName == attachment.FileName); }
public void AddMissingTMSTasksToRedmine() { sw.StartStopwatchAndPrintMessage("Getting TMS tasks from DB and making cache...", output); GetherSyncData(); IdentifiableName p = IdentifiableName.Create <Project>(Consts.PROJECT_NAMES.TMS.MACBI.PROBLEMS); //to-be-changed //IdentifiableName u = IdentifiableName.Create<User>(USER_ID); //var user = RMManegerService.RMManager.GetObject<User>(USER_ID.ToString(), null); IdentifiableName u = IdentifiableName.Create <IdentifiableName>(USER_ID); IdentifiableName priority = IdentifiableName.Create <IdentifiableName>(PRIORITY_HIGH); //var newIssue = new Issue { Subject = subject, Project = p, Description = details }; //RMManegerService.RMManager.CreateObject(newIssue); int limit = 5; List <string> listOfAddedItems = new List <string>(); List <string> listOfNOTAddedItems = new List <string>(); foreach (TMSItem item in dbTMSDict.GetNotClosedNotUsedAssignedToDEV1ItemList(TeamService.UsersTMSLogin)) { string description = item.Desctiption; //check if really there is no such a TMS in RM (maybe it was already closed) TMSItem tmsItem = rmTMSDict.Get(item.TMS); //redMineTMSList.Contains() if (tmsItem == null) { string firstLine = null; if (description.Contains("\r\n") || description.Contains(".")) { firstLine = description.Substring(0, description.Contains("\r\n") ? description.IndexOf("\r\n") : description.IndexOf(".")); } else { firstLine = description; } if (firstLine.Length > 255) { firstLine = firstLine.Substring(0, 240);//255 is max lenght of subject. int lastDotIndex = firstLine.LastIndexOf("."); if (lastDotIndex > -1) { firstLine = firstLine.Substring(0, lastDotIndex); } } string subject = string.Format("{0} - {1}", item.TMS, firstLine); var newIssue = new Issue { Subject = subject, Project = p, Description = description, AssignedTo = u, Priority = priority }; RMManegerService.RMManager.CreateObject(newIssue); listOfAddedItems.Add(subject); } else { listOfNOTAddedItems.Add(string.Format("{0}", tmsItem)); //Console.WriteLine("Item can't be added as it already exists: {0}", tmsItem); } if (Consts.TEST_MODE) { if (--limit == 0) { return; } } } output.WriteLine("List of added items ({0})", listOfAddedItems.Count); output.WriteLine("List of NOT added items ({0})", listOfNOTAddedItems.Count); if (listOfAddedItems.Count > 0) { output.WriteLine("Cache needs to be refreshed!"); rmTMSDict = null; GetherSyncData(); } sw.StopStopwatchAndPrintDoneMessageWithElapsedTime(output); }