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