我大致遵循excellent series of blog posts by Kazi Manzur Rashid作为学习练习来学习如何实现一些新的(至少对我而言)设计模式,但是我从一开始就遇到了麻烦。ArgumentException创建从ObjectContext继承的对象的实例
我基本上复制了他对Database
,RepositoryBase
和RepositoryBaseTests
类的代码,但是当我尝试运行测试,我得到一个错误信息说
Unable to create instance of class Booking.Infrastructure.EntityFramework.Repositories.Tests.RepositoryBaseTests. Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0..
通过调试我已经验证抛出异常的构造函数Database
类,它看起来像这样:
public Database(
IConfigurationManager configurationManager,
string connectionstringName)
: base(
GetConnectionString(configurationManager, connectionstringName),
"BookingEntities")
{ // Nothing happens here }
调用base
构造函数时,引发错误,并且如果我硬-code我目前发送的值,它是这样的:
: base("Dummy connStr", "BookingEntities")
为什么不这项工作?
确定。那么,我可以弄清楚连接字符串不是一个有效的字符串,但是我认为它应该能够正常工作,就像它在文章中的例子一样。无论如何,我还没有建立数据库,所以我没有真正的连接字符串。是否有任何(简单)的方法来建立一个虚拟字符串,它具有所有必要的部分,但实际上不会做任何事情? – 2009-09-18 22:16:25
只需使用Northwind.mdb或其他演示数据库。 – 2009-09-19 00:18:31
问题是我正在做这个单元测试我的仓库 - 我根本不想连接到数据库,只是看到仓库从'Database'对象中获得正确的东西。 – 2009-09-19 09:37:48