Migration from MBUnit v2 to v3 and the ProviderFactory is gone

醉酒当歌 提交于 2020-01-07 02:25:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!