public void Can_construct_instance_with_data() { var workitem = new Workitem(new SubmitData { Data = "Keep it safe" }); var required = workitem.Require<SubmitData>(); Assert.That(required.Data, Is.EqualTo("Keep it safe")); }
public void Can_require_instance() { var workitem = new Workitem(); workitem.Submit(new SubmitData { Data = "Keep it safe" }); var required = workitem.Require<SubmitData>(); Assert.That(required.Data, Is.EqualTo("Keep it safe")); }
public void When_submitting_when_same_type_exists_it_replaces_instance() { var workitem = new Workitem(new SubmitData { Data = "Keep for only a while" }); workitem.Submit(new SubmitData { Data = "This is better" }); var required = workitem.Require<SubmitData>(); Assert.That(required.Data, Is.EqualTo("This is better")); }
public WorkitemCreationResult CreateWorkitem(Workitem item, ServerConnector.Entities.Workitem closedDuplicate) { item.Description += string.Format("\n\n This is a copy of '{0}' {1}", closedDuplicate.Number, closedDuplicate.TypeName); var workitem = CreateNewWorkitem(item); var url = v1Processor.GetSummaryLink(closedDuplicate); var link = new Link(url, "Previous item"); v1Processor.AddLinkToEntity(workitem, link); return GetWorkitemCreationResult(item, workitem); }
public void It_can_transform_to_enumerable_inputs() { var transform = new Transform<string, string, int, int>(); var workitem = new Workitem(1); workitem.Submit("a string"); var stepIos = new [] {new StepIo<int, int>(workitem)}; var transformed = transform.Do(stepIos).Single(); Assert.That(transformed.Input, Is.EqualTo("a string")); }
private WorkitemCreationResult GetWorkitemCreationResult(Workitem item, ServerConnector.Entities.Workitem newWorkitem) { if(newWorkitem != null) { var result = ConvertToWorkitemCreationResult(item, newWorkitem); result.Messages.Add(string.Format("Created item \"{0}\" ({1}) in Project \"{2}\" URL: {3}", item.Title, result.Source.Number, item.Project, result.Permalink)); return result; } return null; }
private WorkitemCreationResult ConvertToWorkitemCreationResult(Workitem item, ServerConnector.Entities.Workitem newWorkitem) { var result = new WorkitemCreationResult(item) { Source = { Number = newWorkitem.Number, ExternalId = item.ExternalId, Description = newWorkitem.Description, ExternalSystemName = item.ExternalSystemName, ProjectId = newWorkitem.Project.Key, Project = newWorkitem.Project.Value, Title = newWorkitem.Name, Priority = newWorkitem.PriorityToken, }, WorkitemId = newWorkitem.Id, Permalink = v1Processor.GetWorkitemLink(newWorkitem), }; return result; }
public ActionResult AddWorkitem(Workitem addWorkitemData, HttpPostedFileBase myFiles) { var redirectURL = ""; try { if (myFiles != null) { if (myFiles.ContentLength < 1024 * 1024 * 4) { string filename = Convert.ToString(Session["path"]); myFiles.SaveAs(filename); redirectURL = Url.Action("Dashboard", "Home"); } } else { if (addWorkitemData.Title != null && addWorkitemData.Content < 4194304) { if (ModelState.IsValid) { if (addWorkitemData.DocumentFilePath != null) { var path = Path.Combine(Server.MapPath("~/work1/Download/"), addWorkitemData.DocumentFilePath); addWorkitemData.DocumentFilePath = path; Session["path"] = addWorkitemData.DocumentFilePath; } var getResultsOfWorkitemData = workbountyRepo.AddWorkitem(addWorkitemData); redirectURL = Url.Action("Dashboard", "Home"); return null; } else { return RedirectToAction("Error", "Home"); } } } } catch (Exception) { return RedirectToAction("Error", "Home"); } return RedirectToAction("Dashboard", "Home"); }
public string AddWorkitem(Workitem addWorkitemData) { try { if (ModelState.IsValid) { entity.Workitems.Add(addWorkitemData); entity.SaveChanges(); return "Data Successfully saved"; } else { return "Error"; } } catch (Exception) { return "error"; } }
public bool CheckForDuplicate(Workitem item) { if(string.IsNullOrEmpty(item.ExternalSystemName) || string.IsNullOrEmpty(externalFieldName)) { // Can't check for duplicates if we don't have the Source and the ID. return false; } try { var filter = GroupFilter.And( Filter.Equal(Entity.SourceNameProperty, item.ExternalSystemName), Filter.Equal(externalFieldName, item.ExternalId) ); var duplicates = v1Processor.GetPrimaryWorkitems(filter); return duplicates.Count > 0; } catch(WebException) { //LogMessage.Log(LogMessage.SeverityType.Error, string.Format("Error querying VersionOne ({0}) for closed external defects:\r\n{1}", ex.Response.ResponseUri, ex.ToString()), _eventManager); } return false; }
public IList<ServerConnector.Entities.Workitem> GetDuplicates(Workitem item) { var emptyDuplicateList = new List<ServerConnector.Entities.Workitem>(); if(string.IsNullOrEmpty(item.ExternalSystemName) || string.IsNullOrEmpty(configuration.ExternalIdFieldName)) { return emptyDuplicateList; } try { var filter = GroupFilter.And( Filter.Equal(Entity.SourceNameProperty, item.ExternalSystemName), Filter.Equal(configuration.ExternalIdFieldName, item.ExternalId), Filter.OfTypes(VersionOneProcessor.PrimaryWorkitemType) ); var duplicates = v1Processor.GetWorkitems(item.Type, filter); return duplicates; } catch (VersionOneException ex) { logger.Log(LogMessage.SeverityType.Error, string.Format("Can't get duplicates for {0} {1}. Cause:\n{2}", item.Number, item.Type, ex.Message)); } return emptyDuplicateList; }
private ServerConnector.Entities.Workitem CreateNewWorkitem(Workitem item) { if(item == null) { throw new ArgumentNullException("item"); } var type = item.Type; logger.Log(LogMessage.SeverityType.Info, string.Format("Creating VersionOne {0} for item from {1} system with identifier {2}", type, item.ExternalSystemName, item.ExternalId)); var projectToken = FindProperProjectToken(item.ProjectId, item.Project); try { var newWorkitem = v1Processor.CreateWorkitem(type, item.Title, item.Description, projectToken, configuration.ExternalIdFieldName, item.ExternalId, item.ExternalSystemName, item.Priority, item.Owners); AddLinkToWorkitemToOriginalIssue(item, newWorkitem); logger.Log(LogMessage.SeverityType.Info, string.Format("VersionOne asset {0} succesfully created.", newWorkitem.Id)); return newWorkitem; } catch(Exception ex) { logger.Log(LogMessage.SeverityType.Error, string.Format("Error during saving workitems: {0}", ex.Message)); return null; } }
public WorkitemCreationResult(Workitem source) { Source = source; }
public string ApplyReward(Rewards id) { try { using (WorkBountyDBEntities entities = new WorkBountyDBEntities()) { entities.Configuration.ValidateOnSaveEnabled = false; string remarks = id.Remarks.ToString(); Workitem remark = new Workitem() { WorkitemID = id.WorkItemID, Remarks = id.Remarks }; entities.Workitems.Attach(remark); entities.Entry(remark).Property(u => u.Remarks).IsModified = true; entities.SaveChanges(); } List<WorkItemAssignment> checkUploadedWorkitem = entity.WorkItemAssignments.Where(s => s.WorkItemID == id.WorkItemID && s.UserID == id.UserID).ToList(); foreach (var data in checkUploadedWorkitem) { WorkItemAssignment item = entity.WorkItemAssignments.Where(s => s.WorkItemID == id.WorkItemID && s.UserID == id.UserID).FirstOrDefault(); item.IsRewarded = true; entity.SaveChanges(); } return "Success"; } catch (Exception) { return "Error"; } }
public bool UpdateExternalWorkitem(Workitem workitem) { var primaryWorkitem = v1Processor.GetPrimaryWorkitemByNumber(workitem.Number); if (primaryWorkitem == null) return false; primaryWorkitem.Source = workitem.ExternalSystemName; primaryWorkitem.Reference = workitem.ExternalId; v1Processor.SaveWorkitem(primaryWorkitem); Link link = new Link(workitem.ExternalUrl.Url, workitem.ExternalUrl.Title, true); v1Processor.AddLinkToWorkitem(primaryWorkitem, link); return true; }
public WorkitemCreationResult CreateWorkitem(Workitem item) { var workitem = CreateNewWorkitem(item); return GetWorkitemCreationResult(item, workitem); }
public WorkitemFromExternalSystem(Workitem item, string externalIdFieldName) : base(item.Asset, item.ListValues, item.TypeResolver) { this.externalIdFieldName = externalIdFieldName; }
public UpdateResult UpdateWorkitem(Workitem item) { if (item == null) return null; if(statusMapping == null) statusMapping = v1Processor.GetAvailableStatuses(); try { string externalId = item.ExternalId; string externalSystemName = item.ExternalSystemName; string statusId = ResolveStatusIdFromName(item.Status); UpdateResult result = new UpdateResult(); v1Processor.UpdateWorkitem(externalFieldName, externalId, externalSystemName, statusId, result); return result; }catch (Exception ex) { logger.Log(LogMessage.SeverityType.Error, string.Format("Faild to update item in versionOne, reason: \"{0}\"", ex.Message)); } return null; }
private WorkitemCreationResult CreateWorkitem(Workitem toSendToV1, IList<ServerConnector.Entities.Workitem> duplicates) { if(duplicates.Count == 0) { return workitemWriter.CreateWorkitem(toSendToV1); } var lastDuplicate = FindLastDuplicate(duplicates); var result = workitemWriter.CreateWorkitem(toSendToV1, lastDuplicate); return result; }
private void AddLinkToWorkitemToOriginalIssue(Workitem item, ServerConnector.Entities.Workitem newWorkitem) { if(item.ExternalLink == null) { return; } var url = item.ExternalLink.Url; var urlTitle = item.ExternalLink.Title; var title = !string.IsNullOrEmpty(urlTitle) ? urlTitle : url; var link = new Link(url, title, true); v1Processor.AddLinkToEntity(newWorkitem, link); }
public void It_throws_when_requiring_something_that_hasnt_been_submitted() { var workitem = new Workitem(); Assert.Throws<Exception>(() => workitem.Require<SubmitData>()); }
public WorkitemUpdateResult CreateWorkitem(Workitem item) { if(item == null) { throw new ArgumentNullException("item"); } var type = item.Type; logger.Log(LogMessage.SeverityType.Info, string.Format("Creating VersionOne {0} for item from {1} system with identifier {2}", type, item.ExternalSystemName, item.ExternalId)); var url = string.Empty; var urlTitle = string.Empty; if(item.ExternalUrl != null) { url = item.ExternalUrl.Url; urlTitle = item.ExternalUrl.Title; } ServerConnector.Entities.Workitem newWorkitem = null; string failureMessage = null; try { newWorkitem = v1Processor.CreateWorkitem(type, item.Title, item.Description, item.ProjectId, item.Project, externalFieldName, item.ExternalId, item.ExternalSystemName, item.Priority, item.Owners, urlTitle, url, item.Environment, item.FoundBy, item.VersionAffected, item.BuildNumber, item.SeverityLevel); logger.Log(LogMessage.SeverityType.Info, string.Format("VersionOne asset {0} succesfully created.", newWorkitem.Id)); } catch (Exception ex) { logger.Log(LogMessage.SeverityType.Error, string.Format("Error during saving workitems: {0}", ex.Message)); failureMessage = string.Format("Faild to create item in versionOne, reason: \"{0}\"", ex.Message); } if(newWorkitem != null) { var result = new WorkitemCreationResult(item) { Source = { Number = newWorkitem.Number, ExternalId = item.ExternalId, Description = newWorkitem.Description, ExternalSystemName = item.ExternalSystemName, ProjectId = newWorkitem.Project.Key, Project = newWorkitem.Project.Value, Title = newWorkitem.Name, Priority = newWorkitem.PriorityToken, Environment = newWorkitem.Environment, }, WorkitemId = newWorkitem.Id, Permalink = v1Processor.GetWorkitemLink(newWorkitem), }; result.Messages.Add(string.Format("Created item \"{0}\" ({1}) in Project \"{2}\" URL: {3}", item.Title, result.Source.Number, item.Project, result.Permalink)); return result; } var failureResult = new WorkitemCreationFailureResult(item); failureResult.Messages.Add(failureMessage); failureResult.Warnings.Add(string.Format("[{0}] {1}", item.ExternalId, failureMessage)); return failureResult; }
public WorkitemCreationFailureResult(Workitem source ) { Source = source; }
public IssueCreatedResult(Workitem source) { Source = source; }
public string EditWorkitem(Workitem id) { try { using (var entities = new WorkBountyDBEntities()) { var getWorkitemData = entities.Workitems.Where(x => x.WorkitemID==id.WorkitemID).ToList(); getWorkitemData.ForEach(a => { if(id.Amount!=null) a.Amount = id.Amount; a.ModifyBy = id.ModifyBy; if (id.ModifyDateTime != null) a.ModifyDateTime = id.ModifyDateTime; a.PublishedTo = id.PublishedTo; if (id.Summary != null) a.Summary = id.Summary; if (id.Title != null) a.Title = id.Title; if (id.ProposedReward != "undefined") a.ProposedReward = id.ProposedReward; } ); WorkitemStatu workitemstatusData = new WorkitemStatu(); string statusDescription = "Update"; workitemstatusData.StatusDescription = statusDescription; workitemstatusData.WorkitemID = id.WorkitemID; entities.WorkitemStatus.Add(workitemstatusData); entities.SaveChanges(); WorkitemHistory workitemHistoryData = new WorkitemHistory(); workitemHistoryData.WorkitemID = id.WorkitemID; workitemHistoryData.UpdatedBy = id.ModifyBy; workitemHistoryData.UpdatedDateTIme = DateTime.Now; var getWorkitemStatusID = entities.WorkitemStatus.Where(s => s.WorkitemID == id.WorkitemID).Select(s => s.WorkitemStatusID).FirstOrDefault(); workitemHistoryData.WorkitemStatusID = getWorkitemStatusID; entities.WorkitemHistories.Add(workitemHistoryData); entities.SaveChanges(); } return "Success"; } catch (Exception) { return "Error"; } }