On Sun, Jun 21, 2009 at 11:16 PM, chobo2<[email protected]> wrote:
>...
> So I tested my validation through unit tests now I am at this part
>
>  bool valid = authenticate.VerifyUser(loginValidation.UserName,
> loginValidation.Password);
>  if (valid == false)
>
> So how would I make a mockup that would make sure that valid would be
> true?
>

You'd need to be able to replace the authenticate object with a mock
object (well, in this case it would technical be a stub, but let's not
go into that for now :)). So somewhere in your test code:

authenticate = MockRepository.GenerateMock<IAuthentication>();
//Replace IAuthentication with whatever the actual class/interface is
authenticate
  .Stub( auth => auth.VerifyUser(Arg<string>.Is.Anything,
Arg<string>.Is.Anything))
  .Return(true);

Then when you call your Login() method from your unit test,
authenticate will return the value you are expecting.

You can also hand-code your mock:

class AlwaysVerifiedAuth : IAuthentication {
  public bool VerifyUser(String username, String password) { return true; }
}

I seem to remember Stephen Walther (http://stephenwalther.com/blog/)
having a good series on testing ASP.NET MVC, but can't find the posts
at the moment.

Regards,
David

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Rhino.Mocks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/RhinoMocks?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to