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
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
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
asked by JasonJhuboo (800 points)

2 Answers

0 votes
Hi Jason - I need to further investigate this issue - let's take it offline.
answered by dhelper (11.9k points)
0 votes
Hi Jason - I need to further investigate this issue - let's take it offline.


No problems - please can you either PM me or send me an email as I am unable to PM you from this forum.

Thanks,
Jason
answered by JasonJhuboo (800 points)
...