Here is the code
using System.Windows.Forms;
using Microsoft.Practices.CompositeUI;
using Microsoft.Practices.CompositeUI.SmartParts;
public class class1
{
private WorkItem m_WorkItem;
public WorkItem WorkItem
{
get { return m_WorkItem; }
set { m_WorkItem = value; }
}
public void Foo()
{
WorkItem.SmartParts.AddNew<MyControl>("ID00001");
}
[SmartPart]
public class MyControl : Form
{}
}
And the test:
[Isolated]
[TestMethod]
public void Test()
{
class1 testClass = new class1();
WorkItem testWorkItem = new WorkItem();
testClass.WorkItem = testWorkItem;
MyControl fakeSmartPart = Isolate.Fake.Instance<MyControl>();
Isolate.WhenCalled(() => testWorkItem.SmartParts.AddNew<MyControl>("ID00001")).WillReturn(fakeSmartPart);
testClass.Foo();
}
This required the composite application block (CAB) available from codeplex.
The code is valid - All it is doing is telling an instance of Microsoft.Practices.CompositeUI.Collections.ManagedObjectCollection<TItem> to create and add a new instance of MyControl.
When I run the test however - I get the following error:
Test method TestProject2.UnitTest1+Tests.Test threw exception: System.ArgumentException: GenericArguments[0], 'IsolatorTest.MyControl', on 'TTypeToBuild AddNew[TTypeToBuild](System.String)' violates the constraint of type 'TTypeToBuild'. ---> System.Security.VerificationException: Method Microsoft.Practices.CompositeUI.Collections.ManagedObjectCollection`1[TItem].AddNew: type argument 'IsolatorTest.MyControl' violates the constraint of type parameter 'TTypeToBuild'..
I am using Isolator V5.4.2.0 / VS 2008 (Dev edition) and writing in c#
Any help would be appreciated!
Jason