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

Invoking the constructor of a mocked object

1 Answer 65 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Asim
Top achievements
Rank 1
Asim asked on 28 Jul 2011, 08:41 PM
Hi!

Does JustMock allow invoking the actual constructor of the mocked object, and passing it certain argument values, similar to how TypeMock does (please see TypeMock documentation link below)?

http://docs.typemock.com/Isolator/##typemock.chm/Documentation/ConstructorArgumentsAAA.html

Thanks,
Asim

1 Answer, 1 is accepted

Sort by
0
Ricky
Telerik team
answered on 29 Jul 2011, 09:36 AM
Hi Asim,

Thanks again for pointing that to us. For JustMock you don’t have to specify explicitly that constructor shouldn’t be mocked rather by default the behavior is that it invokes the original (Like Moq).

[TestMethod]
public void PassArgumentsToConstructor_FakeMethods()
{
    var fake = Mock.Create<Person>(x => new Person(100));
    Assert.AreEqual(100, fake.Age);
}

However there is a point in the documentation on how you can mock the constructor, even if you don’t pass the instance via dependency Injection. For that i am creating a task and giving you some telerik points for it as well :-).
 
Here is the task for you to monitor:
http://www.telerik.com/support/pits.aspx#/public/justmock/7167

Kind Regards,
Mehfuz
the Telerik team

 

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

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