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 631683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:59:34+00:00 2026-05-13T19:59:34+00:00

I am using RhinoMocks, and I have a Mock which has a property I

  • 0

I am using RhinoMocks, and I have a Mock which has a property I need to behave as a real property – updating its value when set, and also trigger PropertyChanged when the property is changed.

The interface of the mocked object is in essence this:

public interface IFoo
{
    event PropertyChangedEventHandler PropertyChanged;
    int Bar { get; set; }
}

When creating the mock I set PropertyBehavior – which makes it actually update its faked value:

var mocks = new MockRepository();
var fakeFoo = mocks.DynamicMock<IFoo>();
SetupResult.For(fakeFoo.Bar).PropertyBehavior();

But when I update the value PropertyChanged isn’t triggered. Now, the interface doesn’t implement the INotifyPropertyChanged interface as it is an interface.. How can I make PropertyChanged triggered?

  • 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-13T19:59:35+00:00Added an answer on May 13, 2026 at 7:59 pm

    The role of listener and mutator may sometimes be combined in the same class (e.g. in an adapter), but both roles should not be tested together.

    In one test, you merely verify that your listening class reacts to the PropertyChanged event as designed. You don’t care about what caused the property to change in that test:

    [Test]
    public void Updates_Caption_when_Bar_PropertyChanged()
    {
       var foo = MockRepository.GenerateStub<IFoo>();
       foo.Bar = "sometestvalue1";
       var underTest = new UnderTest(foo);
    
       // change property and raise PropertyChanged event on mock object
       foo.Bar = "sometestvalue2";
       foo.Raise(x=>x.PropertyChanged+=null,
           foo,
           new PropertyChangedEventArgs("Bar"));
    
       // assert that the class under test reacted as designed
       Assert.AreEqual("sometestvalue2", underTest.Caption);
    
       // or if the the expected state change is hard to verify, 
       // you might just verify that the property was at least read
       foo.AssertWasCalled(x => { var y = foo.Bar; } );
    }
    

    In another test, you verify that your class plays its mutator role as designed:

    [Test]
    public void Reset_clears_Foo_Bar()
    {
       var foo = MockRepository.GenerateStub<IFoo>();
       foo.Bar = "some string which is not null";
       var underTest = new UnderTest(foo);
    
       underTest.Reset();
    
       // assert that the class under test updated the Bar property as designed
       Assert.IsNull(foo.Bar);
    }
    

    This way, it is never necessary to put real logic into your mock objects like you are trying to do. This does require that you design your classes for testability; it is hard to add such tests to existing classes. Hence the practice of test driven development.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a mock object in RhinoMocks to represent a class that makes
ADO.NET has the notorious DataRow class which you cannot instantiate using new. This is
Using RhinoMocks, I have a catch-22 situation: I want to verify that a method
So I have a bunch of internal classes which I am trying to mock
using ASP.NET MVC, I have a Model, to which I'm attaching attributes so that
using linux commands, I have a quoted csv file which I sorted by first
I am using NHibernate and Rhinomocks and having trouble testing what I want. I
Using online interfaces to a version control system is a nice way to have
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Are there any ways to mock a WCF client proxy using Rhino mocks framework

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.