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

AutoMock Abstract Class

1 Answer 57 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Nick
Top achievements
Rank 1
Nick asked on 21 Aug 2014, 07:40 AM
Hi, is it possible to use MockingContainer<T> where T is an abstract class, such as the following:

01.public abstract class SimpleBaseClass
02.{
03.    private readonly IService service;
04.    protected SimpleBaseClass(IService service)
05.    {
06.        this.service = service;
07.    }
08.    public void CallServiceMethod()
09.    {
10.        this.service.DoLotsOfThings();
11.    }
12.}

I've tried the following, the latter works as expected. 
01.[TestMethod]
02.public void AutoMock_AbstractClass_CallsMethod()
03.{
04.    var container = new MockingContainer<SimpleBaseClass>();
05.    //container.Bind<SimpleBaseClass>().ToMock(); // Still fails :(
06.    container.Arrange<IService>(s => s.DoLotsOfThings()).MustBeCalled();
07. 
08.    container.Instance.CallServiceMethod();
09. 
10.    container.AssertAll();
11.}
12. 
13.[TestMethod]
14.public void CreateMock_AbstractClass_CallsMethod()
15.{
16.    var service = Mock.Create<IService>();
17.    var target = Mock.Create<SimpleBaseClass>(Behavior.CallOriginal, service);
18. 
19.    target.CallServiceMethod();
20. 
21.    service.Assert(s => s.DoLotsOfThings());
22.}

I've tried configuring with AutoMockSettings using CallOriginal, but it just seems like NInject always jumps in and fails to find a suitable constructor.

1 Answer, 1 is accepted

Sort by
0
Tsvetomir
Telerik team
answered on 22 Aug 2014, 11:55 AM
Hello Nick,

Yes, this is known limitation of JustMock. I've added this as a feature request in our feedback portal, so you can vote for it. As a workaround I would suggest in the test to call the implementation of the abstract class with public constructor in it.

I hope this helps.

Kind Regards,
Tsvetomir
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
General Discussions
Asked by
Nick
Top achievements
Rank 1
Answers by
Tsvetomir
Telerik team
Share this question
or