public void InitializeTest()
        {
            FakeModuleProvider provider = new FakeModuleProvider();

            MockAuthenticationModule = MockRepository.GenerateMock <WSFederationAuthenticationModule>();
            provider.ModuleToReturn  = MockAuthenticationModule;
            AuthenticationUtility.SetModuleProvider(provider);
            TestUser = new User {
                Id = 20, UserKey = "3u2e2"
            };
            Identity = new ClaimsIdentity();
            MockHttpContext.Request.Expect(m => m.RequestContext).Return(new RequestContext(MockHttpContext, new RouteData()));
            MockHttpContext.Request.Expect(m => m.Url).Return(new Uri("http://tempuri.org"));
            MockAccountManager       = MockRepository.GenerateMock <IAccountManager>();
            Target                   = new AccountController(MockAccountManager);
            Target.ControllerContext = new ControllerContext(MockHttpContext, new RouteData(), Target);
        }
        public void GivenNoClaimsIdentityExists_WhenIAuthenticate_ThenNoUserEntityIsSet()
        {
            AuthorizationContext authorizationContext = CreateAuthorizationContext(true, "whatever");

            authorizationContext.HttpContext.Request.Expect(m => m.FilePath).Return("hsdjkfhdkjhsfkjhdkjsf");

            WSFederationAuthenticationModule module = new WSFederationAuthenticationModule {
                Issuer = "http://blah.com", HomeRealm = "http://blah.com", Realm = "http://site.com"
            };
            IAuthenticationModuleProvider provider = MockRepository.GenerateMock <IAuthenticationModuleProvider>();

            provider.Expect(m => m.GetModule()).Return(module);
            AuthenticationUtility.SetModuleProvider(provider);

            Target.OnAuthorization(authorizationContext);

            Assert.IsNull(Target.UserEntity);
        }
        public void GivenNoClaimsIdentityExists_WhenIAuthenticate_ThenCorrectRedirectResponseIssued()
        {
            AuthorizationContext authorizationContext = CreateAuthorizationContext(true, "whatever");

            authorizationContext.HttpContext.Request.Expect(m => m.FilePath).Return("hsdjkfhdkjhsfkjhdkjsf");

            WSFederationAuthenticationModule module = new WSFederationAuthenticationModule {
                Issuer = "http://blah.com", HomeRealm = "http://blah.com", Realm = "http://site.com"
            };
            IAuthenticationModuleProvider provider = MockRepository.GenerateMock <IAuthenticationModuleProvider>();

            provider.Expect(m => m.GetModule()).Return(module);
            AuthenticationUtility.SetModuleProvider(provider);

            Target.OnAuthorization(authorizationContext);
            Assert.IsInstanceOfType(authorizationContext.Result, typeof(RedirectToRouteResult));
            ((RedirectToRouteResult)authorizationContext.Result).AssertActionRedirection("Login", "Account");
        }
        public void GivenAnAuthenticatedUserWasAlreadyAuthorized_AndNoClaimsIdentityExists_WhenIAuthenticate_ThenNoUserEntityIsSet()
        {
            string userKey = "whatever";
            AuthorizationContext authorizationContext = CreateAuthorizationContext(false, userKey);

            authorizationContext.HttpContext.Request.Expect(m => m.FilePath).Return("hsdjkfhdkjhsfkjhdkjsf");
            MockAccountManager.Expect(m => m.EnsureUserEntity(authorizationContext.HttpContext.User.Identity as System.Security.Claims.ClaimsIdentity)).Return(new User());
            Target.OnAuthorization(authorizationContext);
            authorizationContext = CreateAuthorizationContext(true, userKey);
            authorizationContext.HttpContext.Request.Expect(m => m.FilePath).Return("hsdjkfhdkjhsfkjhdkjsf");

            WSFederationAuthenticationModule module = new WSFederationAuthenticationModule {
                Issuer = "http://blah.com", HomeRealm = "http://blah.com", Realm = "http://site.com"
            };
            IAuthenticationModuleProvider provider = MockRepository.GenerateMock <IAuthenticationModuleProvider>();

            provider.Expect(m => m.GetModule()).Return(module);
            AuthenticationUtility.SetModuleProvider(provider);

            Target.OnAuthorization(authorizationContext);

            Assert.IsNull(Target.UserEntity);
        }