After an insane amount of experimenting and beating my head against the wall, I've found the answer.
For those who are curious, here's how it works:
If I create the test run using
ITestManagementService.TestRuns.Create();
I can add Test Cases but not Test Points.If I create the test run using
ITestPlan.CreateTestRun(isAutomated);
I can add Test Points but not Test Cases.
I overcomplicated things a lot trying to get this working - I've now cleaned up a lot of the mess and have my application correctly reporting test results to TFS.
I'm using a fake build more or less as described by Jason Prickett's blog.
One thing I did find was that I couldn't define the run as an automated run because I have no test run controllers in my environment and couldn't find a way to move the test run state from WaitingForController to Completed.
There's more cleanup to go but the core works this way:
this.Run = this.Plan.CreateTestRun(false);
ConfigureTestRun(build);
this.Result = CreateRunResults();
this.Iteration = CreateSingleIteration(suiteRun.Description);
// custom processing omitted for brevity
this.Result.Iterations.Add(this.Iteration);
// Attach the run log to the results
ITestAttachment item = this.Iteration.CreateAttachment(ConfigurationManager.AppSettings["LogFile"], SourceFileAction.None);
this.Result.State = TestResultState.Completed;
this.Result.Save();
this.Run.Attachments.Add(item);
this.Run.Save();
And the test run configuration routine is:
private void ConfigureTestRun(IBuildDetail build)
{
this.Run.DateStarted = DateTime.Now;
this.Run.DateCompleted = DateTime.Now;
this.Run.BuildDirectory = build.DropLocation;
this.Run.BuildFlavor = "debug";
this.Run.BuildNumber = build.BuildNumber;
this.Run.BuildPlatform = "test platform";
this.Run.BuildUri = build.Uri;
this.Run.Controller = build.BuildController.Name;
// find the points that correspond to test cases in the run suite
foreach (ITestPoint point in this.Points)
{
if (point.TestCaseExists && point.Plan.Id == this.Plan.Id && point.ConfigurationId == this.Config.Id)
{
this.Run.AddTestPoint(point, this.CurrentUser);
}
}
this.Run.Save();
}