This is a migrated thread and some comments may be shown as answers.

Bug recursively mocking IEnumerable<T>

3 Answers 87 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Micah
Top achievements
Rank 1
Micah asked on 30 Jan 2014, 07:00 PM
01.using System;
02.using System.Collections.Generic;
03.using Microsoft.VisualStudio.TestTools.UnitTesting;
04.using Telerik.JustMock;
05. 
06.namespace JustMockTestProject
07.{
08.    public interface IFoo
09.    {
10.        IBar Bar { get; }
11.    }
12. 
13.    public interface IBar : IEnumerable<Object>
14.    {
15.        IBaz GetBaz();
16.    }
17. 
18.    public interface IBaz {}
19. 
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);
28. 
29.            Assert.IsNotNull(bar.GetBaz()); // passes
30.            Assert.IsNotNull(foo.Bar.GetBaz()); // fails
31.        }
32.    }
33.}


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.

3 Answers, 1 is accepted

Sort by
0
Kaloyan
Telerik team
answered on 04 Feb 2014, 09:19 AM
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.

Regards,
Kaloyan
Telerik
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.
0
s
Top achievements
Rank 1
answered on 10 Jul 2017, 01:53 PM
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
0
Kamen Ivanov
Telerik team
answered on 13 Jul 2017, 01:14 PM
Hello,

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.

Regards,
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
Tags
General Discussions
Asked by
Micah
Top achievements
Rank 1
Answers by
Kaloyan
Telerik team
s
Top achievements
Rank 1
Kamen Ivanov
Telerik team
Share this question
or