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
I'm developing a project in ASP.NET. When testing my pages (using WatiN)
I cannot fake my static methods called from my pages.

Here's the layout of my porject:
- Foo
Contains all core functionallity
- Foo.Web
- Contains all templates, user controls, styles etc.
- Foo.Test
- Contains all test logic and references the Foo project.

So when testing one of my pages, it has a button which will call the method Foo.FooProviders.FooService.DoSomething(Int32).

So I try to fake theses methods by (NOTE! FooService is not a static class):
Isolate.Fake.StaticMethods<FooService>(Members.ReturnRecursiveFakes);
Isolate.WhenCalled(() => FooService.DoSomething(1)).WillReturn(true);


When running the test, the method is never faked when the page calls this method. BUT, if I call the FooService from within the unit test it works.

How can I fix this?
asked by c3nturion (640 points)

3 Answers

0 votes
Hi,

The reason for the methods being faked inside the test but not in the browser context is that it runs in different processes.

Isolator doesn't support cross process fakes, and therefore the behavior was not faked as expected.

When WatiN calls to the site under test it talks to the local site, but it's a different process than the test process. In runtime you have 2 different CLRs and fake on the static methods in one CLR does not reflect on the 2nd CLR.
using (IE ie = new IE("localhost:1234"))
{
     // Automation logic here...
     // Actual CLR being automated is different than the test CLR
}


Regards,
Elisha
Typemock Support
answered by Elisha (12k points)
0 votes
Now I feel like an idiot. Makes absolute sense!

All I have to do now is figure out a way to somehow achieve something similar.

Thank you!
answered by c3nturion (640 points)
0 votes
Don't feel too bad 8)

If you want to test your web side logic using isolated unit tests, you should consider using Isolator + Ivonna - Ivonna is built on top of Isolator and allows you to fake the containing web environment to achieve isolation. This lets you test only the logic without relying on clumsy external runners.

You can find out more here: http://learn.typemock.com/aspnet_unit_testing_page .

Doron
Typemock Support
answered by doron (17.2k points)
...