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
0 votes
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
asked by tesicg (1.3k points)

13 Answers

0 votes
also - what are you trying to test? what is the logical pieace of code you are testing there?

also note - there is no need to add your control to a panel since you can just "new" it up and start calling methods on it.
answered by royo (2k points)
0 votes
I'm having an issue with SilverUnit and TypeMock Isolator. It's saying System.IO.FileNotFoundException: Could not load file or assembly 'TypeMock, Version=5.2.3.0, Culture=neutral, ...
which is correct because the version of TypeMock seems to be version 5.3.0.0.
I downloaded both today (Trial TypeMock) so they should be the latest. Is there a newer SilverUnit that I've somehow missed?

thanks,
Stephen
answered by Lyynx (140 points)
0 votes
There is an updated version of the binaries on the Silverunit page (release 0.5).
this should be working correctly against the latest Typemock binaries.
please post a reply letting us know if this has fixed your issue or not.
answered by royo (2k points)
...