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 am having problems using the WillReturnCollectionValuesOf method.

The collection I am trying to fake contains Silverlight UIElements: our own Silverlight class that derives from System.Windows.Controls.UserControl.
An exception is thrown when accessing the count of the collection. Oddly, when stepping through with the debugger, if the Count is inspected before the call to the WillReturnCollectionValuesOf is made, the code works. But if the count is inspected after the collection setup, it throws a TypeInitializationException. If the code is run without debugging, the following exception is thrown:
System.UnauthorizedAccessException: [InvalidCrossThreadAccess]

Here is the test code reproducing the problem:
            Grid fakeGrid = Isolate.Fake.Instance<Grid>();
            //Inspecting Count here in debugger works (0 returned) and 
            //fixes problem (Count returns 1 below)
            Isolate.WhenCalled(() => fakeGrid.Children)
                    .WillReturnCollectionValuesOf(new List<UIElement>() 
                             { Isolate.Fake.Instance<View>() });
            
            int count = fakeGrid.Children.Count; //Throws


Can you tell me if this should work?
thanks,
a
asked by andredking (800 points)

2 Answers

0 votes
Hi a,

The test passes here :cry:

Can you please send us (support at typemock.com) a small project reproducing the problem?

Also, which test runner are you using?

_________________
Regards

Yonatan Eldar,
TypeMock Support Group
answered by yonatan (1.6k points)
0 votes
Hi Yonatan,
Thanks for your reply. I am afraid I did not give you all the information last time. I have been able to reproduce the problem with a small solution and will send it to the support alias.
Here is some more information:
mstest version 10.0.30319.1
typemock isolator version 6.0.3.0
We are following Roy Osherove's article about unit testing Silverlight and have replaced all the System* references in the test project with the ones from the Silverlight SDK - I will include these in the zip I send you so you can compile without a lot of messing around changing references.
Thanks for the help,
andre
answered by andredking (800 points)
...