How to Mock Poco Property Behaviour from Interface

6 posts, 0 answers
  1. Andre
    Andre avatar
    4 posts
    Member since:
    Jun 2011

    Posted 16 Jun 2011 Link to this post

    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
  2. Andre
    Andre avatar
    4 posts
    Member since:
    Jun 2011

    Posted 21 Jun 2011 Link to this post

    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.
  3. DevCraft R3 2016 release webinar banner
  4. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 22 Jun 2011 Link to this post

    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
  5. Jeff
    Jeff avatar
    4 posts
    Member since:
    Dec 2007

    Posted 17 Aug 2011 Link to this post

    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?
  6. Andre
    Andre avatar
    4 posts
    Member since:
    Jun 2011

    Posted 17 Aug 2011 Link to this post

    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
  7. Jeff
    Jeff avatar
    4 posts
    Member since:
    Dec 2007

    Posted 17 Aug 2011 Link to this post

    Andre, thanks for the info!  I didn't realize that the fix was already incorporated.  I'll have to try it out.
Back to Top
DevCraft R3 2016 release webinar banner