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
Hello,

I've found an old forum thread (from 2006) with the following information:

"It is not possible to mock objects that are created in a separate AppDomain yet. However this is in our features list so don't lose your hope".

What is the situation with cross-domain mocking now? It does not seem to be supported - I just tried to create a mock object in a test, but this did not affect the instantiation of an object of the same type in a different domain.

Are there any recommendations/workarounds regarding this? Basically we need to mock behavior of method calls (both static and instance) that are invoked in a different AppDomain.
asked by vagif (19.4k points)

3 Answers

0 votes
Hello Vagif,

Unfortunately cross domain mocking isn't supported (yet) due to low customer interest.

Can you please specify the scenarios you've been using Isolator and the required functionality?
answered by dhelper (11.9k points)
0 votes
Hello,

Here is a scenario. I have a static class with static method that returns a a class that wraps a currency collection: MyClass.Currencies. The currency collection class has an indexer that can be used to return a currency by currency code:

MyCurrency c = MyClass.Currencies["USD"];

I need to mock MyCurrency instance that is returned by this call, so it will have properties that I need for the test.

The problem is that the call above is made in a different domain. So if create custom MyCurrency object, set the properties I need and then mock the call above:

using(RecordExpectations recorder = new RecordExpectations())
{
recorder.ExpectAndReturn(MyClass.Currencies[null], myCustomCurrency).RepeatAlways();
}

then this call is perfectly mocked as long I execute MyClass.Currencies[] call in the same AppDomain as the test method. Unfortunately the call is executed in a different AppDomain that is created during execution of method being tested. And then it is not mocked.

What is your recommended approach to such tests? I am surprised that this testing with several AppDomains does not attract customer interest.
answered by vagif (19.4k points)
0 votes
I guess THAT topic is again two years old; I was considering Isolator, but I also was looking for mocking across AppDomains. I was trying to use Microsoft Moles and it also has this limitation.

What I want to accomplish is mocking the .NET ConfigurationManager to run services that normally require configuration files, but setting up the configurations as part of the unit test, then hosting them on the stop so they all connect together just so (sort of like an integration test in the form of a unit test... maybe I should be shot?) Each service would run in its own AppDomain to simulate different configuration files, of course. I can make the whole thing work with Moles, just only in the current AppDomain.

Of course I can find workarounds, but this is a good excuse to have management buy us your snazzy-looking software :)

Thanks.
answered by daniele.pagano (140 points)
...