为什么我的 WCF RIA 上下文在单元测试期间抛出 FileNotFound 异常?
我正在尝试编写涉及 WCF RIA 实体代理的单元测试,当我尝试通过关联访问实体的父级或子级属性时,当 WebContext 类无法加载 时,我会收到
。FileNotFoundException
System.Xml
例如,我在实体框架的 Web 项目中定义了两个实体 - Course
和 CourseUnit
。 Course
有许多 CourseUnit
子级。我不会向我的 ViewModel 公开任何 RIA 上下文或任何内容,它们都隐藏在界面后面。我使用 Moq 来模拟这些接口并将标准 RIA 实体代理返回到我的单元测试。
当我测试诸如
Assert.AreEqual("title", course.Title)
之类的东西时,这工作得很好,其中 course
是 RIA 代理的实例。但是,如果我执行类似
Assert.AreEqual(0, course.CourseUnits.Count)
的
操作,则会出现以下异常
FileNotFoundException 未处理 用户代码无法加载文件或 程序集'System.Xml,版本=2.0.5.0, 文化=中立, PublicKeyToken=7cec85d7bea7798e' 或 它的依赖项之一。系统 找不到指定的文件。
同样,如果我在涉及这些关系之一的单元测试中执行任何代码,那么该代码会引发相同的异常。基本上,如果我尝试通过测试中的关联关系访问这些属性,它们就会破坏。
异常实际上发生在生成的代码中。它可以在分部类 Course : Entity
的文件 [webProjectName].g.cs
中找到,并发生在 CourseUnits getter 中。
有什么想法吗?
编辑 - 我添加了对 EntityFramework 程序集的引用,异常已更改为相同的内容,但 System.ComponentModel.DataAnnotations 而不是 System.Xml。不用说,我已经尝试在单元测试项目中引用这两个程序集,但它不起作用。
I'm trying to write unit tests involving my WCF RIA entity proxies and when I try to access an entity's parent or child properties through an association I get a FileNotFoundException
when the WebContext class fails to load System.Xml
.
For example, I have two entities defined in my web project in Entity Framework - Course
and CourseUnit
. A Course
has many CourseUnit
children. I'm not exposing any RIA contexts or anything to my ViewModels, they are all hidden behind interfaces. I'm using Moq to mock these interfaces and return the standard RIA entity proxies to my unit tests.
This works fine when I'm testing things like
Assert.AreEqual("title", course.Title)
where course
is an instance of the RIA proxy. However, if I do something like
Assert.AreEqual(0, course.CourseUnits.Count)
I get the following exception
FileNotFoundException was unhandled by
user code Could not load file or
assembly 'System.Xml, Version=2.0.5.0,
Culture=neutral,
PublicKeyToken=7cec85d7bea7798e' or
one of its dependencies. The system
cannot find the file specified.
And similarly if I execute any code in a unit test that involved one of these relationships then the code throws the same exception. Basically if I ever try to access these properties with association relationships from my tests they break.
The exception actually occurs in generated code. It an be found in the file [webProjectName].g.cs
in the partial class Course : Entity
and happens in the CourseUnits getter.
Any ideas?
Edit - I added a reference to the EntityFramework assembly and the exception has changed to the same thing but System.ComponentModel.DataAnnotations instead of System.Xml. Needless to say I have tried referencing both assemblies in the unit test project, and it didn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论