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
Hi
I have an abstract object that have an ObservableCollection<T> in it. The private field set to new at declaration.
A lot of tests depend on that object.
In the TestInitialize method I construct an object using isolator and pass it Members.CallOriginal.

If I'm running all the test in sln I'm getting 5 failed tests.
If I'm running those tests they pass.
If I'm running all test in that TestClass they pass.

There is no using in global variables in those test methods.
Every test method is completely independent from other.
I've tried to debug the tests and find out that there is an exception at every call to the Fake.Instance method.

The error is:
System.ArgumentOutOfRangeException was unhandled by user code
Message=Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Source=TypeMock
ParamName=index
StackTrace:
at System.ThrowHelper.ThrowArgumentOutOfRangeException()
at System.Collections.Generic.List`1.get_Item(Int32 index)
at h1.b(gy A_0)
at h1.a(String A_0, gy A_1, Int32 A_2, Mock& A_3)
at h1.a(String A_0, Object A_1, Object A_2, Type& A_3, String A_4)
at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4)
at TypeMock.InternalMockManager.isMocked(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected)
at System.Collections.ObjectModel.ObservableCollection`1..ctor()
at AM5Client.Controller..ctor() in C:UsersAdielAM5ClientController.cs:line 20
at Mock0000Controller..ctor()
at TypeMock.MockManager.b(Type A_0, Object[] A_1)
at TypeMock.MockManager.a(Type A_0, Constructor A_1, Object[] A_2, Boolean A_3)
at TypeMock.MockManager.MockObject(Type type, Constructor mockConstructors, Object[] args)
at TypeMock.MockManager.MockObject[TMockedType](Constructor mockConstructors)
at TypeMock.ArrangeActAssert.InstanceFaker`1.e()
at TypeMock.ArrangeActAssert.InstanceFaker`1.c()
at if.CreateFakeInstance[T](Members behavior, Constructor constructorFlag, Constructor baseConstructorFlag, Type baseType, Object[] ctorArgs)
at if.Instance[T](Members behavior)
at AM5Client.UnitTests.ControllerTest.Init() in C:UsersAdielAM5Client.UnitTestsControllerTest.cs:line 23
InnerException:

at line 20 there is:
private ObservableCollection<IReader> _readers = new ObservableCollection<IReader>();

any idea?
Thanks
Adiel
asked by adiel.sharabi (3.4k points)

5 Answers

0 votes
Hi Adiel,

I am going to need a bit more info about this. Can you post said class code here, along with a couple of the failing tests? (if it's better for you, you can send the code to us at support (at) typemock.com, and we'll work on it offline)

Without the data, I would hazard the guess that this is either an isolation cleanup, or a multithreading issue. To rule these out please do the following:
:arrow: make sure the said test class is decorated with the [Isolated] attribute - this takes care of Isolation cleanup
:arrow: try forcing these tests to run before the rest of the tests. You can do that in mstest by defining a test list.

Please let me know if these things helped, and please send over the code if they did not.

Thanks,
Doron
Typemock Support
answered by doron (17.2k points)
0 votes
Hi
I cannot post in here all the code... but it look like the problem is in the ctor of ObservableCollection with an IReader interface.
I've tried to run all tests with resharper runner and all tests pass.
I didn't success to create different execute order with mstest list.
The class is decorated with Isolated.
Thanks
Adiel

BTW - I didn't recive any mail about your answer...
answered by adiel.sharabi (3.4k points)
0 votes
Hi Adial,
Any chance you can send a small repro to our support mail?
answered by ohad (35.4k points)
0 votes
I'll try to reproduce it with partial code and send it to you.
Thanks
answered by adiel.sharabi (3.4k points)
0 votes
Hi
We had a bug that prevent the application from closed.
as we fix it (dispose issue) the problem was gone.
I think it's maybe related.
Thanks anyway.
Adiel
answered by adiel.sharabi (3.4k points)
...