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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:21:57+00:00 2026-05-11T19:21:57+00:00

I currently have a test which tests the presenter I have in the MVP

  • 0

I currently have a test which tests the presenter I have in the MVP model. On my presenter I have a property which will call into my View, which in my test is mocked out. In the Initialization of my test, after I set my View on the Presenter to be the mocked View, I set my property on the Presenter which will call this method.

In my test I do not have an Expect.Call for the method I invoke, yet when I run I get this Rhino mock exception:

Rhino.Mocks.Exceptions.ExpectationViolationException: IView.MethodToInvoke(); Expected #1, Actual #0..

From what I understand with Rhino mocks, as long as I am invoking on the Mock outside the expecting block it should not be recording this. I would imagine the test to pass. Is there a reason it is not passing?

Below is some code to show my setup.

public class Presenter
{
    public IView View;

    public Presenter(IView view)
    {
        View = view
    }
    private int _property;
    public int Property
    get { return _property;}
    set
    {
       _property = value;

       View.MethodToInvoke();
    }
}

… Test Code Below …

[TestInitialize]
        public void Initilize()
        {
            _mocks = new MockRepository();
            _view = _mocks.StrictMock<IView>();
            _presenter = new Presenter(_view);
            _presenter.Property = 1;            
        }
[TestMethod]
        public void Test()
        {
            Rhino.Mocks.With.Mocks(_mocks).Expecting(delegate
            {                
            }).Verify(delegate
            {
                _presenter.SomeOtherMethod();
});
        }
  • 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-11T19:21:57+00:00Added an answer on May 11, 2026 at 7:21 pm

    Why in the world would you want to test the same thing each time a test is run?

    If you want to test that a specific thing happens, you should check that in a single test.

    The pattern you are using now implies that you need to
    – set up prerequisites for testing
    – do behavior
    – check that behavior is correct
    and then repeat that several times in one test

    You need to start testing one thing for each test, and that help make the tests clearer, and make it easier to use the AAA syntax.

    There’s several things to discuss here, but it certainly would be clearer if you did it something like:

    [TestMethod]
    ShouldCallInvokedMethodWhenSettingProperty()
    {
       var viewMock = MockRepository.GenerateMock<IView>()
    
       var presenter = new Presenter(viewMock);
    
       presenter.Property = 1;
    
       viewMock.AssertWasCalled(view => view.InvokedMethod());
    
    }
    

    Read up more on Rhino Mocks 3.5 syntax here: http://ayende.com/Wiki/Rhino+Mocks+3.5.ashx

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

Sidebar

Related Questions

I have a test fixture class which is currently used by many tests. #include
We currently have a suite of integration tests that run via MbUnit test suites.
We are currently using unit tests to test our project. We have the majority
I currently have a model set up like so: I have a Test class
Note: I'm using Google Chrome Currently I have this test page http://www.evecakes.com/doodles/canvas_size_issue.htm It should
I have a PHPUnit test suite that is currently causing a fatal error due
I have Eclipse plug-in and junit tests for it, which are using jMock library.
I currently have a table which has these columns: id (INT) parent_id (INT) col0
I have written a large script to run a series of tests. Each test
We currently have a situation where several tests are failing. Someone is working on

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.