Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rhino Mock 3.6 Repository Expected #0, Actual#1

I'm using Rhino Mock 3.6 Repository and Nhibernate. But I'm getting ExpectationViolationException Expected#0, Actual #1. I've spent two days on it. I don't know what i'm doing wrong. Here is my code. I'm getting error on mockRepository.Save(user) line.

        var username = "abcdef";
        var mocks = new MockRepository();
        var validationResults = new ValidationResults();
        IDataQuery query = mocks.StrictMock<IDataQuery>();
        UserRepository mockRepository = mocks.StrictMock<UserRepository>(query);
        var user = mocks.StrictMock<User>();

        user.FirstName = "javed";
        user.LastName = "ahmad";
        user.UserName = "abc";
        user.Password = "password";
        user.Email = "[email protected]";
        user.IsActive = true;
        user.CreatedBy = 1000000;
        user.CreatedDate = DateTime.Today;
        user.ModifiedBy = 1000000;
        user.ModifiedDate = DateTime.Today;

        Expect.Call(user.Validate()).Return(validationResults);
        mocks.ReplayAll();

        mockRepository.Save(user);

Thanks in Advance.

Thanks Imran

like image 351
user585014 Avatar asked Oct 21 '25 17:10

user585014


2 Answers

You're using a StrickMock which means the only calls to be considered valid are the calls you set Expectations for. Since you didn't set an Expectation that Save would be called, you're getting an error.

like image 158
PatrickSteele Avatar answered Oct 27 '25 07:10

PatrickSteele


Normally this means RhinoMock expects you to call user.Validate() once, but you call the method twice. You can either check that you call the method only once or change

Expect.Call(user.Validate()).Return(validationResults);

to

Expect.Call(user.Validate()).Return(validationResults).Repeat.Twice();

like image 38
user779913 Avatar answered Oct 27 '25 05:10

user779913



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!