/// <summary>
        /// Performed just after each test is called.
        /// </summary>
        /// <param name="testCase">The Rhino.Api.Contracts.AutomationProvider.RhinoTestCase which was executed.</param>
        public override RhinoTestCase OnPostTestExecute(RhinoTestCase testCase)
        {
            // constants
            const string Updated = "runUpdated";

            // setup
            var outcome     = testCase.Actual ? "PASSED" : "FAILED";
            var alreadyFail = ProviderManager
                              .TestRun
                              .TestCases
                              .Any(i => i.Key == testCase.Key && !i.Actual && i.Context.ContainsKey(Updated) && (bool)i.Context[Updated]);

            // failed on this run (mark as fail)
            if (alreadyFail)
            {
                outcome = "FAILED";
            }

            // inconclusive on this run (mark as default)
            if (ProviderManager.TestRun.TestCases.Any(i => i.Key.Equals(testCase.Key) && i.Inconclusive))
            {
                outcome = testCase.GetCapability(AtlassianCapabilities.InconclusiveStatus, "TODO");
            }

            // put
            testCase.Context["outcome"] = outcome;

            // update
            ProviderManager.UpdateTestResult(testCase);

            // return with results
            return(testCase);
        }
        /// <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)
        {
            // shortcuts
            var onProject = Configuration.ConnectorConfiguration.Project;

            testCase.Context[ContextEntry.Configuration] = Configuration;
            var testType = $"{testCase.GetCapability(AtlassianCapabilities.TestType, "Test")}";

            // setup context
            testCase.Context["issuetype-id"]                   = $"{jiraClient.GetIssueTypeFields(idOrKey: testType, path: "id")}";
            testCase.Context["project-key"]                    = onProject;
            testCase.Context["test-sets-custom-field"]         = jiraClient.GetCustomField(schema: TestSetSchema);
            testCase.Context["manual-test-steps-custom-field"] = jiraClient.GetCustomField(schema: ManualTestStepSchema);
            testCase.Context["test-plan-custom-field"]         = jiraClient.GetCustomField(schema: AssociatedPlanSchema);

            // setup request body
            var requestBody = testCase.ToJiraXrayIssue();
            var issue       = jiraClient.Create(requestBody);

            // comment
            var comment = Utilities.GetActionSignature(action: "created");

            jiraClient.AddComment(idOrKey: $"{issue.SelectToken("key")}", comment);

            // success
            Logger?.InfoFormat($"Create-Test -Project [{onProject}] -Set [{string.Join(",", testCase?.TestSuites)}] = true");

            // results
            return($"{issue}");
        }
Пример #3
0
        private IEnumerable <JToken> DoGetBugs(RhinoTestCase testCase)
        {
            // shortcuts
            var          bugType    = testCase.GetCapability(AtlassianCapabilities.BugType, "Bug");
            const string typePath   = "fields.issuetype.name";
            const string statusPath = "fields.status.name";

            // get test issue
            var test = client.Get(testCase.Key).AsJObject();

            // get bugs
            var bugsKeys = test
                           .SelectTokens("..inwardIssue")
                           .Where(i => $"{i.SelectToken(typePath)}"?.Equals(bugType) == true && $"{i.SelectToken(statusPath)}"?.Equals("Closed") != true)
                           .Select(i => $"{i["key"]}")
                           .ToArray();

            // add to context
            testCase.Context["bugs"] = bugsKeys;

            // get issues
            var bugs = client.Get(bugsKeys);

            testCase.Context["bugsData"] = bugs;

            // get
            return(bugs);
        }
        /// <summary>
        /// Converts connector test case interface into a test management test case.
        /// </summary>
        /// <param name="testCase">Test case to convert</param>
        /// <returns>Test management test case</returns>
        public static string ToJiraXrayIssue(this RhinoTestCase testCase)
        {
            // exit conditions
            ValidationXray(testCase);

            // field: steps > description
            var steps       = GetSteps(testCase);
            var description = testCase.Context.ContainsKey("description")
                ? testCase.Context["description"]
                : string.Empty;

            // compose json
            var payload = new Dictionary <string, object>
            {
                ["summary"]     = testCase.Scenario,
                ["description"] = description,
                ["issuetype"]   = new Dictionary <string, object>
                {
                    ["id"] = $"{testCase.Context["issuetype-id"]}"
                },
                ["project"] = new Dictionary <string, object>
                {
                    ["key"] = $"{testCase.Context["project-key"]}"
                },
                [$"{testCase.Context["manual-test-steps-custom-field"]}"] = new Dictionary <string, object>
                {
                    ["steps"] = steps
                }
            };

            // test suite
            if (testCase.TestSuites.Any())
            {
                payload[$"{testCase.Context["test-sets-custom-field"]}"] = testCase.TestSuites;
            }

            // test plan
            var testPlans  = testCase.GetCapability(capability: AtlassianCapabilities.TestPlans, defaultValue: Array.Empty <string>());
            var isTestPlan = testPlans.Length != 0 && testCase.Context.ContainsKey("test-plan-custom-field");

            if (isTestPlan)
            {
                payload[$"{testCase.Context["test-plan-custom-field"]}"] = testPlans;
            }
            return(JsonConvert.SerializeObject(new Dictionary <string, object>
            {
                ["fields"] = payload
            }));
        }
Пример #5
0
        /// <summary>
        /// Performed just after each test is called.
        /// </summary>
        /// <param name="testCase">The Rhino.Api.Contracts.AutomationProvider.RhinoTestCase which was executed.</param>
        public override RhinoTestCase OnPostTestExecute(RhinoTestCase testCase)
        {
            // setup
            var outcome = testCase.Actual ? "PASS" : "FAIL";

            if (testCase.Inconclusive)
            {
                outcome = testCase.GetCapability(AtlassianCapabilities.InconclusiveStatus, "ABORTED");
            }

            // put
            testCase.Context["outcome"] = outcome;

            // update
            ProviderManager.UpdateTestResult(testCase);

            // return with results
            return(testCase);
        }
Пример #6
0
        /// <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);
        }