In short: How would I check the type of a UI user control during a Silverlight unit test?
In detail: I am loading child views into a ContentControl on a parent view. During testing I want to check that the correct view has been loaded at the correct time. My views are in separate projects, and I don’t want to add a reference to those assemblies into my test project for the parent view (too tightly coupled).
This is where I am stuck:
[TestMethod]
[Asynchronous]
[Description("Test to confirm that upon initial class creation, the login view is loaded as the default content for the TaskRegion.")]
public void Shell_Initialisation_LoginViewIsLoadedByDefault()
{
Shell shell = new Shell();
//helper method from Justin Angels example
WaitFor(shell, "Loaded");
TestPanel.Children.Add(shell);
Shell_ViewModel viewModel = shell.DataContext as Shell_ViewModel;
EnqueueCallback(() => Assert.IsTrue(viewModel.TaskRegionContent is **How do I reference my control type**));
EnqueueTestComplete();
}
Should I be using mocking?
(The WaitFor is a helper method supplied by Justin Angel)
How about using GetType()? You can then use various methods on the Type instance to check whether it is an instance of type, or inherited from, the type.
Where “Control” above is the type of interest that you want to check.
See also: http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.assert.isinstanceoftype(VS.80).aspx