使用起订量嘲笑构造? [英] Use Moq to mock Constructor?
本文介绍了使用起订量嘲笑构造?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样一组构造:
public BusinessObjectContext() :
this(CloudStorageAccount.FromConfigurationSetting("DataConnectionString").TableEndpoint.ToString(),
CloudStorageAccount.FromConfigurationSetting("DataConnectionString").Credentials) {}
public BusinessObjectContext(string dataConnectionString) :
this(CloudStorageAccount.Parse(dataConnectionString).TableEndpoint.ToString(),
CloudStorageAccount.Parse(dataConnectionString).Credentials) { }
public BusinessObjectContext(String baseAddress, StorageCredentials credentials) : base(baseAddress, credentials) { }
不过测试/惩戒我所需要的对象没有任何连接字符串参数时。我怎样才能做到这一点 - preferrably的起订量
However when testing / Mocking I need the object without any of the connection string parameters. How can I do this - preferrably in Moq?
这是可能的吗?
推荐答案
听起来好像你有一个code气味 - 的的的构造做太多的工作。文章包括一组修复这样的场景。基本上,答案是的只有的构造函数中执行任务,而不是执行业务逻辑。
It sounds as if you have a code smell - the constructor is doing too much work. The article includes a set of fixes for such scenarios. Basically the answer is to only perform assignment in constructors, not execute business logic.
这篇关于使用起订量嘲笑构造?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文