Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vs 2012: Shims compile

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?

like image 555
alerya Avatar asked Dec 28 '12 09:12

alerya


2 Answers

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>
like image 95
Oleg Sych Avatar answered Nov 24 '22 01:11

Oleg Sych


I have resolved it already alone.

It was .Net Framework 4.0 in Property.

Changing on 4.5 resolve the problem.

like image 35
alerya Avatar answered Nov 24 '22 00:11

alerya