vs 2012: Shims compile

[亡魂溺海] 提交于 2019-11-27 16:24:35

问题


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);
        }
    }
}

see http://msdn.microsoft.com/en-us/library/hh549176.aspx

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

warning : Some fakes could not be generated. For complete details, set Diagnostic attribute of the Fakes element in this file to 'true' and rebuild the project.

How can I resolve this warning?


回答1:


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.

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.)

To resolve the warning, change the .Fakes file to generate only those Stubs and Shims you need in your tests. Details here here 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>



回答2:


I have resolved it already alone.

It was .Net Framework 4.0 in Property.

Changing on 4.5 resolve the problem.




回答3:


Try removing those .Fakes file. I removed them accidentally and compiled, and the warnings are gone. I am not sure what the impact is, but everything seems to run fine. I think it causes the compile to recompile the fakes file everything there is a build.



来源:https://stackoverflow.com/questions/14067332/vs-2012-shims-compile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!