public async Task <ModelGitHubIssue> EnsureGitHubIssueAsync(ModelBuild modelBuild, GitHubIssueKey issueKey, bool saveChanges) { var query = GetModelBuildQuery(modelBuild.GetBuildKey()) .SelectMany(x => x.ModelGitHubIssues) .Where(x => x.Number == issueKey.Number && x.Organization == issueKey.Organization && x.Repository == issueKey.Repository); var modelGitHubIssue = await query.SingleOrDefaultAsync().ConfigureAwait(false); if (modelGitHubIssue is object) { return(modelGitHubIssue); } modelGitHubIssue = new ModelGitHubIssue() { Organization = issueKey.Organization, Repository = issueKey.Repository, Number = issueKey.Number, ModelBuild = modelBuild, }; Context.ModelGitHubIssues.Add(modelGitHubIssue); if (saveChanges) { await Context.SaveChangesAsync().ConfigureAwait(false); } return(modelGitHubIssue); }
public async Task <ModelTestRun> EnsureTestRunAsync(ModelBuild modelBuild, int attempt, DotNetTestRun testRun, Dictionary <HelixInfo, HelixLogInfo> helixMap) { var modelTestRun = await FindModelTestRunAsync(modelBuild.GetBuildKey(), testRun.TestRun.Id).ConfigureAwait(false); if (modelTestRun is object) { return(modelTestRun); } var buildInfo = testRun.Build.GetBuildResultInfo(); modelTestRun = new ModelTestRun() { AzureOrganization = buildInfo.Organization, AzureProject = buildInfo.Project, ModelBuild = modelBuild, TestRunId = testRun.TestRun.Id, Name = testRun.TestRun.Name, Attempt = attempt, }; Context.ModelTestRuns.Add(modelTestRun); foreach (var dotnetTestCaseResult in testRun.TestCaseResults) { var testCaseResult = dotnetTestCaseResult.TestCaseResult; var testResult = new ModelTestResult() { TestFullName = testCaseResult.TestCaseTitle, Outcome = testCaseResult.Outcome, ModelTestRun = modelTestRun, ModelBuild = modelBuild, ErrorMessage = testCaseResult.ErrorMessage, IsSubResultContainer = testCaseResult.SubResults?.Length > 0, IsSubResult = false, }; AddHelixInfo(testResult); Context.ModelTestResults.Add(testResult); if (testCaseResult.SubResults is { } subResults) { foreach (var subResult in subResults) { var iterationTestResult = new ModelTestResult() { TestFullName = testCaseResult.TestCaseTitle, Outcome = subResult.Outcome, ModelTestRun = modelTestRun, ModelBuild = modelBuild, ErrorMessage = subResult.ErrorMessage, IsSubResultContainer = false, IsSubResult = true }; AddHelixInfo(iterationTestResult); Context.ModelTestResults.Add(iterationTestResult); } } void AddHelixInfo(ModelTestResult testResult) { if (dotnetTestCaseResult.HelixInfo is { } helixInfo&& helixMap.TryGetValue(helixInfo, out var helixLogInfo)) { testResult.IsHelixTestResult = true; testResult.HelixConsoleUri = helixLogInfo.ConsoleUri; testResult.HelixCoreDumpUri = helixLogInfo.CoreDumpUri; testResult.HelixRunClientUri = helixLogInfo.RunClientUri; testResult.HelixTestResultsUri = helixLogInfo.TestResultsUri; } } } await Context.SaveChangesAsync().ConfigureAwait(false); return(modelTestRun); }