public async Task ForgotPassword_ValidModel_CallsApi() { await controller.ForgotPassword(new ForgotPasswordViewModel { Email = "*****@*****.**" }); var tokenResponse = A.Fake <TokenResponse>(); A.CallTo(() => oauthClientCredentialClient.GetClientCredentialsAsync()).Returns(tokenResponse); A.CallTo(() => client.Registration.ResetPasswordRequestAsync(tokenResponse.AccessToken, A <PasswordResetRequest> ._)) .MustHaveHappened(Repeated.Exactly.Once); }
public async Task <ActionResult> VerifyEmail(Guid id, string code) { var response = await oauthClientCredentialClient.GetClientCredentialsAsync(); var result = await client.Registration.VerifyEmailAsync(response.AccessToken, new VerifiedEmailData { Id = id, Code = code }); if (!result) { return(RedirectToAction("EmailVerificationRequired")); } return(View()); }
public async void HttpPost_Create_ModelIsValid_ShouldIncludeUserDetails() { var model = ValidModel(); var newUser = A.Fake <IUnauthenticatedUser>(); var token = A.Fake <TokenResponse>(); var accessToken = "token"; A.CallTo(() => oauthClientCredential.GetClientCredentialsAsync()).Returns(token); var userCreationData = new InternalUserCreationData(); A.CallTo(() => newUser.CreateInternalUserAsync(A <InternalUserCreationData> ._, token.AccessToken)) .Invokes((InternalUserCreationData u, string t) => { userCreationData = u; accessToken = token.AccessToken; }) .Returns(Task.FromResult(A.Dummy <string>())); A.CallTo(() => apiClient.User).Returns(newUser); A.CallTo(() => weeeAuthorization.SignIn(A <string> ._, A <string> ._, A <bool> ._)) .Returns(LoginResult.Success("dshadjk", A.Dummy <ActionResult>())); await AccountController().Create(model); Assert.Equal(model.Name, userCreationData.FirstName); Assert.Equal(model.Surname, userCreationData.Surname); Assert.Equal(model.Email, userCreationData.Email); Assert.Equal(model.Password, userCreationData.Password); }
public async Task <string> GetAccessToken() { var token = httpContext.User.GetAccessToken(); if (string.IsNullOrWhiteSpace(token)) { var tokenResponse = await oauthClientCredentialClient.GetClientCredentialsAsync(); token = tokenResponse.AccessToken; } return(token); }