Redirect deals with an HttpContext which will be hard to test. I presume you're dealing with WebForms because otherwise MVC framework has a RedirectResult (where you can test that the action will redirect) which you cannot do in WebForms.
Tim On Wed, Jun 24, 2009 at 1:41 AM, chobo2 <[email protected]> wrote: > > Thanks both it is making more sense. I actually found that I could > just Wrap the Membership Provider around and I don't even need to make > a interface for it. However I do need one for FormsAuthentication. > > I am trying to test now RedirectFromLoginPage but I can't get it work. > Like I know you should only test the stuff your wrote and thats what I > am trying to do. I just want to see if it makes it to that part of my > login and to check that easily it is to see the use gets send back to > the Home page. > > Yet it seems the RedirectFromLoginPage happens after it goes back to > the view so I am not sure how to test this. > > On Jun 22, 1:19 pm, Tim Barcz <[email protected]> wrote: > > In this case I'd wrap the framework's membership provider behind an > > interface, for example IUserService. > > > > public interface IUserService > > { > > bool ValidateUser(string username, string password); > > > > } > > > > public class UserService : IUserService > > { > > public bool ValidateUser(string username, string password) > > { > > return Membership.ValidateUser(username, password); > > } > > > > } > > > > Any place you'd use membership service, instead have a reference to > > IUserService and make calls on it instead. This method allows you to > > provide a fake value (what we refer to mock or stub) in any code that > would > > need to use Membership services. > > > > Does that help? > > > > > > > > On Sun, Jun 21, 2009 at 10:50 PM, chobo2 <[email protected]> wrote: > > > > > Hmm > > > > > 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 > > > > -- > > Tim Barcz > > ASPInsiderhttp://timbarcz.devlicio.ushttp://www.twitter.com/timbarcz > > > -- Tim Barcz ASPInsider http://timbarcz.devlicio.us http://www.twitter.com/timbarcz --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
