FYI, here is a clarification of my comment, "I am familiar with the workaround of referencing SomethingStatic before mocking ClassToMock."
Here is the code for the workaround. All I did was add the line that creates somethingStaticWorkaround, making sure it comes before mocking ClassToMock.
Notice that I don't use that variable. What's the purpose, then? The purpose is to force the initialization of StaticStuff's static data. If I do this, then the test passes.
- Chris V
public void TypeMockStaticDemo_Part1()
string somethingStaticWorkaround = StaticStuff.SomethingStatic;
ClassToMock mockedClassToMock = Isolate.Fake.Instance<ClassToMock>();
Isolate.WhenCalled(() => mockedClassToMock.GetSomethingStatic()).CallOriginal();
string somethingStatic = mockedClassToMock.GetSomethingStatic();
Assert.AreEqual("Something Static", somethingStatic);