NUnit测试以及如何初始化DependencyManager.Resolve

时间:2017-01-13 09:26:21

标签: c# nunit

我需要在C#NUnit测试中的集成测试中启动以下代码。

如何初始化DependencyManager.Resolve方法?

非常感谢,

单元测试调用此方法

public static Account GetCustomer(string databaseName)
{
    Database db = DatabaseFactory.CreateDatabase(databaseName);

    using(DbCommand cmd = db...)
    {

    }
}

CreateDatabase方法

public static Database CreateDatabase(string name)
{
    IDbFactory factory = DependencyManager.Resolve<IDbFactory>();
    return factory.GetDatabase(name);
}

单元测试

[Test]
public void When_I_Call_GetCustomer_A_Customer_Is_Returned()
{
    var result = CustomerAccount.GetCustomer(..);
} 

更新

下面显示的DependencyManager实现

public class DependencyManager
{
    public static T Resolve<T>(string key = "", ParamDictionary parameters = null)
    {
        return Resolver.Resolve<T>(key, parameters);
    }
}


private static volatile IDependencyResolver resolver;
...

public static IDependencyResolver Resolver
{
    get { return DependencyManager.resolver; }
}

最终到达

public class CastleDependencyContainer : IDependencyBuilder, IDependencyResolver

0 个答案:

没有答案