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?
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>