本文介绍了vs 2012:Shims编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图在VS 2012 Ultimate(如MSDN网站中所述)中发挥作用:

I am trying to make a shim in VS 2012 ultimate as it described in MSDN site:

[TestClass]
public class TestClass1
{
    [TestMethod]
    public void TestCurrentYear()
    {
        int fixedYear = 2000;

        using (ShimsContext.Create())
        {
          // Arrange:
          // Detour DateTime.Now to return a fixed date:
          System.Fakes.ShimDateTime.NowGet =
              () =>
              { return new DateTime(fixedYear, 1, 1); };

          // Instantiate the component under test:
          var componentUnderTest = new MyComponent();

          // Act:
          int year = componentUnderTest.GetTheCurrentYear();

          // Assert:
          // This will always be true if the component is working:
          Assert.AreEqual(fixedYear, year);
        }
    }
}

请参见 http://msdn.microsoft.com/en-us/library/hh549176.aspx

但是当我编译测试项目时,我在输出中得到了一个概念:

But when I compile my test project I get a notion in Output:

如何解决此警告?

推荐答案

Visual Studio 2012 Update 1在Fakes中改进了代码生成,以简化对代码生成问题的疑难解答.每当无法为特定类型生成存根或Shim时,假货现在都可以生成警告消息-您可以在Visual Studio的错误列表"窗口中看到此消息.

Visual Studio 2012 Update 1 improved code generation in Fakes to simplify troubleshooting of code generation problems. Whenever a Stub or a Shim could not be generated for a particular type, Fakes can now generate a warning message - you can see this in the Error List window of Visual Studio.

但是,为了防止警告数量对于大型组件(如系统)变得不堪重负,Fakes默认情况下会生成一个警告.通过将.Fakes文件中Fakes XML元素的Diagnostic属性设置为"true" 或"1"并重建项目,可以看到警告消息的完整列表. (有关示例,请参见下面的第一行代码.)

However, to prevent the number of warnings from becoming overwhelming for a large assembly, such as System, Fakes generates a single warning by default. You can see a complete list of warning messages by setting the Diagnostic attribute of the Fakes XML element in the .Fakes file to "true" or "1" and rebuilding the project. (See the first line of code below for an example.)

要解决该警告,请更改.Fakes文件以仅生成测试中需要的那些存根和垫片.详细信息此处此处可用选项的完整列表

To resolve the warning, change the .Fakes file to generate only those Stubs and Shims you need in your tests. Details herehere a complete list of available options

<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/" Diagnostic="true">
  <Assembly Name="System" Version="4.0.0.0"/>
  <StubGeneration Disable="true" />
  <ShimGeneration>
    <Clear/>
    <Add FullName="System.DateTime!"/>
  </ShimGeneration>
</Fakes>

这篇关于vs 2012:Shims编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-14 07:45