Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4623486
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:59:39+00:00 2026-05-22T02:59:39+00:00

My following straight forward test doesn’t pass (Though I feel it should). Either I

  • 0

My following straight forward test doesn’t pass (Though I feel it should). Either I am missing something or is not clear of Property.value constraint. please help me in understanding concept of property.value constraint.

public interface ISomeInterface
{
     void SomeMethod(string x, string y);
}

public class SomeClassTest
{

[Test]

public void SomeMethodTest()
    {

        MockRepository mocks = new MockRepository();
        ISomeInterface mockservice = mocks.StrictMock<ISomeInterface>();
        using (mocks.Record())
        {
            mockservice.SomeMethod("xValue", "yValue");
            LastCall.Constraints(Property.Value("x", "xValue"),
                                 Property.Value("y", "yValue"));
        }
        mockservice.SomeMethod("xValue", "yValue");
        mocks.Verify(mockservice);
    }
}

Exception raised:

Rhino.Mocks.Exceptions.ExpectationViolationException : ISomeInterface.SomeMethod(“xValue”, “yValue”); Expected #0, Actual #1.
ISomeInterface.SomeMethod(property ‘x’ equal to xValue, property ‘y’ equal to yValue); Expected #1, Actual #0.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:59:40+00:00Added an answer on May 22, 2026 at 2:59 am

    This sample class illustrates the options for asserting methods were called with appropriate properties:

    public class UsesThing
    {
       private IMyThing _thing;
    
       public UsesThing(IMyThing thing)
       {
          _thing = thing;
       }
    
       public void DoTheThing(int myparm)
       {
          _thing.DoWork(myparm, Helper.GetParmString(myparm));
       }
    
       public void DoAnotherThing(int myparm)
       {
           AnotherThing thing2 = new AnotherThing();
           thing2.MyProperty = myparm + 2;
           _thing.DoMoreWork(thing2)
        }
    }
    

    Using simple values for assertions may work for methods like the DoTheThing method which uses value types:

    [Test]
    public void TestDoTheThing()
    {
        IMyThing thing = MockRepository.GenerateMock<IMyThing>();
        UsesThing user = new UsesThing(thing);
    
        user.DoTheThing(1);
    
        thing.AssertWasCalled(t => t.DoWork(1, "one");
    }
    

    However, if you need to create an object in your method and pass it as a parameter like in the DoAnotherThing method, this approach will not work since you will not have a reference to the object. You have to check the property values of the unknown object, like this:

    [Test]
    public void TestDoAnotherThing()
    {
        IMyThing thing = MockRepository.GenerateMock<IMyThing>();
        UsesThing user = new UsesThing(thing);
    
        user.DoAnotherThing(1);
    
        thing.AssertWasCalled(t => t.DoMoreWork(null), t => t.IgnoreArguments().Constraints(Property.Value("MyProperty", 3))));        
    }
    

    The new Rhino syntax would look like the following, but I am crashing VS 2008 when I use it:

    thing.AssertWasCalled(t => t.DoMoreWork(Arg<AnotherThing>.Matches(Property.Value("MyProperty", 3))));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This should be fairly straight forward but is proving not to be. I want
I've a straight forward question, I think I'm missing some point. My test app
Should be straight-forward, right? We have the following listener at our disposal. chrome.tabs.onRemoved.addListener(function (tabId,
I'm wondering why the following piece of code doesn't work, looks pretty straight-forward, am
The installation for clearance seems very straight forward ( https://github.com/thoughtbot/clearance ). I'm following in
Give the following (straight-forward) code: public class pr1 { public static void f1(){ long
I am writing the following code on boost's program_options (version 1.42). This seems straight-forward
Seems fairly straight forward and simple, I am doing the following and getting an
I'm following a tutorial here It's fairly straight forward and simple, only 2 steps.
Extracting the href value from the following sample HTML code is straight forward if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.