So anyhow, breakfast was good.
I’m suspecting this:
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
public void InitializeComponent() {
if (_contentLoaded) {
return;
}
_contentLoaded = true;
System.Windows.Application.LoadComponent(this, new System.Uri("/SilverlightApplication1;component/Page.xaml", System.UriKind.Relative));
this.LayoutRoot = ((System.Windows.Controls.Grid)(this.FindName("LayoutRoot")));
}
Which is inside page.g.cs (generated part of the Page partial class)
So I can’t override it inside of Page, but if I go inherit from it with a test class then I can Hide it via the ‘new’ keyword like so:
public class TestPage : Page
{
public new void InitializeComponent()
{
}
}
And, well… that didn’t work. I still get
----> System.UnauthorizedAccessException : InvalidCrossThreadAccess
So let’s try something else. We have this inside of page:
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
}
}
Let’s change that to:
public partial class Page : UserControl
{
public Page()
{
Init();
}
public virtual void Init()
{
InitializeComponent();
}
}
I ‘think’ this works in c# and java (but wouldn’t work in c++ because you can’t call virtuals from constructors). Let’s see by overriding it in our test page:
public class TestPage : Page
{
public override void Init()
{
}
}
Well, I think now we’re dealing with a hidden dependency inside the UserControl constructor in all reality (which reading the stack trace, I should have known) because the Page constructor never even gets called.
I’m really not interested in redefining user control for the sake of constructing this stuff inside a test because I can just use an mvc or mvp pattern (or M_V_VM pattern)
So blah, disappointing that yet another UI technology is hard to construct inside a unit test. (probably not impossible, but I’m bored of trying)