Search code examples
c#unit-testingvisual-studio-2013microsoft-fakes

Test fails with ShimNotSupportedException


I have a very simple test that uses a shim but when I run the test I get a "ShimNotSupportedException". I am using VS2013 Ultimate and I am not debugging.

[TestMethod]
public void GetDateTimeString_ReturnDTString_SetDateTime_CurrentYear()
{
    using (ShimsContext.Create())
    {                
        // Set 'UtcNow' to 1 March 2014
        ShimDateTime.UtcNowGet = () => new DateTime(2014, 3, 1, 5, 30, 28);

        var inputDate = new DateTime(2014, 06, 20, 18, 33, 50);

        // Act
        var actual = CustomTimeHelper.GetDateTimeString(inputDate);

        // Assert
        Assert.IsNotNull(actual);               
    }
}

I have tried the following with no success

  • Running VS as a Adminstrator
  • Deleting System.4.0.0.0.Fakes from reference, System.fakes from the Fakes directory, and all System.4.0.0.0.Fakes files from the FakeAssemblies and recreating the fake from the right-click "Add-fakes assembly" menu in references
  • I'm not using a Test Settings File
  • I have disabled IntelliTrace from the options menu
  • I have done a Clean Solution and Rebuild
  • I have performed the "Run All Tests" via the Test menu item and via Test Explorer
  • I have run just the single test that is broken
  • I DO have a warning saying that "Some Fakes could not be generated" when when investigated (by setting Diagnostic="True" in the System.Fakes file, System.DateTime seems to be fine as it is not listed in the list of classes that could not be generated from
  • I have Tried both Release and Debug and on other computers

If anyone has any ideas as to what might be happening or how to resolve the issue, it would be greatly appreciated.


Solution

  • The issue was coming from referencing version 11.0.0.0 of Microsoft.QualityTools.Testing.Fakes.

    The following steps fixed the issue for me.

    1. remove all *.fakes references from the project
    2. Delete all files in your Fakes folder
    3. re-add Microsoft.QualityTools.Testing.Fakes version 12.0.0.0
    4. Regenerate the fake assemblies you deleted in step 1