本文整理汇总了C#中AllReady.Controllers.AccountController类的典型用法代码示例。如果您正苦于以下问题:C# AccountController类的具体用法?C# AccountController怎么用?C# AccountController使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AccountController类属于AllReady.Controllers命名空间,在下文中一共展示了AccountController类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExternalLoginConfirmationInvokesSignInAsyncWithCorrectParameters_WhenExternalLoginIsAddedSuccessfully
public async Task ExternalLoginConfirmationInvokesSignInAsyncWithCorrectParameters_WhenExternalLoginIsAddedSuccessfully()
{
var userManager = CreateUserManagerMockWithSucessIdentityResult();
var signInManager = CreateSignInManagerMock(userManager);
SetupSignInManagerWithTestExternalLoginValue(signInManager, "test", "testKey", "testDisplayName");
SetupSignInManagerWithDefaultSignInAsync(signInManager);
var urlHelperMock = CreateUrlHelperMockObject();
SetupUrlHelperMockToReturnTrueForLocalUrl(urlHelperMock);
var viewModel = CreateExternalLoginConfirmationViewModel();
var generalSettings = new Mock<IOptions<GeneralSettings>>();
generalSettings.Setup(x => x.Value).Returns(new GeneralSettings { DefaultTimeZone = "DefaultTimeZone" });
var sut = new AccountController(userManager.Object, signInManager.Object, generalSettings.Object, Mock.Of<IMediator>(), null);
sut.SetFakeUser("userId");
sut.Url = urlHelperMock.Object;
await sut.ExternalLoginConfirmation(viewModel, "testUrl");
signInManager.Verify(s => s.SignInAsync(It.Is<ApplicationUser>(au => au.Email == viewModel.Email
&& au.FirstName == viewModel.FirstName
&& au.LastName == viewModel.LastName
&& au.PhoneNumber == viewModel.PhoneNumber),
It.Is<bool>(p => p == false),
It.Is<string>(auth => auth == null)));
}
示例2: CreateUserManagerMock
public async Task ForgotPasswordPostReturnsForgotPasswordConfirmationView_WhenModelStateIsValid_AndUserIsNotNull_AndUsersEmailHasBeenVerified()
{
const string email = "[email protected]";
var vm = new ForgotPasswordViewModel { Email = email };
var userManager = CreateUserManagerMock();
var user = new ApplicationUser();
userManager.Setup(x => x.FindByNameAsync(email)).Returns(() => Task.FromResult(user));
userManager.Setup(x => x.IsEmailConfirmedAsync(user)).Returns(() => Task.FromResult(true));
userManager.Setup(x => x.GeneratePasswordResetTokenAsync(user)).Returns(() => Task.FromResult(It.IsAny<string>()));
var sut = new AccountController(userManager.Object, null, null, Mock.Of<IMediator>(), null);
sut.SetFakeHttpRequestSchemeTo(It.IsAny<string>());
sut.Url = Mock.Of<IUrlHelper>();
var result = await sut.ForgotPassword(vm) as ViewResult;
Assert.Equal(result.ViewName, "ForgotPasswordConfirmation");
}
示例3: ConfirmEmailInvokesConfirmEmailAsyncWithTheCorrectParameters_WhenUserAndUserIdAndTokenAreNotNull
public async Task ConfirmEmailInvokesConfirmEmailAsyncWithTheCorrectParameters_WhenUserAndUserIdAndTokenAreNotNull()
{
const string userId = "userId";
const string token = "someToken";
var userManager = CreateUserManagerMock();
var user = new ApplicationUser();
userManager.Setup(x => x.FindByIdAsync(userId)).Returns(() => Task.FromResult(user));
userManager.Setup(x => x.ConfirmEmailAsync(user, token)).Returns(() => Task.FromResult(IdentityResult.Success));
var sut = new AccountController(userManager.Object, null, null, null, null);
await sut.ConfirmEmail(userId, token);
userManager.Verify(x => x.ConfirmEmailAsync(It.Is<ApplicationUser>(y => y == user), It.Is<string>(y => y == token)), Times.Once);
}
示例4: ConfirmEmailReturnsConfirmEmailView_WhenUsersEmailCanBeConfirmed
public async Task ConfirmEmailReturnsConfirmEmailView_WhenUsersEmailCanBeConfirmed()
{
const string userId = "userId";
const string token = "someToken";
var userManager = CreateUserManagerMock();
var user = new ApplicationUser();
userManager.Setup(x => x.FindByIdAsync(userId)).Returns(() => Task.FromResult(user));
userManager.Setup(x => x.ConfirmEmailAsync(user, token)).Returns(() => Task.FromResult(IdentityResult.Success));
var sut = new AccountController(userManager.Object, null, null, null, null);
var result = await sut.ConfirmEmail(userId, token) as ViewResult;
Assert.Equal(result.ViewName, "ConfirmEmail");
}
示例5: RegisterPostInvokesCreateAsyncWithTheCorrectParameters_WhenModelStateIsValid
public async Task RegisterPostInvokesCreateAsyncWithTheCorrectParameters_WhenModelStateIsValid()
{
const string defaultTimeZone = "DefaultTimeZone";
var model = new RegisterViewModel { Email = "email", Password = "Password" };
var generalSettings = new Mock<IOptions<GeneralSettings>>();
generalSettings.Setup(x => x.Value).Returns(new GeneralSettings { DefaultTimeZone = defaultTimeZone });
var userManager = CreateUserManagerMock();
userManager.Setup(x => x.CreateAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).Returns(() => Task.FromResult(IdentityResult.Failed()));
var sut = new AccountController(userManager.Object, null, generalSettings.Object, null, null);
await sut.Register(model);
userManager.Verify(x => x.CreateAsync(It.Is<ApplicationUser>(au =>
au.UserName == model.Email &&
au.Email == model.Email &&
au.TimeZoneId == defaultTimeZone),
model.Password), Times.Once);
}
示例6: GeneralSettings
public async Task RegisterPostInvokesUrlActionWithTheCorrectParameters_WhenModelStateIsValid_AndUserCreationIsSuccessful()
{
const string requestScheme = "requestScheme";
var generalSettings = new Mock<IOptions<GeneralSettings>>();
generalSettings.Setup(x => x.Value).Returns(new GeneralSettings());
var userManager = CreateUserManagerMock();
userManager.Setup(x => x.CreateAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).Returns(() => Task.FromResult(IdentityResult.Success));
userManager.Setup(x => x.GenerateEmailConfirmationTokenAsync(It.IsAny<ApplicationUser>())).Returns(() => Task.FromResult(It.IsAny<string>()));
userManager.Setup(x => x.GenerateChangePhoneNumberTokenAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).Returns(() => Task.FromResult(It.IsAny<string>()));
var signInManager = CreateSignInManagerMock(userManager);
var sut = new AccountController(userManager.Object, signInManager.Object, generalSettings.Object, Mock.Of<IMediator>(), null);
sut.SetFakeHttpRequestSchemeTo(requestScheme);
var urlHelper = new Mock<IUrlHelper>();
sut.Url = urlHelper.Object;
await sut.Register(new RegisterViewModel());
urlHelper.Verify(mock => mock.Action(It.Is<UrlActionContext>(uac =>
uac.Action == "ConfirmEmail" &&
uac.Controller == "Account" &&
uac.Protocol == requestScheme)),
Times.Once);
}
示例7: ExternalLoginConfirmationAddsIdentityResultErrorsToModelStateError_WhenUserIsCreatedSuccessfully
public async Task ExternalLoginConfirmationAddsIdentityResultErrorsToModelStateError_WhenUserIsCreatedSuccessfully()
{
var userManager = CreateUserManagerMock();
userManager.Setup(u => u.CreateAsync(It.IsAny<ApplicationUser>())).Returns(Task.FromResult(IdentityResult.Success));
userManager.Setup(u => u.AddLoginAsync(It.IsAny<ApplicationUser>(), It.IsAny<ExternalLoginInfo>()))
.Returns(Task.FromResult(IdentityResult.Failed(
new IdentityError { Code = "TestCode1", Description = "TestDescription1" },
new IdentityError { Code = "TestCode2", Description = "TestDescription2" }
)));
var signInManager = CreateSignInManagerMock(userManager);
SetupSignInManagerWithTestExternalLoginValue(signInManager, "test", "testKey", "testDisplayName");
SetupSignInManagerWithDefaultSignInAsync(signInManager);
var urlHelperMock = CreateUrlHelperMockObject();
SetupUrlHelperMockToReturnResultBaseOnLineBegining(urlHelperMock);
var viewModel = CreateExternalLoginConfirmationViewModel();
var generalSettings = new Mock<IOptions<GeneralSettings>>();
generalSettings.Setup(x => x.Value).Returns(new GeneralSettings { DefaultTimeZone = "DefaultTimeZone" });
var sut = new AccountController(userManager.Object, signInManager.Object, generalSettings.Object, Mock.Of<IMediator>(), null);
sut.SetFakeUser("userId");
sut.Url = urlHelperMock.Object;
var result = await sut.ExternalLoginConfirmation(viewModel, "http://localUrl") as ViewResult;
Assert.Equal(result.ViewData.ModelState.ErrorCount, 2);
var firstModelStateError = result.ViewData.ModelState.Values.FirstOrDefault().Errors.FirstOrDefault();
var secondModelStateError = result.ViewData.ModelState.Values.FirstOrDefault().Errors.Skip(1).FirstOrDefault();
Assert.Equal(firstModelStateError.ErrorMessage, "TestDescription1");
Assert.Equal(secondModelStateError.ErrorMessage, "TestDescription2");
}
示例8: AccountController
private static AccountController AccountController(Microsoft.AspNetCore.Identity.SignInResult signInResult = default(Microsoft.AspNetCore.Identity.SignInResult))
{
var userManagerMock = CreateUserManagerMock();
var signInManagerMock = CreateSignInManagerMock(userManagerMock);
signInManagerMock.Setup(mock => mock.PasswordSignInAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>()))
.ReturnsAsync(signInResult == default(Microsoft.AspNetCore.Identity.SignInResult) ? Microsoft.AspNetCore.Identity.SignInResult.Success : signInResult);
var urlHelperMock = new Mock<IUrlHelper>();
urlHelperMock.Setup(mock => mock.IsLocalUrl(It.Is<string>(x => x.StartsWith("http")))).Returns(false);
urlHelperMock.Setup(mock => mock.IsLocalUrl(It.Is<string>(x => !x.StartsWith("http")))).Returns(true);
var controller = new AccountController(userManagerMock.Object, signInManagerMock.Object, Mock.Of<IOptions<GeneralSettings>>(), Mock.Of<IMediator>(), null)
{
Url = urlHelperMock.Object
};
return controller;
}
示例9: CreateUserManagerMockWithSucessIdentityResult
public async Task ExternalLoginConfirmationRedirectsToCorrectActionAndContrller_WhenUrlIsNotLocalUrl_AndUserIsNeitherSiteAdminOrOrgAdmin()
{
var userManager = CreateUserManagerMockWithSucessIdentityResult();
var signInManager = CreateSignInManagerMock(userManager);
SetupSignInManagerWithTestExternalLoginValue(signInManager, "test", "testKey", "testDisplayName");
SetupSignInManagerWithDefaultSignInAsync(signInManager);
var urlHelperMock = CreateUrlHelperMockObject();
SetupUrlHelperMockToReturnResultBaseOnLineBegining(urlHelperMock);
var viewModel = CreateExternalLoginConfirmationViewModel();
var generalSettings = new Mock<IOptions<GeneralSettings>>();
generalSettings.Setup(x => x.Value).Returns(new GeneralSettings { DefaultTimeZone = "DefaultTimeZone" });
var sut = new AccountController(userManager.Object, signInManager.Object, generalSettings.Object, Mock.Of<IMediator>(), null);
sut.SetFakeUser("userId");
sut.Url = urlHelperMock.Object;
var result = await sut.ExternalLoginConfirmation(viewModel, "http://localUrl") as RedirectToActionResult;
Assert.Equal(result.ActionName, nameof(HomeController.Index));
Assert.Equal(result.ControllerName, "Home");
}
示例10: ExternalLoginConfirmationRedirectsToCorrectUrl_WhenUrlIsLocalUrl
public async Task ExternalLoginConfirmationRedirectsToCorrectUrl_WhenUrlIsLocalUrl()
{
const string returnUrl = "localUrl";
var userManager = CreateUserManagerMockWithSucessIdentityResult();
var signInManager = CreateSignInManagerMock(userManager);
SetupSignInManagerWithTestExternalLoginValue(signInManager, "test", "testKey", "testDisplayName");
SetupSignInManagerWithDefaultSignInAsync(signInManager);
var urlHelperMock = CreateUrlHelperMockObject();
SetupUrlHelperMockToReturnResultBaseOnLineBegining(urlHelperMock);
var viewModel = CreateExternalLoginConfirmationViewModel();
var generalSettings = new Mock<IOptions<GeneralSettings>>();
generalSettings.Setup(x => x.Value).Returns(new GeneralSettings { DefaultTimeZone = "DefaultTimeZone" });
var sut = new AccountController(userManager.Object, signInManager.Object, generalSettings.Object, Mock.Of<IMediator>(), null);
sut.SetFakeUser("userId");
sut.Url = urlHelperMock.Object;
var result = await sut.ExternalLoginConfirmation(viewModel, returnUrl) as RedirectResult;
Assert.Equal(result.Url, returnUrl);
}
示例11: ConfirmEmailInvokesFindByIdAsyncWithCorrectUserId_WhenUserIdAndTokenAreNotNull
public async Task ConfirmEmailInvokesFindByIdAsyncWithCorrectUserId_WhenUserIdAndTokenAreNotNull()
{
const string userId = "userId";
const string token = "someToken";
var userManager = CreateUserManagerMock();
var sut = new AccountController(userManager.Object, null, null, null, null);
await sut.ConfirmEmail(userId, token);
userManager.Verify(x => x.FindByIdAsync(It.Is<string>(y => y == userId)), Times.Once);
}
示例12: ConfirmEmailReturnsErrorView_WhenUserIsNull_AndUserIdAndTokenAreNotNull
public async Task ConfirmEmailReturnsErrorView_WhenUserIsNull_AndUserIdAndTokenAreNotNull()
{
const string userId = "userId";
const string token = "someToken";
var userManager = CreateUserManagerMock();
userManager.Setup(x => x.FindByIdAsync(userId)).Returns(() => Task.FromResult((ApplicationUser)null));
var sut = new AccountController(userManager.Object, null, null, null, null);
var result = await sut.ConfirmEmail(userId, token) as ViewResult;
Assert.Equal("Error", result.ViewName);
}
示例13: RegisterPostRedirectsToCorrectActionAndController_WhenModelStateIsValid_AndUserCreationIsSuccessful
public async Task RegisterPostRedirectsToCorrectActionAndController_WhenModelStateIsValid_AndUserCreationIsSuccessful()
{
var generalSettings = new Mock<IOptions<GeneralSettings>>();
generalSettings.Setup(x => x.Value).Returns(new GeneralSettings());
var userManager = CreateUserManagerMock();
userManager.Setup(x => x.CreateAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).Returns(() => Task.FromResult(IdentityResult.Success));
userManager.Setup(x => x.GenerateEmailConfirmationTokenAsync(It.IsAny<ApplicationUser>())).Returns(() => Task.FromResult(It.IsAny<string>()));
userManager.Setup(x => x.GenerateChangePhoneNumberTokenAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).Returns(() => Task.FromResult(It.IsAny<string>()));
var signInManager = CreateSignInManagerMock(userManager);
var urlHelper = new Mock<IUrlHelper>();
urlHelper.Setup(x => x.Action(It.IsAny<UrlActionContext>())).Returns(It.IsAny<string>());
userManager.Setup(x => x.AddClaimAsync(It.IsAny<ApplicationUser>(), It.IsAny<Claim>())).Returns(() => Task.FromResult(IdentityResult.Success));
signInManager.Setup(x => x.SignInAsync(It.IsAny<ApplicationUser>(), It.IsAny<bool>(), null)).Returns(() => Task.FromResult(It.IsAny<Task>()));
var sut = new AccountController(userManager.Object, signInManager.Object, generalSettings.Object, Mock.Of<IMediator>(), null);
sut.SetFakeHttpRequestSchemeTo(It.IsAny<string>());
sut.Url = urlHelper.Object;
var result = await sut.Register(new RegisterViewModel()) as RedirectToActionResult;
Assert.Equal(result.ActionName, nameof(HomeController.Index));
Assert.Equal(result.ControllerName, "Home");
}
示例14: ForgotPasswordPostInvokesIsEmailConfirmedAsyncWithThecorrectUser_WhenModelStateIsValid
public async Task ForgotPasswordPostInvokesIsEmailConfirmedAsyncWithThecorrectUser_WhenModelStateIsValid()
{
const string email = "[email protected]";
var vm = new ForgotPasswordViewModel { Email = email };
var userManager = CreateUserManagerMock();
var user = new ApplicationUser();
userManager.Setup(x => x.FindByNameAsync(email)).Returns(() => Task.FromResult(user)).Verifiable();
var sut = new AccountController(userManager.Object, null, null, null, null);
await sut.ForgotPassword(vm);
userManager.Verify(m => m.IsEmailConfirmedAsync(user), Times.Once);
}
示例15: RegisterPostAddsIdentityResultErrorsToModelStateError_WhenUserCreationFails
public async Task RegisterPostAddsIdentityResultErrorsToModelStateError_WhenUserCreationFails()
{
var generalSettings = new Mock<IOptions<GeneralSettings>>();
generalSettings.Setup(x => x.Value).Returns(new GeneralSettings());
var identityResult = IdentityResult.Failed(new IdentityError { Description = "IdentityErrorDescription" });
var userManager = CreateUserManagerMock();
userManager.Setup(x => x.CreateAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).Returns(() => Task.FromResult(identityResult));
var sut = new AccountController(userManager.Object, null, generalSettings.Object, null, null);
await sut.Register(new RegisterViewModel());
var errorMessages = sut.ModelState.GetErrorMessages();
Assert.Equal(errorMessages.Single(), identityResult.Errors.Select(x => x.Description).Single());
}