Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
HanaKana opened this issue Sep 28, 2015 · 2 comments
Labels

Comments

@HanaKana
Copy link

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.

@vanderkleij
Copy link
Owner

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.

@vanderkleij
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants