Beispiel #1
0
            public void GivenNoAuthenticatedUser_ItLoadsProvidersIntoViewModelAndDisplaysLogOnView()
            {
                // Arrange
                EnableAllAuthenticators(Get <AuthenticationService>());
                var controller = GetController <AuthenticationController>();

                // Act
                var result = controller.LogOn("/foo");

                // Assert
                var model = ResultAssert.IsView <LogOnViewModel>(result, viewName: "LogOn");

                Assert.NotNull(model.SignIn);
                Assert.NotNull(model.Register);
                Assert.Equal(1, model.Providers.Count);
                Assert.Equal("MicrosoftAccount", model.Providers[0].ProviderName);
            }
Beispiel #2
0
        public void IndexActionReturnsSubscriptionNames()
        {
            // Arrange.
            var policyService   = new TestSecurityPolicyService();
            var entitiesContext = policyService.MockEntitiesContext.Object;
            var controller      = new SecurityPolicyController(entitiesContext, policyService);

            // Act.
            var result = controller.Index();

            // Assert
            var model = ResultAssert.IsView <SecurityPolicyViewModel>(result);

            Assert.NotNull(model);
            Assert.NotNull(model.SubscriptionNames);
            Assert.Single(model.SubscriptionNames);
        }
Beispiel #3
0
            public async Task WillInvalidateModelStateAndShowTheViewWithErrorsWhenTheUsernameAndPasswordAreNotValid()
            {
                GetMock <AuthenticationService>()
                .Setup(x => x.Authenticate(It.IsAny <string>(), It.IsAny <string>()))
                .CompletesWith(new PasswordAuthenticationResult(PasswordAuthenticationResult.AuthenticationResult.BadCredentials));
                var controller = GetController <AuthenticationController>();

                var result = await controller.SignIn(
                    new LogOnViewModel()
                {
                    SignIn = new SignInViewModel()
                },
                    "theReturnUrl", linkingAccount : false);

                ResultAssert.IsView(result, viewName: SignInViewName);
                Assert.False(controller.ModelState.IsValid);
                Assert.Equal(Strings.UsernameAndPasswordNotFound, controller.ModelState[SignInViewName].Errors[0].ErrorMessage);
            }
Beispiel #4
0
            public async Task GivenNoLinkButEmailMatchingLocalUser_ItDisplaysLogOnViewPresetForSignIn()
            {
                // Arrange
                var fakes        = Get <Fakes>();
                var existingUser = new User("existingUser")
                {
                    EmailAddress = "*****@*****.**"
                };
                var cred     = new CredentialBuilder().CreateExternalCredential("MicrosoftAccount", "blorg", "Bloog");
                var msAuther = new MicrosoftAccountAuthenticator();
                var msaUI    = msAuther.GetUI();
                var authUser = new AuthenticatedUser(
                    fakes.CreateUser("test", cred),
                    cred);

                GetMock <AuthenticationService>(); // Force a mock to be created
                GetMock <IUserService>()
                .Setup(u => u.FindByEmailAddress(existingUser.EmailAddress))
                .Returns(existingUser);

                var controller = GetController <AuthenticationController>();

                GetMock <AuthenticationService>()
                .Setup(x => x.AuthenticateExternalLogin(controller.OwinContext))
                .CompletesWith(new AuthenticateExternalLoginResult()
                {
                    ExternalIdentity = new ClaimsIdentity(new[] {
                        new Claim(ClaimTypes.Email, existingUser.EmailAddress)
                    }),
                    Authenticator = msAuther
                });

                // Act
                var result = await controller.LinkExternalAccount("theReturnUrl");

                // Assert
                var model = ResultAssert.IsView <LogOnViewModel>(result, viewName: LinkExternalViewName);

                Assert.Equal(msaUI.AccountNoun, model.External.ProviderAccountNoun);
                Assert.Null(model.External.AccountName);
                Assert.True(model.External.FoundExistingUser);
                Assert.Equal(existingUser.EmailAddress, model.SignIn.UserNameOrEmail);
                Assert.Equal(existingUser.EmailAddress, model.Register.EmailAddress);
            }
            public void WillInvalidateModelStateAndShowTheViewWhenAnEntityExceptionIsThrow()
            {
                GetMock <AuthenticationService>()
                .Setup(x => x.Register(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
                .Throws(new EntityException("aMessage"));
                var controller = GetController <AuthenticationController>();

                var request = new RegisterRequest
                {
                    Username     = "******",
                    Password     = "******",
                    EmailAddress = "theEmailAddress",
                };
                var result = controller.Register(request, null);

                ResultAssert.IsView(result);
                Assert.False(controller.ModelState.IsValid);
                Assert.Equal("aMessage", controller.ModelState[String.Empty].Errors[0].ErrorMessage);
            }
            public async Task WillInvalidateModelStateAndShowTheViewWhenAnEntityExceptionIsThrow()
            {
                GetMock <AuthenticationService>()
                .Setup(x => x.Register(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Credential>()))
                .Throws(new EntityException("aMessage"));
                var controller = GetController <AuthenticationController>();

                var request = new LogOnViewModel()
                {
                    Register = new RegisterViewModel
                    {
                        Username     = "******",
                        Password     = "******",
                        EmailAddress = "theEmailAddress",
                    }
                };
                var result = await controller.Register(request, null, linkingAccount : false);

                ResultAssert.IsView(result, viewName: RegisterViewName);
                Assert.False(controller.ModelState.IsValid);
                Assert.Equal("aMessage", controller.ModelState["Register"].Errors[0].ErrorMessage);
            }