使用 Unity 作为 IoC 时,包含具体 类 的项目不会复制到 TestResult 目录
Project containing concrete classes is not copied to TestResult directory when using Unity as IoC
我有一个解决方案,其中有几个项目根据 DDD 原则划分。集成测试之一想要测试服务方法之一。该方法依赖于 ICustomerRepository。
CustomerRepository 在 CustomerDomain.Infrastructure 程序集中定义,具体的 ICustomerRepository 在 CustomerDomain.Model 程序集中定义。
依赖由统一配置文件管理。映射是正确的,它指出了正确的 assemblies/namespaces 和 类。 unity配置文件被正确复制到testresult文件夹中。但是,当测试运行时,它会失败并出现异常:"The type initializer for 'UnityContainerManager' threw an exception." 包含内部异常:
“{"The type name or alias CustomerRepository could not be resolved. Please check your configuration file and verify this type name."}”
经过一些调查,我发现 CustomerDomain.Model.dll 永远不会复制到 testResult 目录,即使 属性 复制本地设置为 True。
如果我在 TestInitialize 方法中创建 CustomerRepository 的实例,一切正常 - 程序集被复制并且测试通过。但这个解决方法对我来说似乎是正确的 - 有没有更好的选择?
Visual Studio 仅复制那些至少使用了一种类型的引用程序集。
如果您不想创建真实的 CustomerRepository
,请在引用的程序集中定义一个虚拟类型 CopyEnforcer
并在引用的程序集中创建该虚拟类型的实例。
我有一个解决方案,其中有几个项目根据 DDD 原则划分。集成测试之一想要测试服务方法之一。该方法依赖于 ICustomerRepository。 CustomerRepository 在 CustomerDomain.Infrastructure 程序集中定义,具体的 ICustomerRepository 在 CustomerDomain.Model 程序集中定义。
依赖由统一配置文件管理。映射是正确的,它指出了正确的 assemblies/namespaces 和 类。 unity配置文件被正确复制到testresult文件夹中。但是,当测试运行时,它会失败并出现异常:"The type initializer for 'UnityContainerManager' threw an exception." 包含内部异常: “{"The type name or alias CustomerRepository could not be resolved. Please check your configuration file and verify this type name."}”
经过一些调查,我发现 CustomerDomain.Model.dll 永远不会复制到 testResult 目录,即使 属性 复制本地设置为 True。
如果我在 TestInitialize 方法中创建 CustomerRepository 的实例,一切正常 - 程序集被复制并且测试通过。但这个解决方法对我来说似乎是正确的 - 有没有更好的选择?
Visual Studio 仅复制那些至少使用了一种类型的引用程序集。
如果您不想创建真实的 CustomerRepository
,请在引用的程序集中定义一个虚拟类型 CopyEnforcer
并在引用的程序集中创建该虚拟类型的实例。