vanderkleij/Smocks

calling static method in another function does not call shim unless it is called within the smock function.

HanaKana opened this issue · 2 comments

Smock.Run(context =>
{
    context.Setup(() => DateTime.Now).Returns(new DateTime());
    //this line is required to link the shim ?
    var required = DateTime.Now;
    var datetime = StaticClass.TestDatetime();
    var breakHere = 123;
});

public class StaticClass
{
    public static DateTime TestDateTime()
    {
        return DateTime.Now;
    }
}

With the example code above I have to call the function DateTime.Now; within the smock otherwise it will not call the shim datetime value in my StaticClassTestDatetime() function.

I was able to reproduce this issue, when StaticClass is in a different assembly as the Smock.Run call. If they are in the same assembly, it works as expected.

I'll look into this in more detail shortly and provide a fix.

The Smocks nuget package 0.4.15 contains the fix for this issue and is available now.