chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
Have a static method on a static class (static class Foo, not class Foo with static method):

Isolate.Fake.StaticMethods<UserNotification>();

Get compile error:
static types cannot be used as type arguments

If I change to regular class, works - known issue or user error? Looked in known issues but didn't see it.

Possibly add this as an example to developers guide (which is great help by the way).

Surprisingly I hadn't ran into this scenario yet and it got me...

Thanks for your help!

Brian
asked by boo (21.8k points)

6 Answers

0 votes
We will investigate this and pass your recommandations to our dev team.

Thanks for the heads up
answered by dhelper (11.9k points)
0 votes
Hi Brian

Adding a bit to what Dror said:
You can use the Isolate.Fake.StaticMethods(Type type) overload
e.g:
Isolate.Fake.StaticMethods(typeof(UserNotification)); 


On top of that remember that in order to fake a static method
you don't have to go through Isolate.Fake.StaticMethods

Example:
[Test]
public void TestStaticClass()
{
    Isolate.Fake.StaticMethods(typeof(UserNotification));
    Isolate.WhenCalled(() => UserNotification.SomeMethod()).WillReturn(5);

    Assert.AreEqual(5, UserNotification.SomeMethod());
}
answered by ohad (35.4k points)
0 votes
Hi Ohad, thanks for help, I'll check this tonight when I'm back at the house to see if it worked; one quick question though:

You say 'you don't have to go through Isolate.Fake.StaticMethods', yet in your example afterwards you are still using it - was this a typo or are you saying that the call to
Isolate.Fake.StaticMethods(typeof(UserNotification)); is redundant?

Thanks for the help.
answered by boo (21.8k points)
0 votes
Hi Brian

Oops my bad. :oops:
The line:
Isolate.Fake.StaticMethods(typeof(UserNotification));
Is indeed redundant.
answered by ohad (35.4k points)
0 votes
The docs in the developers guide should be updated to reflect this and it won't get me next time. :D

What is the purpose of Isolate.Fake.StaticMethods<T>() if it is not needed (redundant) then?
answered by boo (21.8k points)
0 votes
Hi Brian

You are right about the documentation. We'll fix it up.

Basically it lets you define the default behavior for static methods.
The default is Members.ReturnRecursiveFakes
So you can change it by using the overload
FakeStaticMethods(Type, Members)

For example to set the default to call original methods use:
Isolate.Fake.StaticMethods(typeof(UserNotification), Members.CallOriginal);


Hope it clears things up. :)
answered by ohad (35.4k points)
...