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

Can't arrange method call on different object of same type after invocation.

2 Answers 57 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Erik
Top achievements
Rank 1
Erik asked on 30 Apr 2012, 08:56 PM
I have an odd case where I have multiple tests running on the same class. For most of these tests I am mocking a method on the class to return controlled results. One of the tests actually uses the normal version of the method. When the test that uses the concrete version of the method call runs first then I am unable to mock the method in the other tests.

Here is some example code depicting my issue:
var first = new MyClass();
var second = new MyClass();
second.DoSomething();
Mock.Arrange(() => first.DoSomething()).Returns(new List<IDataItem>);
first.DoSomething();

In the code above, first will actually call the method rather than using the mock. Is this a bug? It seems like a bug. Is there a work around?

2 Answers, 1 is accepted

Sort by
0
Erik
Top achievements
Rank 1
answered on 01 May 2012, 02:53 PM
0
Ricky
Telerik team
answered on 02 May 2012, 05:31 PM
Hi Erik,

Its great that you’ve got what you are looking for. However, should you have any other questions please don’t hesitate to contact us.



Kind Regards
Mehfuz
the Telerik team

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

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