Bug recursively mocking IEnumerable<T>

4 posts, 0 answers
  1. Micah
    Micah avatar
    6 posts
    Member since:
    Sep 2013

    Posted 30 Jan 2014 Link to this post

    01.using System;
    02.using System.Collections.Generic;
    03.using Microsoft.VisualStudio.TestTools.UnitTesting;
    04.using Telerik.JustMock;
    06.namespace JustMockTestProject
    08.    public interface IFoo
    09.    {
    10.        IBar Bar { get; }
    11.    }
    13.    public interface IBar : IEnumerable<Object>
    14.    {
    15.        IBaz GetBaz();
    16.    }
    18.    public interface IBaz {}
    20.    [TestClass]
    21.    public class JustMockTest
    22.    {
    23.        [TestMethod]
    24.        public void TestMethod1()
    25.        {
    26.            var foo = Mock.Create<IFoo>(Behavior.RecursiveLoose);
    27.            var bar = Mock.Create<IBar>(Behavior.RecursiveLoose);
    29.            Assert.IsNotNull(bar.GetBaz()); // passes
    30.            Assert.IsNotNull(foo.Bar.GetBaz()); // fails
    31.        }
    32.    }

    Expected Behavior: RecursiveLoose mocking behavior will cause every method to return a mocked object for reference types.
    Actual Behavior: When RecursiveLoose runs into an interface that derives from IEnumerable<T>, the returned mocked object does not get recursively mocked causing NullReferenceException when a test attempts to access members on the mocked object (IBaz in the example above).

    The above is a simplified test case to narrow down the source of the bug.  If I have an IEnumerable<T> property on IFoo instead, then the returned object is correctly mocked (GetEnumerator doesn't return null).

    As shown in the above example on line 29, mocking an IBar directly works.  It is only when attempting to recursively mock an object that derives from IEnumerable that the problem occurs.
  2. Kaloyan
    Kaloyan avatar
    878 posts

    Posted 04 Feb 2014 Link to this post

    Hello Micah,

    Thank you for pointing this out. It is clearly a bug in our product. I am adding it into the backlog and it should be fixed in the near future releases.

    I have also updated your Telerik points.

    Share what you think about JustTrace & JustMock with us, so we can become even better! You can use the built-in feedback tool inside JustTrace, our forums, or our JustTrace or JustMock portals.
  3. s
    s avatar
    1 posts
    Member since:
    Jul 2017

    Posted 10 Jul in reply to Kaloyan Link to this post

    I see the bug was posted in 2017. Has it been fixed? If yes in which release? I can still see this bug in 2015.3.929.5
  4. Kamen Ivanov
    Kamen Ivanov avatar
    80 posts

    Posted 13 Jul Link to this post


    Thank you for your interest in JustMock.

    I can confirm that the bug is fixed.

    I double checked it with our latest version and could not reproduce it.

    Kamen Ivanov
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top