예제 #1
0
        public async Task PostWithExternalLoginViewModelWithReturnUrlSpecified_RedirectsToReturnUrl() {
            var externalLoginViewModel = new ExternalLoginViewModel {
                ExternalLoginData = "fakeExternalLoginData",
                ReturnUrl = "/Countdown/Index"
            };

            var providerLoginData = new ProviderLoginData {
                ProviderUserId = "fakeProviderUserId"
            };

            var accountController = TestableAccountController.Create();
            accountController.MockOAuthWebSecurityWrapper
                             .Setup(x => x.DeserializeProviderLoginData(externalLoginViewModel.ExternalLoginData))
                             .Returns(providerLoginData);

            var result = await accountController.ExternalLoginConfirmation(externalLoginViewModel) as RedirectResult;

            Assert.IsNotNull(result);
            Assert.AreEqual("/Countdown/Index", result.Url);
        }
예제 #2
0
        public async Task PostWithExternalLoginViewModelWithNoReturnUrlSpecified_RedirectsToTheDefaultUrl() {
            var externalLoginViewModel = new ExternalLoginViewModel {
                ExternalLoginData = "fakeExternalLoginData"
            };

            var providerLoginData = new ProviderLoginData {
                ProviderUserId = "fakeProviderUserId"
            };

            var accountController = TestableAccountController.Create();
            accountController.MockOAuthWebSecurityWrapper
                             .Setup(x => x.DeserializeProviderLoginData(externalLoginViewModel.ExternalLoginData))
                             .Returns(providerLoginData);

            var result = await accountController.ExternalLoginConfirmation(externalLoginViewModel) as RedirectToRouteResult;

            Assert.IsNotNull(result);
            Assert.AreEqual("Countdown", result.RouteValues["Controller"]);
            Assert.AreEqual("Trending", result.RouteValues["Action"]);
        }
예제 #3
0
        public async Task PostWithExternalLoginViewModel_CallsAccountRepositoryCreateWithCorrectlyComposedAccount() {
            var externalLoginViewModel = new ExternalLoginViewModel {
                DisplayName = "fakeDisplayName",
                ProviderName = "fakeProviderName",
                ExternalLoginData = "fakeExternalLoginData",
                ReturnUrl = "/Countdown/Index"
            };

            var providerLoginData = new ProviderLoginData {
                ProviderName = "fakeProvider",
                ProviderUserId = "fakeProviderUserId"
            };

            var accountController = TestableAccountController.Create();

            accountController.MockOAuthWebSecurityWrapper
                             .Setup(x => x.DeserializeProviderLoginData(externalLoginViewModel.ExternalLoginData))
                             .Returns(providerLoginData);

            await accountController.ExternalLoginConfirmation(externalLoginViewModel);

            accountController.MockAccountRepository
                             .Verify(x => x.CreateAsync(
                                 It.Is<Account>(a =>
                                                a.DisplayName == externalLoginViewModel.DisplayName &&
                                                a.Email == externalLoginViewModel.Email &&
                                                // TODO - Inject a clock and test the creation date better
                                                (a.CreatedOn.Date == DateTime.UtcNow.Date &&
                                                 a.CreatedOn.Hour == DateTime.UtcNow.Hour &&
                                                 a.CreatedOn.Minute == DateTime.UtcNow.Minute) &&
                                                a.AccountLogins.First().ProviderName == providerLoginData.ProviderName &&
                                                a.AccountLogins.First().ProviderUserId ==
                                                providerLoginData.ProviderUserId &&
                                                a.AccountLogins.First().Id != Guid.Empty
                                     )),
                                     Times.Once());
        }
예제 #4
0
        public async Task PostWithExternalLoginViewModel_CallsFormsAuthenticationWrapperSetAuthCookieWithProviderUserId() {
            var externalLoginViewModel = new ExternalLoginViewModel();

            var providerLoginData = new ProviderLoginData {
                ProviderUserId = "fakeProviderUserId"
            };

            var accountController = TestableAccountController.Create();

            accountController.MockOAuthWebSecurityWrapper
                             .Setup(x => x.DeserializeProviderLoginData(It.IsAny<string>()))
                             .Returns(providerLoginData);

            await accountController.ExternalLoginConfirmation(externalLoginViewModel);

            accountController.MockFormsAuthenticationWrapper
                             .Verify(x => x.SetAuthCookie(providerLoginData.ProviderUserId, true),
                                     Times.Once());
        }
예제 #5
0
 private Task RegisterAccount(ExternalLoginViewModel viewModel, ProviderLoginData providerLoginData) {
     var account = new Account {
         DisplayName = viewModel.DisplayName,
         Email = viewModel.Email,
         CreatedOn = DateTime.UtcNow,
         AccountLogins = new List<AccountLogin> {
             new AccountLogin {
                 Id = Guid.NewGuid(),
                 ProviderName = providerLoginData.ProviderName,
                 ProviderUserId = providerLoginData.ProviderUserId
             }
         }
     };
     account.AccountLogins.First().Account = account;
     return _accountRepository.CreateAsync(account);
 }