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
This code is failing when it tries to set the Count property of the mocked collection:

premListMock = MockManager.MockObject(typeof (PremiseList));
premListMock.ExpectGet("Count", 0); <-- Fails when it attempts this call


item = invTrans as IElementTransaction;
List<ValidationFailureOptions> expected = new
List<ValidationFailureOptions>();
List<ValidationFailureOptions> actual;
expected.Add(ValidationFailureOptions.NoPremiseExists);
actual = Validators.Validate(item, (PremiseList)premListMock.Object, null, null);
asked by damiens (680 points)

5 Answers

0 votes
Hi
Can you please post the error message or the exception you're getting?
answered by ohad (35.4k points)
0 votes
------ Test started: Assembly: CIS.Transaction.dll ------

TestCase 'Test.Transaction.ValidatorsTest.ValidateTestNoActivePremise'
failed: TypeMock.TypeMockException:
*** Cannot mock methods defined in types from mscorlib assembly.
at TypeMock.MockManager.a(Type A_0, String A_1, Boolean A_2)
at TypeMock.MockManager.a(MethodBase A_0)
at TypeMock.Mock.a(String A_0, Object A_1, Boolean A_2, Boolean A_3, Int32 A_4, Type[] A_5)
at TypeMock.Mock.ExpectAndReturn(String method, Object ret, Int32 timesToRun, Type[] genericTypes)
at TypeMock.Mock.ExpectGet(String property, Object value, Int32 timesToRun)
at TypeMock.Mock.ExpectGet(String property, Object value)
D:workCommonMarketInterfaceCISTransactionValidatorsTest.cs(85,0): at Test.Transaction.ValidatorsTest.ValidateTestNoActivePremise()
answered by damiens (680 points)
0 votes
Hi
My guess is that the class you are mocking (PremiseList) inherits from some .NET collection that is defined in mscorlib. If PremiseList class doesn't implements its own Count property than the base type implementation gets called.

The Isolator can mock anything except concrete types from mscorlib.
:arrow: Note that the Isolator can mock interfaces and abstract classes from mscorlib.

Anyway this is a guess based on the code you posted.
Can you confirm it?
answered by ohad (35.4k points)
0 votes
It is a Csla.ExtendedBindingList<T> which inherits from BindingList<T>
answered by damiens (680 points)
0 votes
Hi
I checked it out. CLSA.ExtendedBindingList and its base BindingList does not implements the count property so what gets called is Collection<T>.Count
from mscorlib assembly.

That said if you can post more details of what you are trying to test + the test code
we will try to help you testing it.

You can alos click on the following link to find out more on Natural Mocks
answered by ohad (35.4k points)
...