[Prev] Thread [Next]  |  [Prev] Date [Next]

[RhinoMocks] Re: Where can I download the source code from the tutorial? chobo2 Mon Jun 22 05:04:20 2009


Ok I will try to do a couple tests by hand to start off with I guess
to just a get a feel for it. I still don't get how to do them though.

Can someone walk me through like step by step how to test that section
of my code?

This is the verifyUser method from the authenticate class

   public bool VerifyUser(string userName, string password)
            bool valid = Membership.ValidateUser(userName, password);
            return valid;

It really does not need to be tested. Otherwise that basically is all
my code.

On Jun 22, 9:12 am, David Tchepak <[EMAIL PROTECTED]> wrote:
> 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