Baz*_*Baz 9 c# unit-testing shim
我正在学习在单元测试中使用垫片.我正在尝试使用DateTime的经典示例,来自以下链接:http: //www.wiliam.com.au/wiliam-blog/getting-started-with-microsoft-fakes
我可以在单元测试项目中为系统引用添加Fakes,但是当我尝试使用System.Fakes.ShimDateTime时,它告诉我:
The type or namespace name 'ShimDateTime' does not exist in the namespace 'System.Fakes' (are you missing an assembly reference?)
Run Code Online (Sandbox Code Playgroud)
如果我检查System.Fakes下可用的内容,我只看到存根和没有垫片,所以我似乎缺少一些产生垫片的东西?
不确定它是否相关,但这是System.fakes文件中的(默认)内容:
<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
<Assembly Name="System" Version="4.0.0.0"/>
</Fakes>
Run Code Online (Sandbox Code Playgroud)
我正在使用Visual Studio 2015. VS2015 14.0.25420.01 Update 3,我的项目在.NET Framework 4.5.2中运行
实际上我的项目在添加System的假货之后无法正确编译,因此甚至没有尝试使用ShimDateTime.我得到的编译错误是:
The type or namespace name 'EventSourceCreatedEventArgs' does not exist in the namespace 'System.Diagnostics.Tracing' (are you missing an assembly reference?)
Run Code Online (Sandbox Code Playgroud)
这来自\ UnitTestProject1\obj\Debug\Fakes\m\f.csproj和文件f.cs在线:[mqttf :: Microsoft.QualityTools.Testing.Fakes.Stubs.StubClass(typeof(global :: Syst) em.Diagnostics.Traci ng.EventSourceCreate dEventArgs))]
谁能让我走上正确的轨道,在System.Fakes下获得ShimDateTime?
我能够在Visual Studio 2015 Update 3上为.NET 4.5.2项目解决此问题:
error CS0234: The type or namespace name 'ShimDateTime' does not exist in the namespace 'System.Fakes' (are you missing an assembly reference?)
Run Code Online (Sandbox Code Playgroud)
修复方法是将条目实际添加到mscorlib.fakesXML文件中(而不是您可能认为的那样System.fakes)
<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/" Diagnostic="false">
<Assembly Name="mscorlib" Version="4.0.0.0" />
<StubGeneration>
<Clear />
</StubGeneration>
<ShimGeneration>
<Clear />
<Add FullName="System.DateTime!" />
</ShimGeneration>
</Fakes>
Run Code Online (Sandbox Code Playgroud)
我相信这是因为,如MSDN所示,System.DateTime实际上是在mscorlib程序集中.
根据https://connect.microsoft.com/VisualStudio/feedback/details/1049181/fakes-cant-generate-fakes-dlls-for-system-dll,这是 .NET Framework 4.5 中的一个错误。
将 .NET Framework 更改为 4.5.2 确实为我解决了这个问题。
| 归档时间: |
|
| 查看次数: |
4779 次 |
| 最近记录: |