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

How to Mock Poco Property Behaviour from Interface

5 Answers 48 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Andre
Top achievements
Rank 1
Andre asked on 16 Jun 2011, 06:57 PM
I dug through the forums and found this post
http://www.telerik.com/community/forums/justmock/general-discussions/how-to-set-up-property-assignment.aspx

I have the Free Edition, Telerik.JustMock.dll File Version 2011.1.315.0
The promise of a build available next week in August 2010, doesn't prove to work with Behavior.CallOriginal.  (an empty Constructor works though).

Here is a sample of my TestMethod
public interface ISamplePoco
{
  string Name { get; set; }
}
 
[TestMethod]
public void GenerateMockWithPocoPropertyBehaviour()
{
  // arrange
  var target = Mock.Create<ISamplePoco>(Behavior.CallOriginal);   
  // act
  target.Name = "Dude";
  target.Name += "s";   
  // assert
  Assert.AreEqual("Dudes", target.Name);
}

I tried the above code with no parameters for the constructor, all 3 behaviour enums for the Constructor, but nothing works.
I tried to do some code where I stored the name parameter as a local variable to the test and implement my own logic, but I can't seem to get the actual value in ArrangeSet.  I tried to do something like:

string name = string.Empty;
Mock.Arrange(() => target.Name).Returns(name);
Mock.ArrangeSet((string val) => { name = val; }).IgnoreArguments();

But there is nothing like that. Is there another solution?
Thanks

5 Answers, 1 is accepted

Sort by
0
Andre
Top achievements
Rank 1
answered on 21 Jun 2011, 10:07 PM
I would like a response from someone on this.  I think waiting 5 days is sufficient time to wait for a response.

Actually responding would be most appreciated.
Here is some options for you guys to respond to me with
  • it should work, we'll tell you what you are doing wrong.
  • it works on my machine (i have code you can clearly copy and paste into visual studio).
  • what you are doing is wrong and against windows standards, don't do it.
  • we are looking into putting this feature in a future version, you'll have to wait.
0
Ricky
Telerik team
answered on 22 Jun 2011, 01:59 PM
Hi Andre,

Sorry for the late reply. I am actually working on this currently and in a day or two i will be able to send you an internal build. In the meantime, you could open up a support ticket so that we can send you the build there (since we can't send internal build in public forum).

Ideally, the following will work as expected when the fix is done.


// arrange
var target = Mock.Create<ISamplePoco>();
 
// act
target.Name = "Dude";
target.Name += "s";
 
// assert
Assert.AreEqual("Dudes", target.Name);

Here, i re-wrote the test removing the Behavior.CallOriginal since there is no base to call for in interface.

Sorry for any inconvenience.


Finally, here is the issue to follow:
http://www.telerik.com/support/pits.aspx#/public/justmock/6598


KInd Regardds,
Mehfuz
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items
0
Jeff
Top achievements
Rank 1
answered on 17 Aug 2011, 04:09 PM
I saw that this issue was resolved in the public issue tracker, but is not scheduled until the next release in the fall.  Is an internal build available to download so that I can test out this functionality?
0
Andre
Top achievements
Rank 1
answered on 17 Aug 2011, 04:42 PM
The issue is fixed.  It passes my test assuming the version written below.
The current downloadable release (2011.2.713.2) updated on July 13th fixed this issue.

I believe my original issue was with the 2011 Q1 release? but the Q2 release in July fixed it.
Hope that helps
-Andre
0
Jeff
Top achievements
Rank 1
answered on 17 Aug 2011, 04:45 PM
Andre, thanks for the info!  I didn't realize that the fix was already incorporated.  I'll have to try it out.
Tags
General Discussions
Asked by
Andre
Top achievements
Rank 1
Answers by
Andre
Top achievements
Rank 1
Ricky
Telerik team
Jeff
Top achievements
Rank 1
Share this question
or