Search code examples
.netasp.net-mvctddmbunit

Is there any good way to run one set of tests with two different AssemblyStartups


I'm working on a pretty standed ASP.NET MVC application. We've got the core logic behind a set of services and we're using StructureMap to inject appropriate instances of appropriate IRepositories to abstract communications with the data layer proper. We've also got a rather exhaustive series of unit tests on these services. But, as things stand now, the unit tests talk to a set of fake repositories using in-memory object graphs to represent the database.

What I would like to do is find a good way to use the same set of tests backed by the database and our Linq2Sql repositories. Now, I can see a pretty ghetto way of accomplishing this using #if() compiler directives and some flags, but I'd suspect that there is a better way to get there. Any suggestions?

EDIT:

James answered the original question, but he also made me realize I wasn't quite clear about what my goals here are.

What I'd like to do is have this appear, at least to the test runner (currently Gallio) as two separate assemblies. Main reason is so I can run the unit tests and the integration tests separately and avoid complete DB dependence.


Solution

  • Sure, just add parameters to the AssemblyFixture.

    [AssemblyFixture] public class AssemblyStartup { [Row("in-memory-database-connection-string")] [Row("real-database-connection-string")] public string ConnectionString;

    [FixtureSetUp]
    public void SetUp()
    {
        ... set up my repositories using ConnectionString above...
    }
    

    }

    What will happen is that all of the fixtures and the assembly fixture Setup() will be run twice using different values of ConnectionString each time.