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

common property value not being applied to base interfaces

2 Answers 62 Views
JustMock Free Edition
This is a migrated thread and some comments may be shown as answers.
Sainath
Top achievements
Rank 1
Sainath asked on 24 May 2017, 02:23 PM

Hi,

 

I have 2 interfaces (I1 and I2) that have a property called FileName. Another interface is inheriting these two interfaces. Let us call it I3.In I3, I am using new modifier (this is C#) so that in my code I do not get FileName property displayed twice and prevent compiler ambiguity errors.

When I mock interface I3 and set the FileName value, this value does not propagate to interfaces I1 and I2. This is not an issue in my actual code. 

I have attached a sample pictures of the code. The first assert works. Second and third fail.

Assert.IsTrue(toTest.FileName == @"test file name", "FileName missing"); //1
Assert.IsTrue((toTest as Interface1).FileName== @"test file name","FileName missing"); //2
Assert.IsTrue((toTest as Interface2).FileName == @"test file name", "FileName missing"); //3

Am I doing something wrong OR is this a bug with the lite version of JustMock?

Thank you for time taken to read and any direction to resolve my challenge.

Sainath

 

2 Answers, 1 is accepted

Sort by
0
Kamen Ivanov
Telerik team
answered on 29 May 2017, 10:32 AM
Hi Sainath,

Thank you for your interest in JustMock.

The behavior that you experience is expected because mocked instances act differently from the real instances.

JustMock creates a proxy object of the type that you are mocking and then uses the specified expressions to substitute them with the mocked behavior. In your case only thing that is mocked is calling FileName from the created proxy that's why it could only substitute it with the mocked value. The other two expressions "(toTest as Interface1).FileName" and "(toTest as Interface2).FileName" are obscure and cannot be substituted.
Adding them to the mock object will fix the failing test.
Mock.Arrange(() => (toTest as Interface1).FileName).Returns("test file name");
Mock.Arrange(() => (toTest as Interface2).FileName).Returns("test file name");

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
0
Sainath
Top achievements
Rank 1
answered on 31 May 2017, 07:43 PM
Thank you for the clarification Kamen. What you suggested did work out. 
Tags
JustMock Free Edition
Asked by
Sainath
Top achievements
Rank 1
Answers by
Kamen Ivanov
Telerik team
Sainath
Top achievements
Rank 1
Share this question
or