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
0 votes

As a suggestion, I find myself using these lines of code a great deal (don't worry about the code itself, but I use these keywords a lot):

var httpCtx = Isolate.Fake.Instance<HttpContextWrapper>(); Isolate.Swap.NextInstance<HttpContextWrapper>().With(httpCtx);


Isolate.WhenCalled(() => HttpContext.Current).WillReturn(ctx);

I think it would be very helpful, and save me a lot of time, to be able to combine these two statements into one, something like:

var httpCtx = Isolate.Swap.NextInstance<HttpContextWrapper>().WithNewFake();


Isolate.WhenCalled(() => HttpContext.Current).StaticMethod().WillReturn(ctx);

That would save a lot of coding time in the long run, since it's a pretty popular option in my design.

asked by bmains (13.2k points)

3 Answers

0 votes

We're always looking to make the API easier to use. so thanks very much for the suggestions!

We've actually implemented a requested feature, which is similar to your first suggestion. You can create a future fake with one line by calling:


This, however, does not return the fake object, but rather instructs Isolator to replace the next call to a real type with fake one. Usually there's no need to set any additional behavior.
answered by igal (5.7k points)
0 votes
It would actually be pretty great if WithRecursiveFake would return the fake that is created. I often use this code:

            var fakeDataSource = Isolate.Fake.Instance<RelayDataSource>();
            Isolate.WhenCalled(() =>fakeDataSource.ExecuteDataTable("")).WillReturn(somePreparedValue);

Where most members of the fake will return the default empty or recursive fakes, except for a few specific ones that I want to return prepared values. Having WithRecursiveFake return the created fake would merge the first 2 lines every time I make this happen.

answered by Guillaume (3.5k points)
0 votes
Now working as requested.
Right on!
answered by Guillaume (3.5k points)