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); }
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"]); }
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()); }
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()); }
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); }