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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:44:02+00:00 2026-05-26T23:44:02+00:00

I created a test recently around a property with only a setter, today I

  • 0

I created a test recently around a property with only a setter, today I modified the property to include a getter in the interface and the test case then failed.

I have created a boiled down example of it working and failing which is below.
I am not sure if its my ignorance or maybe a bug in Rhino.Mocks or NUnit that is presenting this behaviour.

I would appreaciate any input.

I am using Visual Studio 2010 on Windows 7 64bit.
I am using Rhino.Mocks 3.6 (tried 2.6 build 21 as well for same results)
I am using NUnit-2.5.10.11092

using NUnit.Framework;
using Rhino.Mocks;
using Rhino.Mocks.Constraints;

namespace PropertyTestFailure
{
    public interface ITest
    {
        int SetOnlyProperty { set; }
        int SetGetProperty { get;  set; }
    }

    /// <summary>
    /// The property with getter fails.
    /// It appears purely adding the getter that breaks things.
    /// </summary>
    [TestFixture]
    public class TestCase
    {
        [Test]
        public void SetOnlyPropertyWorks()
        {
            var mockTest = MockRepository.GenerateStub<ITest>();

            mockTest.SetOnlyProperty = 23;

            mockTest.AssertWasCalled(x => x.SetOnlyProperty
                = Arg<int>.Matches(new PredicateConstraint<int>(y => y == 23)));
        }

        [Test]
        public void SetGetPropertyFails()
        {
            var mockTest = MockRepository.GenerateStub<ITest>();

            mockTest.SetGetProperty = 24;

            mockTest.AssertWasCalled(x => x.SetGetProperty
                = Arg<int>.Matches(new PredicateConstraint<int>(y => y == 24)));
        }
    }
}

The failure report message.

SetGetPropertyFails : FailedRhino.Mocks.Exceptions.ExpectationViolationException : ITest.set_SetGetProperty(Predicate (TestCase.<SetGetPropertyFails>b__5(obj);)); Expected #1, Actual #0.
at Rhino.Mocks.RhinoMocksExtensions.AssertWasCalled(T mock, Action`1 action, Action`1 setupConstraints)
at PropertyTestFailure.TestCase.SetGetPropertyFails() in TestCase.cs: line 40 
  • 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-26T23:44:03+00:00Added an answer on May 26, 2026 at 11:44 pm

    Change

    MockRepository.GenerateStub<ITest>();
    

    to

    MockRepository.GenerateMock<ITest>();
    

    Generally if you want to assert on a behavior with an expectation, you will want a mock, not a stub. A stub will create its own getters and setters that can’t verify behavior.

    You can also simplify your AssertWasCalled to:

    mockTest.AssertWasCalled(x => x.SetGetProperty = 24);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a program called test: #include<stdlib.h> #include<iostream> int main() { std::cout<<system(..\\add\\debug\\add.exe 4 8);
i have recently created a test paypal account, and also verified all the details,
I have recently installed Expression Blend 4 and created a test Silverlight 4 project.
I have created a test table in MySQL and would like to insert 10
In a Test project in Visual Studio 2008 (Pro), I created a Test project,
In showing a colleague how to use SVN yesterday, we created a test folder
I created a simple test page on my website www.xaisoft.com and it had no
I created a simple test with SendKeys, and tried both SendWait and Send. Private
I've created some MbUnit Test Fixtures that have SetUp methods marked with the SetUp
I have created a simple test form with FormBorderStyle = FixedToolWindow by default and

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.