本文整理汇总了C#中AllReady.Controllers.AdminController类的典型用法代码示例。如果您正苦于以下问题:C# AdminController类的具体用法?C# AdminController怎么用?C# AdminController使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AdminController类属于AllReady.Controllers命名空间,在下文中一共展示了AdminController类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: RegisterInvokesCreateAsyncWithCorrectUserAndPassword
public async Task RegisterInvokesCreateAsyncWithCorrectUserAndPassword()
{
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 AdminController(userManager.Object, null, null, null, null, generalSettings.Object);
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));
}
开发者ID:mmoore99,项目名称:allReady,代码行数:22,代码来源:AdminControllerTests.cs
示例2: RegisterSendsSendAccountConfirmationEmailWithCorrectDataWhenUserCreationIsSuccessful
public async Task RegisterSendsSendAccountConfirmationEmailWithCorrectDataWhenUserCreationIsSuccessful()
{
const string callbackUrl = "callbackUrl";
var model = new RegisterViewModel { Email = "email" };
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>()));
var urlHelper = new Mock<IUrlHelper>();
urlHelper.Setup(x => x.Action(It.IsAny<UrlActionContext>())).Returns(callbackUrl);
var mediator = new Mock<IMediator>();
var sut = new AdminController(userManager.Object, null, mediator.Object, null, generalSettings.Object);
sut.SetFakeHttpRequestSchemeTo(It.IsAny<string>());
sut.Url = urlHelper.Object;
await sut.Register(model);
mediator.Verify(x => x.SendAsync(It.Is<SendAccountConfirmationEmail>(y => y.Email == model.Email && y.CallbackUrl == callbackUrl)));
}
开发者ID:mheggeseth,项目名称:allReady,代码行数:26,代码来源:AdminControllerTests.cs
示例3: VerifyCodePostRedirectsToHomeControllerIndexWhenTwoFactorSignInAsyncSucceedsAndReturnUrlIsNotLocalUrl
public async Task VerifyCodePostRedirectsToHomeControllerIndexWhenTwoFactorSignInAsyncSucceedsAndReturnUrlIsNotLocalUrl()
{
var signInManager = CreateSignInManagerMock();
signInManager.Setup(x => x.TwoFactorSignInAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>()))
.ReturnsAsync(Microsoft.AspNetCore.Identity.SignInResult.Success);
var urlHelper = new Mock<IUrlHelper>();
urlHelper.Setup(x => x.IsLocalUrl(It.IsAny<string>())).Returns(false);
var sut = new AdminController(null, signInManager.Object, null, null, null) { Url = urlHelper.Object };
var result = await sut.VerifyCode(new VerifyCodeViewModel()) as RedirectToActionResult;
Assert.Equal(result.ActionName, nameof(HomeController.Index));
Assert.Equal(result.ControllerName, "Home");
}
开发者ID:mheggeseth,项目名称:allReady,代码行数:15,代码来源:AdminControllerTests.cs
示例4: VerifyCodePostReturnsLockoutViewIfTwoFactorSignInAsyncFailsAndIsLockedOut
public async Task VerifyCodePostReturnsLockoutViewIfTwoFactorSignInAsyncFailsAndIsLockedOut()
{
var signInManager = CreateSignInManagerMock();
signInManager.Setup(x => x.TwoFactorSignInAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>())).ReturnsAsync(Microsoft.AspNetCore.Identity.SignInResult.LockedOut);
var sut = new AdminController(null, signInManager.Object, null, null, null);
var result = await sut.VerifyCode(new VerifyCodeViewModel()) as ViewResult;
Assert.Equal(result.ViewName, "Lockout");
}
开发者ID:mheggeseth,项目名称:allReady,代码行数:10,代码来源:AdminControllerTests.cs
示例5: VerifyCodePostInvokesTwoFactorSignInAsyncWithCorrectParameters
public async Task VerifyCodePostInvokesTwoFactorSignInAsyncWithCorrectParameters()
{
var model = new VerifyCodeViewModel
{
Provider = "provider",
Code = "code",
RememberBrowser = true,
RememberMe = true
};
var signInManager = CreateSignInManagerMock();
signInManager.Setup(x => x.TwoFactorSignInAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>())).ReturnsAsync(new Microsoft.AspNetCore.Identity.SignInResult());
var sut = new AdminController(null, signInManager.Object, null, null, null);
await sut.VerifyCode(model);
signInManager.Verify(x => x.TwoFactorSignInAsync(model.Provider, model.Code, model.RememberMe, model.RememberBrowser));
}
开发者ID:mheggeseth,项目名称:allReady,代码行数:18,代码来源:AdminControllerTests.cs
示例6: VerifyCodeGetReturnsErrorViewWhenUserIsNull
public async Task VerifyCodeGetReturnsErrorViewWhenUserIsNull()
{
var signInManager = CreateSignInManagerMock();
var sut = new AdminController(null, signInManager.Object, null, null, null);
var result = await sut.VerifyCode(It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<string>()) as ViewResult;
Assert.Equal(result.ViewName, "Error");
}
开发者ID:mheggeseth,项目名称:allReady,代码行数:8,代码来源:AdminControllerTests.cs
示例7: SendCodePostReturnsRedirectToActionResult
public async Task SendCodePostReturnsRedirectToActionResult()
{
var model = new SendCodeViewModel { SelectedProvider = string.Empty, ReturnUrl = "ReturnUrl", RememberMe = true };
var routeValues = new Dictionary<string, object>
{
["Provider"] = model.SelectedProvider,
["ReturnUrl"] = model.ReturnUrl,
["RememberMe"] = model.RememberMe
};
var userManager = CreateUserManagerMock();
var signInManager = CreateSignInManagerMock(userManager);
signInManager.Setup(x => x.GetTwoFactorAuthenticationUserAsync()).ReturnsAsync(new ApplicationUser());
userManager.Setup(x => x.GenerateTwoFactorTokenAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).ReturnsAsync("token");
var sut = new AdminController(userManager.Object, signInManager.Object, null, null, null);
var result = await sut.SendCode(model) as RedirectToActionResult;
Assert.Equal(result.ActionName, nameof(AdminController.VerifyCode));
Assert.Equal(result.RouteValues, routeValues);
}
开发者ID:mheggeseth,项目名称:allReady,代码行数:23,代码来源:AdminControllerTests.cs
示例8: SendCodePostReturnsErrorViewWhenAuthenticationTokenIsNull
public async Task SendCodePostReturnsErrorViewWhenAuthenticationTokenIsNull()
{
var userManager = CreateUserManagerMock();
var signInManager = CreateSignInManagerMock(userManager);
signInManager.Setup(x => x.GetTwoFactorAuthenticationUserAsync()).ReturnsAsync(new ApplicationUser());
var sut = new AdminController(userManager.Object, signInManager.Object, null, null, null);
var result = await sut.SendCode(new SendCodeViewModel()) as ViewResult;
Assert.Equal(result.ViewName, "Error");
}
开发者ID:mheggeseth,项目名称:allReady,代码行数:12,代码来源:AdminControllerTests.cs
示例9: ConfirmEmailInvokesUrlActionWithCorrectParametersWhenUsersEmailIsConfirmedSuccessfully
public async Task ConfirmEmailInvokesUrlActionWithCorrectParametersWhenUsersEmailIsConfirmedSuccessfully()
{
const string requestScheme = "requestScheme";
const string userId = "1";
var userManager = CreateUserManagerMock();
userManager.Setup(x => x.FindByIdAsync(It.IsAny<string>())).Returns(() => Task.FromResult(new ApplicationUser { Id = userId }));
userManager.Setup(x => x.ConfirmEmailAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).Returns(() => Task.FromResult(IdentityResult.Success));
var settings = new Mock<IOptions<SampleDataSettings>>();
settings.Setup(x => x.Value).Returns(new SampleDataSettings());
var urlHelper = new Mock<IUrlHelper>();
var sut = new AdminController(userManager.Object, null, Mock.Of<IMediator>(), settings.Object, null);
sut.SetFakeHttpRequestSchemeTo(requestScheme);
sut.Url = urlHelper.Object;
await sut.ConfirmEmail(It.IsAny<string>(), "code");
urlHelper.Verify(x => x.Action(It.Is<UrlActionContext>(uac =>
uac.Action == "EditUser" &&
uac.Controller == "Site" &&
uac.Protocol == requestScheme &&
uac.Values.ToString() == $"{{ area = Admin, userId = {userId} }}")),
Times.Once);
}
开发者ID:mheggeseth,项目名称:allReady,代码行数:27,代码来源:AdminControllerTests.cs
示例10: ConfirmEmailInvokesConfirmEmailAsyncWithCorrectUserAndCode
public async Task ConfirmEmailInvokesConfirmEmailAsyncWithCorrectUserAndCode()
{
const string code = "code";
var user = new ApplicationUser();
var userManager = CreateUserManagerMock();
userManager.Setup(x => x.FindByIdAsync(It.IsAny<string>())).Returns(() => Task.FromResult(user));
userManager.Setup(x => x.ConfirmEmailAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).Returns(() => Task.FromResult(IdentityResult.Failed()));
var sut = new AdminController(userManager.Object, null, null, null, null);
await sut.ConfirmEmail(null, code);
userManager.Verify(x => x.ConfirmEmailAsync(user, code), Times.Once);
}
开发者ID:mheggeseth,项目名称:allReady,代码行数:14,代码来源:AdminControllerTests.cs
示例11: ConfirmEmailInvokesFindByIdAsyncWithCorrectUserId
public async Task ConfirmEmailInvokesFindByIdAsyncWithCorrectUserId()
{
const string userId = "userId";
var userManager = CreateUserManagerMock();
var sut = new AdminController(userManager.Object, null, null, null, null);
await sut.ConfirmEmail(userId, "code");
userManager.Verify(x => x.FindByIdAsync(userId), Times.Once);
}
开发者ID:mheggeseth,项目名称:allReady,代码行数:9,代码来源:AdminControllerTests.cs
示例12: ConfirmEmailReturnsErrorWhenCannotFindUserByUserId
public async Task ConfirmEmailReturnsErrorWhenCannotFindUserByUserId()
{
var userManager = CreateUserManagerMock();
var sut = new AdminController(userManager.Object, null, null, null, null);
var result = await sut.ConfirmEmail(null, "code") as ViewResult;
Assert.Equal(result.ViewName, "Error");
}
开发者ID:mheggeseth,项目名称:allReady,代码行数:7,代码来源:AdminControllerTests.cs
示例13: RegisterReturnsViewResultAndCorrectModelWhenUserCreationIsNotSuccessful
public async Task RegisterReturnsViewResultAndCorrectModelWhenUserCreationIsNotSuccessful()
{
var model = new RegisterViewModel();
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.Failed()));
var sut = new AdminController(userManager.Object, null, null, null, generalSettings.Object);
sut.SetFakeHttpRequestSchemeTo(It.IsAny<string>());
var result = await sut.Register(model) as ViewResult;
var modelResult = result.ViewData.Model as RegisterViewModel;
Assert.IsType<ViewResult>(result);
Assert.IsType<RegisterViewModel>(modelResult);
Assert.Same(model, modelResult);
}
开发者ID:mheggeseth,项目名称:allReady,代码行数:20,代码来源:AdminControllerTests.cs
示例14: RegisterAddsIdentityResultErrorsToModelStateErrorsWhenUserCreationIsNotSuccessful
public async Task RegisterAddsIdentityResultErrorsToModelStateErrorsWhenUserCreationIsNotSuccessful()
{
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 AdminController(userManager.Object, null, null, null, generalSettings.Object);
sut.SetFakeHttpRequestSchemeTo(It.IsAny<string>());
await sut.Register(new RegisterViewModel());
var errorMessages = sut.ModelState.GetErrorMessages();
Assert.Equal(errorMessages.Single(), identityResult.Errors.Select(x => x.Description).Single());
}
开发者ID:mheggeseth,项目名称:allReady,代码行数:19,代码来源:AdminControllerTests.cs
示例15: RegisterRedirectsToCorrectActionWhenUserCreationIsSuccessful
public async Task RegisterRedirectsToCorrectActionWhenUserCreationIsSuccessful()
{
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>()));
var urlHelper = new Mock<IUrlHelper>();
urlHelper.Setup(x => x.Action(It.IsAny<UrlActionContext>())).Returns(It.IsAny<string>());
var sut = new AdminController(userManager.Object, null, Mock.Of<IMediator>(), null, generalSettings.Object);
sut.SetFakeHttpRequestSchemeTo(It.IsAny<string>());
sut.Url = urlHelper.Object;
var result = await sut.Register(new RegisterViewModel()) as RedirectToActionResult;
Assert.Equal(result.ActionName, nameof(AdminController.DisplayEmail));
Assert.Equal(result.ControllerName, "Admin");
}
开发者ID:mheggeseth,项目名称:allReady,代码行数:21,代码来源:AdminControllerTests.cs
示例16: SendCodePosReturnsErrorViewWhenUserIsNotFound
public async Task SendCodePosReturnsErrorViewWhenUserIsNotFound()
{
var signInManager = CreateSignInManagerMock();
var sut = new AdminController(null, signInManager.Object, null, null, null);
var result = await sut.SendCode(It.IsAny<SendCodeViewModel>()) as ViewResult;
Assert.Equal(result.ViewName, "Error");
}
开发者ID:mheggeseth,项目名称:allReady,代码行数:9,代码来源:AdminControllerTests.cs
示例17: SendCodePostInvokesGenerateTwoFactorTokenAsyncWithCorrectUserAndTokenProvider
public async Task SendCodePostInvokesGenerateTwoFactorTokenAsyncWithCorrectUserAndTokenProvider()
{
var applicationUser = new ApplicationUser();
var model = new SendCodeViewModel { SelectedProvider = "Email" };
var userManager = CreateUserManagerMock();
var signInManager = CreateSignInManagerMock(userManager);
signInManager.Setup(x => x.GetTwoFactorAuthenticationUserAsync()).ReturnsAsync(applicationUser);
var sut = new AdminController(userManager.Object, signInManager.Object, null, null, null);
await sut.SendCode(model);
userManager.Verify(x => x.GenerateTwoFactorTokenAsync(applicationUser, model.SelectedProvider), Times.Once);
}
开发者ID:mheggeseth,项目名称:allReady,代码行数:15,代码来源:AdminControllerTests.cs
示例18: CreateUserManagerMock
public async Task ConfirmEmailSendsSendApproveOrganizationUserAccountEmailWithCorrectDataWhenUsersEmailIsConfirmedSuccessfully()
{
const string defaultAdminUserName = "requestScheme";
const string callbackUrl = "callbackUrl";
var userManager = CreateUserManagerMock();
userManager.Setup(x => x.FindByIdAsync(It.IsAny<string>())).Returns(() => Task.FromResult(new ApplicationUser()));
userManager.Setup(x => x.ConfirmEmailAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).Returns(() => Task.FromResult(IdentityResult.Success));
var settings = new Mock<IOptions<SampleDataSettings>>();
settings.Setup(x => x.Value).Returns(new SampleDataSettings { DefaultAdminUsername = defaultAdminUserName });
var urlHelper = new Mock<IUrlHelper>();
urlHelper.Setup(x => x.Action(It.IsAny<UrlActionContext>())).Returns(callbackUrl);
var mediator = new Mock<IMediator>();
var sut = new AdminController(userManager.Object, null, mediator.Object, settings.Object, null);
sut.SetFakeHttpRequestSchemeTo(It.IsAny<string>());
sut.Url = urlHelper.Object;
await sut.ConfirmEmail(It.IsAny<string>(), "code");
mediator.Verify(x => x.SendAsync(It.Is<SendApproveOrganizationUserAccountEmail>(y => y.DefaultAdminUsername == defaultAdminUserName && y.CallbackUrl == callbackUrl)));
}
开发者ID:mheggeseth,项目名称:allReady,代码行数:25,代码来源:AdminControllerTests.cs
示例19: SendCodePostSendsSendSecurityCodeSmsWithCorrectDataWhenSelectedProviderIsPhone
public async Task SendCodePostSendsSendSecurityCodeSmsWithCorrectDataWhenSelectedProviderIsPhone()
{
const string token = "token";
const string usersPhoneNumber = "usersPhoneNumber";
var applicationUser = new ApplicationUser();
var model = new SendCodeViewModel { SelectedProvider = "Phone" };
var userManager = CreateUserManagerMock();
var signInManager = CreateSignInManagerMock(userManager);
var mediator = new Mock<IMediator>();
userManager.Setup(x => x.GenerateTwoFactorTokenAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).ReturnsAsync(token);
userManager.Setup(x => x.GetPhoneNumberAsync(applicationUser)).ReturnsAsync(usersPhoneNumber);
signInManager.Setup(x => x.GetTwoFactorAuthenticationUserAsync()).ReturnsAsync(applicationUser);
var sut = new AdminController(userManager.Object, signInManager.Object, mediator.Object, null, null);
await sut.SendCode(model);
mediator.Verify(x => x.SendAsync(It.Is<SendSecurityCodeSms>(y => y.PhoneNumber == usersPhoneNumber && y.Token == token)));
}
开发者ID:mheggeseth,项目名称:allReady,代码行数:21,代码来源:AdminControllerTests.cs
示例20: ConfirmEmailReturnsCorrectViewWhenUsersConfirmationIsSuccessful
public async Task ConfirmEmailReturnsCorrectViewWhenUsersConfirmationIsSuccessful()
{
var userManager = CreateUserManagerMock();
userManager.Setup(x => x.FindByIdAsync(It.IsAny<string>())).Returns(() => Task.FromResult(new ApplicationUser()));
userManager.Setup(x => x.ConfirmEmailAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).Returns(() => Task.FromResult(IdentityResult.Success));
var urlHelper = new Mock<IUrlHelper>();
urlHelper.Setup(x => x.Action(It.IsAny<UrlActionContext>())).Returns(It.IsAny<string>());
var settings = new Mock<IOptions<SampleDataSettings>>();
settings.Setup(x => x.Value).Returns(new SampleDataSettings { DefaultAdminUsername = It.IsAny<string>() });
var sut = new AdminController(userManager.Object, null, Mock.Of<IMediator>(), settings.Object, null);
sut.SetFakeHttpRequestSchemeTo(It.IsAny<string>());
sut.Url = urlHelper.Object;
var result = await sut.ConfirmEmail("userId", "code") as ViewResult;
Assert.Equal(result.ViewName, "ConfirmEmail");
}
开发者ID:mheggeseth,项目名称:allReady,代码行数:20,代码来源:AdminControllerTests.cs
注:本文中的AllReady.Controllers.AdminController类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论