Test Case Data

Igal Tabachnik edited this page Jun 4, 2013 · 6 revisions

Agent Mulder plugin works by analyzing container registrations using ReSharper's Structural Search mechanism, allowing specifying patterns and placeholders. From those patterns, Agent Mulder "guesses" the best it can what is happening in the container, and which types are affected by the registration. This assumption is verified by a test case, which makes sure Agent Mulder resolves types correctly.

Under the directory src\Test\Data, you'll find a solution called TestApplication.sln. This project contains the test data, that is picked up and verified during running of Agent Mulder's test fixture. Here's an example of one such test case, from StructureMap:

// Patterns: 1
// Matches: Foo.cs
// NotMatches: Bar.cs 

using StructureMap;
using TestApplication.Types;

namespace TestApplication.StructureMap.ContainerTests
    public class ForGenericUseGenericExpression
        public ForGenericUseGenericExpression()
            var container = new Container(x => x.For<IFoo>().Use<Foo>());

At the top of the file there are comments, which are processed by Agent Mulder's test fixture, and the results are asserted against the values in the comments. In this case, the match against this code should yield exactly 1 pattern, and it's specified by // Patterns: 1.

In case a registration does not produce any patterns (in case of incomplete registration, or otherwise for sanity), this is specified by // Patterns: 0, and the rest of the comments below are not processed.

In some cases, a single registration may produce multiple pattern matches, (for example, Unity is able to chain calls to register methods, so several patterns may be produced. See this test case for example), and the number of expected patterns is specified by // Patterns: 3.

The next comment, // Matches: File1.cs,File2.cs, is a comma-separated (if applicable) list of files, that contain the types the registration should match. In the example above, only the type Foo, located in the file Foo.cs should be matched by the registration.

The last comment, // NotMatches: File1.cs,File2.cs is a mere sanity, to make sure certain types are not matched by the registration. Again, in the example above, the type Bar in file Bar.cs should not be matched by Agent Mulder.

The test cases should each be placed in a separate file, each file covering only one particular case. Those files are automatically scanned and added to the test fixture.

For more examples, see other test data files.