Hi again,
I'm trying to test Silverlight custom control using SilverUnit.
I have XAML file with 2 controls on it, text box and command button.
Here's the code:
public partial class MyControl : UserControl
{
public IList<string> Numbers { get; set; }
public MyControl()
{
InitializeComponent();
Numbers = new List<string>();
}
private void txtNumber_TextChanged(object sender, TextChangedEventArgs e)
{
int number = 0;
string text = this.txtNumber.Text;
if (!int.TryParse(text, out number) || string.IsNullOrEmpty(text))
this.cmdAdd.IsEnabled = false;
else
this.cmdAdd.IsEnabled = true;
}
private void cmdAdd_Click(object sender, RoutedEventArgs e)
{
string text = this.txtNumber.Text;
Numbers.Add(text);
}
}
And I'd like to test UI that is text box's Text_Changed event and command button's Click event. I've created regular MS test project (not MS Silverlight test project) and have this code:
[TestClass]
public class UnitTest1 : SilverlightTest
{
private MyControl myControl;
...
[TestInitialize()]
public void MyTestInitialize()
{
myControl = new MyControl();
this.TestPanel.Children.Add(myControl);
}
[TestMethod, SilverlightUnitTest]
public void TestWithSilverUnit()
{
Assert.IsTrue(true);
}
...
}
It compiles successfully, but when I run the test it gives me an error:
Initialization method TestProject2.UnitTest1.MyTestInitialize threw exception. System.TypeInitializationException: System.TypeInitializationException: The type initializer for 'System.Windows.DependencyObject' threw an exception. ---> System.TypeInitializationException: The type initializer for 'MS.Internal.JoltHelper' threw an exception. ---> System.TypeLoadException: Method 'Create' in type 'System.Net.BrowserHttpWebRequestCreate' from assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' does not have an implementation..
Stack trace is here:
MS.Internal.JoltHelper..cctor()
MS.Internal.JoltHelper.get_ThreadID()
MS.Internal.XcpImports.CheckThread()
System.Windows.DependencyObject..ctor(UInt32 nativeTypeIndex, IntPtr constructDO)
System.Windows.DependencyObject..ctor(UInt32 nativeTypeIndex)
System.Windows.DependencyObject..ctor()
System.Windows.DependencyObject.ManagedReferencesToken..ctor()
System.Windows.DependencyObject..cctor()
System.Windows.DependencyObject..ctor(UInt32 nativeTypeIndex)
System.Windows.UIElement..ctor(UInt32 nKnownTypeIndex)
System.Windows.FrameworkElement..ctor(UInt32 nKnownTypeIndex)
System.Windows.Controls.Control..ctor(UInt32 nKnownTypeIndex)
System.Windows.Controls.UserControl..ctor()
SilverlightApplication1.MyControl..ctor() in D:Corgent DiagramTest projectsSilverlightSilverlightApplication1SilverlightApplication1MyControl.xaml.cs: line 19
TestProject2.UnitTest1.MyTestInitialize() in D:Corgent DiagramTest projectsSilverlightSilverlightApplication1TestProject2UnitTest1.cs: line 68
It fails at this line in MyTestInitialize method:
myControl = new MyControl();
I suppose I didn't do something in proper way, but I'm not sure what.
Could you help me with this, please?
Thank you in advance.
Goran