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

  • Home
  • SEARCH
  • 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 7570015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:18:40+00:00 2026-05-30T15:18:40+00:00

Getting Error while running rhinomock test method : Test method TestProject1.UnitTest2.TestMethod1 threw exception: Rhino.Mocks.Exceptions.ExpectationViolationException:

  • 0

Getting Error while running rhinomock test method : Test method TestProject1.UnitTest2.TestMethod1 threw exception:
Rhino.Mocks.Exceptions.ExpectationViolationException: ITestInterface.Method1(5); Expected #1, Actual #0.

My code looks like:-

namespace ClassLibrary1
{
    public interface ITestInterface
    {
        bool Method1(int x);

        int Method(int a);
    }

    internal class TestClass : ITestInterface
    {

        public bool Method1(int x)
        {
            return true;
        }

        public int Method(int a)
        {
            return a;
        }
    }
}

And my test looks something like:-

using ClassLibrary1;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Rhino.Mocks;

namespace TestProject1
{
    [TestClass]
    public class UnitTest2
    {
        [TestMethod]
        public void TestMethod1()
        {
            ITestInterface mockProxy = MockRepository.GenerateMock<ITestInterface>();

            TestClass tc = new TestClass();
            bool result = tc.Method1(5);           

            Assert.IsTrue(result);


            mockProxy.AssertWasCalled(x => x.Method1(5));

        }
    }
}

Any help appreciated.

  • 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-30T15:18:42+00:00Added an answer on May 30, 2026 at 3:18 pm

    You expect ITestInterface.Method1 to be called, but it never does.
    You don’t use your mockProxy at all in the test code – you just create it and you create your own instance, but there’s no relation between the two of them.
    Your TestClass is not dependant upon any interface that you want to mock, similar example that does use the mock would be:

    internal class TestClass
    {
        private ITestInterface testInterface;
    
        public TestClass(ITestInterface testInterface)
        { 
           this.testInterface = testInterface;
        }
    
        public bool Method1(int x)
        {
            testInterface.Method1(x);
            return true;
        }
    
    }
    
    [TestClass]
    public class UnitTest2
    {
        [TestMethod]
        public void TestMethod1()
        {
            ITestInterface mockProxy = MockRepository.GenerateMock<ITestInterface>();
    
            TestClass tc = new TestClass(mockProxy);
            bool result = tc.Method1(5);           
    
            Assert.IsTrue(result);
    
    
            mockProxy.AssertWasCalled(x => x.Method1(5));
        }
    }
    

    I think you should read more about using Rhino Mocks, e.g. Rhino Mocks AAA Quick Start?

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

Sidebar

Related Questions

I am getting undefined method [] for true:TrueClass error while running the rake task
hiii i am getting this error while running test for my fluent nhibernate application.
I am getting the following error while running my MVC application, which uses the
I'm getting an Undefined Instruction error while running an embedded system, no coprocessor, no
Im getting following error while running the query. org.hibernate.hql.ast.QuerySyntaxException: expecting CLOSE, found 'LIMIT' near
I am getting following error while running a JSP page: org.apache.jasper.JasperException: jsp:getProperty for bean
I have a problem running RoR project. I am getting this error while running
I am getting the following error message while running .net 3.5 applciation Your step-into
Getting Fatal Error while running bin/hadoop namenode -format Using Windows 7 operating system, Under
I am getting an error while running naive bayes classifier in R. I am

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.