/// <summary> /// Updates an existing bug (partial updates are supported, i.e. you can submit and update specific fields only). /// </summary> /// <param name="testCase">Rhino.Api.Contracts.AutomationProvider.RhinoTestCase by which to update automation provider bug.</param> public string OnUpdateBug(RhinoTestCase testCase, string status, string resolution) { // get existing bugs var isBugs = testCase.Context.ContainsKey("bugs") && testCase.Context["bugs"] != default; var bugs = isBugs ? (IEnumerable <string>)testCase.Context["bugs"] : Array.Empty <string>(); // exit conditions if (bugs.All(i => string.IsNullOrEmpty(i))) { return("-1"); } // possible duplicates if (bugs.Count() > 1) { var issues = client.Get(idsOrKeys: bugs).Where(i => testCase.IsBugMatch(bug: i, assertDataSource: true)); var onBugs = issues .OrderBy(i => $"{i["key"]}") .Skip(1) .Select(i => $"{i.SelectToken("key")}") .Where(i => !string.IsNullOrEmpty(i)); var labels = new[] { "Duplicate" }; DoCloseBugs(testCase, status, resolution: !string.IsNullOrEmpty(resolution) ? "Duplicate" : string.Empty, labels, bugs: onBugs); } // update bugs = client .Get(idsOrKeys: bugs) .Select(i => i.AsJObject()) .Where(i => testCase.IsBugMatch(bug: i, assertDataSource: false)) .Select(i => $"{i.SelectToken("key")}") .Where(i => !string.IsNullOrEmpty(i)); testCase.UpdateBug(idOrKey: bugs.FirstOrDefault(), client); // get return($"{Utilities.GetUrl(client.Authentication.Collection)}/browse/{bugs.FirstOrDefault()}"); }
private IEnumerable <RhinoTestCase> GetByPlan(string issueKey) { // parse into JToken var jsonObject = jiraClient.Get(issueKey).AsJObject(); if (jsonObject == default) { return(Array.Empty <RhinoTestCase>()); } // find & validate test cases var customField = jiraClient.GetCustomField(TestPlanSchema); var onTestCases = jsonObject.SelectToken($"..{customField}"); Logger?.DebugFormat($"Get-Tests -By [{AtlassianCapabilities.PlanType}] = {onTestCases.Count()}"); // iterate & load tests var testCases = new List <RhinoTestCase>(); foreach (var onTestCase in onTestCases) { testCases.AddRange(GetOne($"{onTestCase}")); } return(testCases); }
/// <summary> /// Creates a new test case under the specified automation provider. /// </summary> /// <param name="testCase">Rhino.Api.Contracts.AutomationProvider.RhinoTestCase by which to create automation provider test case.</param> /// <returns>The ID of the newly created entity.</returns> public override string CreateTestCase(RhinoTestCase testCase) { // constants: logging const string M = "Create-Test -Project [{0}] -Set [{1}] = true"; // create jira issue var issue = CreateTestOnJira(testCase); // apply to context testCase.Key = $"{issue["key"]}"; testCase.Context["jira-issue-id"] = issue == default ? string.Empty : $"{issue["id"]}"; // create test steps CreateTestSteps(testCase); // create & apply preconditions var precondition = CreatePrecondition(testCase.Key, testCase.DataSource); if (precondition != null) { xpandClient.AddPrecondition($"{precondition.SelectToken("id")}", testCase.Key); } // add to test sets var testSets = jiraClient .Get(idsOrKeys: testCase.TestSuites) .Select(i => (id: $"{i.SelectToken("id")}", key: $"{i.SelectToken("key")}")); Parallel.ForEach(testSets, options, testSet => xpandClient.AddTestsToSet(idAndKey: testSet, new[] { $"{issue.SelectToken("id")}" })); // comment var comment = Utilities.GetActionSignature(action: "created"); jiraClient.AddComment(idOrKey: issue["key"].ToString(), comment); // success Logger?.InfoFormat(M, Configuration.ConnectorConfiguration.Project, string.Join(", ", testCase?.TestSuites)); // results return($"{issue}"); }
/// <summary> /// Gets a collection of test cases issues from test execution. /// </summary> /// <param name="idsOrKeys">A collection of ID or key of the issue.</param> /// <returns>A collection of test cases.</returns> public IEnumerable <JToken> GetTestsByExecution(IEnumerable <string> idsOrKeys) { // setup var testCases = new ConcurrentBag <string>(); // get Parallel.ForEach(idsOrKeys, options, idOrKey => { var execution = jiraClient.Get(idOrKey).AsJObject(); var id = $"{execution.SelectToken("id")}"; var key = $"{execution.SelectToken("key")}"; var runs = XpandCommandsRepository .GetRunsByExecution((id, key)) .Send(executor) .AsJToken() .Select(i => i.AsJObject()); var range = runs.Select(i => $"{i.SelectToken("testIssueId")}"); testCases.AddRange(range); });
/// <summary> /// Updates a bug based on this RhinoTestCase. /// </summary> /// <param name="testCase">RhinoTestCase by which to update a bug.</param> /// <returns><see cref="true"/> if successful, <see cref="false"/> if not.</returns> public static bool UpdateBug(this RhinoTestCase testCase, string idOrKey, JiraClient jiraClient) { // setup var bugType = testCase.GetCapability(capability: AtlassianCapabilities.BugType, defaultValue: "Bug"); var onBug = jiraClient.Get(idOrKey).AsJObject(); // setup conditions var isDefault = onBug == default; var isBug = !isDefault && $"{onBug.SelectToken("fields.issuetype.name")}".Equals(bugType, Compare); // exit conditions if (!isBug) { return(false); } // update body var requestBody = GetUpdateBugPayload(testCase, onBug, jiraClient); var isUpdate = jiraClient.UpdateIssue(idOrKey, requestBody); if (!isUpdate) { return(isUpdate); } // delete all attachments jiraClient.DeleteAttachments(idOrKey: $"{onBug["key"]}"); // upload new attachments var files = testCase.GetScreenshots(); jiraClient.AddAttachments($"{onBug["key"]}", files.ToArray()); // results return(isUpdate); }