Example #1
0
        /// <summary>
        /// Close all existing bugs.
        /// </summary>
        /// <param name="testCase">Rhino.Api.Contracts.AutomationProvider.RhinoTestCase by which to close automation provider bugs.</param>
        public string OnCloseBug(RhinoTestCase testCase, string status, string resolution)
        {
            // get existing bugs
            var isBugs      = testCase.Context.ContainsKey("bugs") && testCase.Context["bugs"] != default;
            var contextBugs = isBugs ? (IEnumerable <string>)testCase.Context["bugs"] : Array.Empty <string>();
            var bugs        = client
                              .Get(idsOrKeys: contextBugs)
                              .Where(i => testCase.IsBugMatch(bug: i, assertDataSource: false));

            // get conditions (double check for bugs)
            if (!bugs.Any())
            {
                return(string.Empty);
            }

            // close bugs: first
            var onBug = $"{bugs.FirstOrDefault()?.SelectToken("key")}";

            testCase.CloseBug(bugIssueKey: onBug, status, resolution, client);

            // close bugs: duplicate (if any)
            foreach (var bug in bugs.Skip(1))
            {
                var labels = new[] { "Duplicate" };
                testCase.CloseBug(
                    $"{bug.SelectToken("key")}",
                    status,
                    resolution: !string.IsNullOrEmpty(resolution) ? "Duplicate" : string.Empty,
                    labels,
                    client);
            }
            return(onBug);
        }
Example #2
0
        private IEnumerable <string> DoCloseBugs(RhinoTestCase testCase, string status, string resolution, IEnumerable <string> labels, IEnumerable <string> bugs)
        {
            // close bugs
            var closedBugs = new List <string>();

            foreach (var bug in bugs)
            {
                var isClosed = testCase.CloseBug(bugIssueKey: bug, status, resolution, labels, client);

                // logs
                if (isClosed)
                {
                    closedBugs.Add($"{Utilities.GetUrl(client.Authentication.Collection)}/browse/{bug}");
                    continue;
                }
                logger?.Info($"Close-Bug -Bug [{bug}] -Test [{testCase.Key}] = false");
            }

            // context
            if (!testCase.Context.ContainsKey(ContextEntry.BugClosed) || !(testCase.Context[ContextEntry.BugClosed] is IEnumerable <string>))
            {
                testCase.Context[ContextEntry.BugClosed] = new List <string>();
            }
            var onBugsClosed = (testCase.Context[ContextEntry.BugClosed] as IEnumerable <string>).ToList();

            onBugsClosed.AddRange(closedBugs);
            testCase.Context[ContextEntry.BugClosed] = onBugsClosed;

            // get
            return(onBugsClosed);
        }