问题
In MBUnit v2 I did this:
public class ConnectionStringFactory
{
[Factory]
public string ConnectionString
{
get
{
return ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString;
}
}
}
[ProviderFactory(typeof(ConnectionStringFactory),typeof(string))]
public class CustomerTests
{
public void GetCustomerTest(string connectionString)
{
}
public void GetCustomersTest(string connectionString)
{
}
}
I had to create ONE Factory class returning me a connectionString which gets injected into each test method of a unit test class.
How can this be done with MBUnit v3 where the ProviderFactory is gone?
I played a lot with the Factory class, but the result is not what I want.
I want to a Connection string factory used by all test classes where the connection string
is injected into each test method automatically.
回答1:
How about this?
public static class ConnectionStringFactory
{
public static IEnumerable<string> GetConnectionString()
{
yield return "connString";
}
}
[Factory(typeof(ConnectionStringFactory), "GetConnectionString")]
public class CustomerTests
{
[Test]
public void GetCustomerTest(string connectionString)
{
Console.WriteLine(connectionString);
}
[Test]
public void GetCustomersTest(string connectionString)
{
Console.WriteLine(connectionString);
}
}
来源:https://stackoverflow.com/questions/9348536/migration-from-mbunit-v2-to-v3-and-the-providerfactory-is-gone