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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:46:34+00:00 2026-06-17T07:46:34+00:00

We have a base class providing some default implementation for INotifyPropertyChanged (this class is

  • 0

We have a base class providing some default implementation for INotifyPropertyChanged (this class is used by many other classes and cannot be easily changed):

public class ObservableBase : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    // this is virtual so derived classes can override it (rarely used, but it is used)
    protected virtual void OnPropertyChanged(string propertyName)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null)
        {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

Now I have an interface and an abstract base class deriving from ObservableBase and implementing that interface providing some default implementations (mainly for the properties):

public interface INamedTrigger
{
    string Name { get; }
    void Execute();
}

public abstract class ObservableNamedTriggerBase : ObservableBase, INamedTrigger
{
    private string _Name;
    public string Name
    {
        get { return _Name; }
        set { _Name = value; OnPropertyChanged("Name"); }
    }

    public abstract void Execute();
}

Now I want to unit test the default implementations of ObservableNamedTriggerBase (using NUnit and RhinoMocks):

[TestFixture]
public class ObservableNamedTriggerBaseTest
{
    [Test]
    public void TestNameChangeRaisesPropertyChanged()
    {
        var prop = "";
        var mocks = new MockRepository();
        var namedBase = mocks.PartialMock<ObservableNamedTriggerBase>();
        namedBase.PropertyChanged += (s, e) => prop = e.PropertyName;
        namedBase.Name = "Foo";
        Assert.AreEqual("Name", prop);
    }
}

Unfortunately this test fails as Rhino seems to override the virtual OnPropertyChanged method from ObservableBase.

This SO question and the Rhino docs indicate that PartialMock should exactly not do this. On the other hand the answer to this SO question indicates that Rhino always overrides virtual methods regardless of the type of mock.

So is the documentation wrong? And how do I go about testing this correctly?

Update: If I create my own mock class providing dummy implementations for just the abstract methods then the test passes but I’d like to use Rhino mocks to save me the work of exactly doing that.

  • 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-06-17T07:46:35+00:00Added an answer on June 17, 2026 at 7:46 am

    Not sure which version are you using, but it seems that you’re mixing RR (Record-Replay) syntax usage with more recent AAA (Arrange-Act-Assert). Basically, doing this:

    var repo = new MockRepository();
    var mock = repo.PartialMock<ObservableNamedTriggerBase>();
    

    Requires you also to at least do this:

    repo.ReplayAll();
    

    Lack of which, will cause mocks to misbehave (a call to repo.Record() might be needed if you’re setting expectations/stubbing too). This is unnecessary effort considering modern syntax is available (starting with Rhino 3.5):

    // no repository needed at all
    var mock = MockRepository.GeneratePartialMock<ObservableNamedTriggerBase>();
    

    New static methods on MockRepository are taking care of the record-replay setup under the hood.

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

Sidebar

Related Questions

I have a c# class providing some simple classes and some base class extensions
I have a base class with many sub-classes, and a generic function to cache
I have base class BaseClass and derived classes DerivedA , DerivedB , and DerivedC
I have a base class like this: public class BaseResponse { public string ErrorMessage
I have a base class called Panel, where some information about a window is
I'm trying to code the following situation: I have a base class providing a
I have a base Color class that looks something like this. The class is
I have a base class, Token. It has no implementation and as such acts
Imagine you have a derived class, where the base class is something you cannot
I have a case where my base class' constructor throws exceptions when providing invalid

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.