Exemple #1
0
        public void Setup()
        {
            context = new AuthorizationContext
            {
                HttpContext = new TestControllerBuilder().HttpContext
            };

            userRepositoryFactory = MockRepository.GenerateStub <IRepositoryFactory <User> >();
            userRepository        = MockRepositoryBuilder.CreateUserRepository();
            userRepositoryFactory.Stub(x => x.Resolve()).Return(userRepository).Repeat.Any();

            formsAuth = MockRepository.GenerateStub <IFormsAuthentication>();
            filter    = new AuthenticateFilter(formsAuth, userRepositoryFactory);

            originalPrincipal = Thread.CurrentPrincipal;
        }
Exemple #2
0
        public void SetUp()
        {
            // you have to be an administrator to access the user controller
            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("admin"), new[] { "Administrator" });

            userRepository = MockRepositoryBuilder.CreateUserRepository();

            var roleRepository = MockRepositoryBuilder.CreateRoleRepository();

            userService = MockRepository.GenerateStub <IUserService>();
            userService.Stub(x => x.HashPassword(Arg <string> .Is.Anything)).Do(new Func <string, string>(s => s + "HASHED"));

            userController = new UserController(userRepository, roleRepository, userService);
            testContext    = new ControllerTestContext(userController);


            // setup the querystring to return an empty name value collection by default
            testContext.TestContext.Request.Expect(r => r.QueryString).Return(new NameValueCollection());
        }