Failure of recursive mocking of internal type.

10 posts, 0 answers
  1. Bob
    Bob avatar
    20 posts
    Member since:
    Mar 2012

    Posted 28 Mar 2012 Link to this post

    I think I have discovered a bug.
        internal class InternalClass
        {
            public int GetInt() { return 5; }
        }
     
        internal class InternalOwner
        {
            public int GetInt() { return 5; }
            public InternalClass InternalClassField = new InternalClass();
     
            public InternalClass InternalClassProp
            {
                get { return InternalClassField; }
            }
        }
     
    ...
     
        [Test]
        public void Test5()
        {
            InternalOwner io = Mock.Create<InternalOwner>();
    //      Mock.Arrange(() => io.GetInt()).Returns(6);     // Test1, works.
    //      Mock.Arrange(() => io.InternalClassField.GetInt()).Returns(6);      // Test2, works.
            Mock.Arrange(() => io.InternalClassProp.GetInt()).Returns(6);       // Test3, FAILS.
        }
    If you uncomment each of the lines Test1, Test2 and Test3 in turn you'll see that recursively mocking the GetInt() method via InternalClassProp fails.

    Adding the InternalsVisibleto assembly attribute has no effect.

  2. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 30 Mar 2012 Link to this post

    Hi Bob,
    Thanks again for reporting the issue. However, in your test I found that you have the following line:
    Mock.Arrange(() => io.InternalClassField.GetInt()).Returns(6); .

    This is invalid anyway since you can't mock a field as there is no way to intercept it. Next, adding the InternalsVisibleTo attribute from the following post made it work.

    http://www.telerik.com/help/justmock/basic-usage-mock-internal-types-via-proxy.html

    I have also included the test project to let you have a look. However, I found an exception accessing the InternalClass from this line:
    Assert.AreEqual(6, io.InternalClassProp.GetInt());

    For the above case, i am creating a task at PITS which you can follow here:
    http://www.telerik.com/support/pits.aspx#/public/justmock/10540

    I am also adding some telerik points into your account for your awesome support.

    Kind Regards,
    Mehfuz
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. DevCraft R3 2016 release webinar banner
  4. Bob
    Bob avatar
    20 posts
    Member since:
    Mar 2012

    Posted 30 Mar 2012 Link to this post

    I've had a look at your sample and compared that solution to my project. I noticed that you were using MsTest as the unit test framework and I was using Nunit, after changing the unit test framework to MsTest I confirm it works exactly as you have stated. Adding the InternalsVisibleAttribute does indeed enable the Arrange call to succeed but accessing the internal class throws an exception.

    Test 'MsTestApp1.TestSuite1.Test6' failed: Test method MsTestApp1.TestSuite1.Test6 threw exception:
    System.TypeAccessException: Attempt by method 'InternalOwner_Interceptor_fdecbacbc82243e184fd89253931c3c2.Intercept(InternalOwner, Boolean ByRef)' to access type 'MsTestApp1.TestSuite1+InternalClass' failed.
        at InternalOwner_Interceptor_fdecbacbc82243e184fd89253931c3c2.Intercept(InternalOwner , Boolean& )
        D:\_UserData\Development\Workspaces\CSharpTesting\JustMockTesting\MsTestApp1\TestSuite1.cs(25,0): at MsTestApp1.TestSuite1.InternalOwner.get_InternalClassProp()
        D:\_UserData\Development\Workspaces\CSharpTesting\JustMockTesting\MsTestApp1\TestSuite1.cs(60,0): at MsTestApp1.TestSuite1.Test6()

    I hope you can get that fixed quickly as it's a bit of a showstopper.

    Don't you support mocking via Nunit? That's probably not a showstopper but Nunit has a good reputation (and I've never had any problems with it before) whereas most TDD guys suggest MsTest is pretty vile.
  5. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 03 Apr 2012 Link to this post

    Hi Bob,
    Thanks again for the reply. I am attaching the updated project with NUnit for your convenience and yes JustMock officially supports NUnit.
     
    In addition, we are also looking into the issue mentioned in the following PITS entry and hopefully it will be fixed in coming release.
     
    http://www.telerik.com/support/pits.aspx#/public/justmock/10540

    Kind regards,
    Mehfuz
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  6. Bob
    Bob avatar
    20 posts
    Member since:
    Mar 2012

    Posted 04 Apr 2012 Link to this post

    Thanks. It's such a critical feature for us though that we are holding off on further testing of JustMock until the fix for recursive mocking internal types is deployed. If you get a fix and want to push an interim build my way for testing that would be great, I'll be monitoring this thread and the PITs ticket for updates.
  7. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 06 Apr 2012 Link to this post

    Hi Bob,
    Thanks again for your reply. I will try to prepare an internal build next week once the issue is fixed. In the meantime, should you face any other problem please don't hesitate to contact me.

    Kind Regards
    Mehfuz
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  8. Bob
    Bob avatar
    20 posts
    Member since:
    Mar 2012

    Posted 17 Apr 2012 Link to this post

    Can you give me a quick update on the status of this issue please?
  9. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 19 Apr 2012 Link to this post

    Hi Bob,

    Thanks again for contacting us. I am still working on the issue. Hopefully I will send you a build early next week.

    Thank you for your patience.

    Kind Regards
    Mehfuz 
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  10. Bob
    Bob avatar
    20 posts
    Member since:
    Mar 2012

    Posted 11 May 2012 Link to this post

    Any progress on this yet please?
  11. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 16 May 2012 Link to this post

    Hi Bob,

    Thanks again for contacting us. 

    I am having some issues in fixing the bug. However, we have fixed a similar issue in SP1 that I would highly recommend to check out. In addition, I will hopefully get around the problem and send you a build next week, also let you know for any exceptions.  

    In addition, you can always reach me at mehfuz.hossain@telerik.com


    Kind Regards
    Mehfuz
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top
DevCraft R3 2016 release webinar banner