public Task StartTestRunAsync(TestRailRunInfo runInfo) => _client.StartTestRunAsync(runInfo, () => { var invalidStatuses = new[] { _config.StatusMapping.Passed, _config.StatusMapping.Failed, _config.StatusMapping.Skipped, _config.StatusMapping.Inconclusive, _config.StatusMapping.Warning, _config.StatusMapping.WithDefect, _config.StatusMapping.FilteringResidue, }.Where(s => !_client.Statuses.Keys.Contains(s)); if (invalidStatuses.Count() > 0) { throw new Exception("Invalid TestRail statuses were specified in NUnitTestRailClient's status mapping: " + invalidStatuses.Aggregate((a, b) => $"{a}, {b}")); } });
public async Task StartTestRunAsync(TestRailRunInfo runInfo, Action validate = null) { if (_config.Disabled) { return; } if (CurrentRun != null) { throw new TestRailClientException($"There's already a test run in progress. " + "Please end it before starting another. Or, initialize and use another client instance."); } var cases = await _apiClient.GetCasesAsync(runInfo.ProjectId, runInfo.SuiteId); if (!_apiClient.Cases.Any()) { throw new TestRailClientException( $"There's no test case in suite {runInfo.SuiteId} of project {runInfo.ProjectId}."); } _config.CaseFilters.ForEach(f => f.Validate(_apiClient)); validate?.Invoke(); if (runInfo.CaseIds != null && runInfo.CaseIds.Length > 0) { throw new TestRailClientException($"Provided TestRailRunInfo filters out all the test cases. " + "Make sure to have one or more case IDs in it." + "If you want to include all the cases, set null to CaseIds property."); } var filtering = cases.Select(c => new FilteringResult { Case = c, isIncluded = runInfo.CaseIds?.Any(i => i == c.Id) ?? true, isFiltered = true, }); foreach (var filter in _config.CaseFilters) { filtering = filtering.Select(f => { if (f.isFiltered && !filter.Filter(f.Case, _apiClient)) { f.isFiltered = false; f.isIncluded = filter.Strategy switch { ResidueCaseStrategy.ExcludeFromRun => false, ResidueCaseStrategy.IncludeToRun => f.isIncluded, _ => throw new NotImplementedException(), }; } return(f); }); } IncludedCases = filtering.Where(f => f.isIncluded) .Select(f => f.Case).ToList().AsReadOnly(); FilteredCases = filtering.Where(f => f.isFiltered) .Select(f => f.Case).ToList().AsReadOnly(); runInfo.CaseIds = IncludedCases.Select(c => c.Id).ToArray(); CurrentRun = await _apiClient.AddRunAsync(runInfo); }