If I have this test
Expect.Call(_session.Single<Admin>(x => x.Email == userModel.Email)).Repeat.Once().Return(null);
Telling me
Rhino.Mocks.Exceptions.ExpectationViolationException : ISession.Single(x => (x.Email == value(Enquete.Test.Controllers.MemberControllerTest+<>c__DisplayClassb).userModel.Email)); Expected #1, Actual #0.
It fails but if I add .IgnoreArguments() it works. Is it possible to test using lambda? If I debug I can see that my Email is the same.
Here's the full test :
[Test]
public void Register_Post_ReturnRedirectOnSuccess()
{
_builder.InitializeController(_controller);
var userModel = TestHelper.CreateMemberModel();
var returnMemberRole = "Member";
var tempPassword = "Val1dPass";
var member = TestHelper.CreateMember(userModel);
var emailSubscription = "subscription@corpiq.com";
var subjectNotification = "sujet du meessaaggee";
var mailUseSSL = "true";
var message = userModel.FirstName + " " + userModel.LastName + " s'est inscrit au système d'enquête en ligne, veuillez confirmer son inscription.";
member.PasswordExpire = DateTime.Now.AddDays(-1);
member.Phone = userModel.Phone;
member.MemberNumber = userModel.MemberNumber;
member.PasswordExpire = DateTime.Now.AddDays(-1);
Expect.Call(_session.Single<Admin>(x => x.Email == userModel.Email)).Repeat.Once().Return(null);
Expect.Call(_session.Single<Member>(x => x.Email == userModel.Email)).Repeat.Once().IgnoreArguments().Return(null);
Expect.Call(_authService.GeneratePassword()).Repeat.Once().Return(tempPassword);
Expect.Call(_authService.MemberRole).Repeat.Once().Return(returnMemberRole);
Expect.Call(_authService.RegisterUser(userModel.Email, tempPassword, returnMemberRole)).Repeat.Once().Return(MembershipCreateStatus.Success);
_session.Add(member);
LastCall.Repeat.Once();
_session.CommitChanges();
LastCall.Repeat.Once();
Expect.Call(_configHelper.GetValue("emailSubscription")).Repeat.Once().Return(emailSubscription);
Expect.Call(_configHelper.GetValue("subjectNotification")).Repeat.Once().Return(subjectNotification);
Expect.Call(_configHelper.GetValue("MailUseSSL")).Repeat.Once().Return(mailUseSSL);
_mailHelper.SendMail(emailSubscription, subjectNotification, message, Convert.ToBoolean(mailUseSSL));
LastCall.Repeat.Once();
_mock.ReplayAll();
var result = _controller.Register(userModel);
_mock.VerifyAll();
result.AssertActionRedirect().ToAction<MemberController>(c => c.RegisterSuccess());
}
Thank you!