Where did UnitTestResult.Exceptions go?

In ReSharper 7 I was able to get a list of TaskExceptions from the UnitTestResult, in ReSharper 8 this property is gone. It looks like it was refactored out (or maybe was always in) UnitTestResultData but I don't know how to get a UnitTestResultData object from anything I have.

For some context I'm in an ActionHandler from a context menu off a UnitTestSession:

   var unitTestSessionView = context.GetData(TreeModelBrowser.TREE_MODEL_DESCRIPTOR) as UnitTestSessionView;
   var unitTestSessionNodes = context.GetData(TreeModelBrowser.TREE_MODEL_NODES);
   var result = unitTestSessionView.GetModelResult(unitTestSessionNodes[0]);


How do I get the UnitTestResultData? There is also result.Message but it seems to always be an empty string, even for tests that fail.

3 comments
Comment actions Permalink

You can get at the UnitTestResultData via IUnitTestResultsManager.GetResultData(IUnitTestElement). You can get at the IUnitTestElement via IUnitTestSession.Elements, or, if you're implementing a context action, you can derive from UnitTestContextActionBase or UnitTestExplorerContextBaseAction, which can get the elements from the tree browser using context.GetData(UnitTestDataConstants.UNIT_TEST_ELEMENTS)

Hope this helps
Matt

0
Comment actions Permalink

Thanks, that helped a bunch!

If anyone else finds this and needs help later, I am now doing this:

    var solution = context.GetData(DataConstants.SOLUTION);
    var unitTestElements = context.GetData(UnitTestDataConstants.UNIT_TEST_ELEMENTS);
    var unitTestResultManager = new UnitTestResultManager(solution.GetLifetime(), solution.GetComponent<IPersistentIndexManager>());


I then loop over the unitTestElements and use unitTestResultManager.GetResultData as Matt had suggested.

One more question, is that the way I should be getting the UnitTestResultManager?

0
Comment actions Permalink

No, the UnitTestResultManager is marked with the [SolutionComponent] attribute, which means the Component Model (ReSharper's IoC container that manages lifetime and dependencies) will create an instance of this, scoped to the lilfetime of the current solution. If you're writing your own component (e.g. [SolutionComponent] or [ShellComponent] marked classes), then you can simply add UnitTestResultManager as a constructor argument. Context actions aren't created by the Component Model, so can't take part in the very useful dependency injection. Instead, you have to use the Service Locator style pattern of solution.GetComponent<UnitTestResultManager>(). The rule of thumb with ReSharper is that most classes are available through the Component Model, and you should try and get them through dependency injection, where supported. You can find out more about the Component Model here: http://confluence.jetbrains.com/display/NETCOM/2.02+Component+Model+%28R8%29

0

Please sign in to leave a comment.