Cleanup + more unit tests (Core @ 81%)

This commit is contained in:
Hao Kung 2014-03-18 11:26:02 -07:00
Родитель f77614c97f
Коммит 7adb28a460
9 изменённых файлов: 257 добавлений и 129 удалений

Просмотреть файл

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30313.0
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{0F647068-6602-4E24-B1DC-8ED91481A50A}"
EndProject
@ -25,7 +25,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Identity.I
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Identity.Test.net45", "test\Microsoft.AspNet.Identity.Test\Microsoft.AspNet.Identity.Test.net45.csproj", "{E00E23B0-79B8-41E1-9998-57FECA1F2535}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Aspnet.Identity.InMemory.Test.net45", "test\Microsoft.Aspnet.Identity.InMemory.Test\Microsoft.Aspnet.Identity.InMemory.Test.net45.csproj", "{2C0D3053-1B4E-4654-A70E-13A9422D53E9}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Aspnet.Identity.InMemory.Test.net45", "test\Microsoft.Aspnet.Identity.InMemory.Test\Microsoft.Aspnet.Identity.InMemory.Test.net45.csproj", "{9102E676-B509-4A78-AD66-A479C50FD1C3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -61,24 +61,24 @@ Global
{E00E23B0-79B8-41E1-9998-57FECA1F2535}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E00E23B0-79B8-41E1-9998-57FECA1F2535}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E00E23B0-79B8-41E1-9998-57FECA1F2535}.Release|Any CPU.Build.0 = Release|Any CPU
{2C0D3053-1B4E-4654-A70E-13A9422D53E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2C0D3053-1B4E-4654-A70E-13A9422D53E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2C0D3053-1B4E-4654-A70E-13A9422D53E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2C0D3053-1B4E-4654-A70E-13A9422D53E9}.Release|Any CPU.Build.0 = Release|Any CPU
{9102E676-B509-4A78-AD66-A479C50FD1C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9102E676-B509-4A78-AD66-A479C50FD1C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9102E676-B509-4A78-AD66-A479C50FD1C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9102E676-B509-4A78-AD66-A479C50FD1C3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{B72401D7-47F6-4A98-89D5-CCBFEFC5B2B8} = {F6B0C0E9-C346-49D0-B583-95B6CE04BB1B}
{6211450F-FFB8-431F-84E2-9A7620875260} = {77CEDA6C-A833-455D-8357-649BFD944724}
{77CEDA6C-A833-455D-8357-649BFD944724} = {0F647068-6602-4E24-B1DC-8ED91481A50A}
{F6B0C0E9-C346-49D0-B583-95B6CE04BB1B} = {0F647068-6602-4E24-B1DC-8ED91481A50A}
{E52361C9-1F0B-4229-86A0-E5C7C12A5429} = {F6B0C0E9-C346-49D0-B583-95B6CE04BB1B}
{D32483A4-B617-480C-81E6-49CD596B9A34} = {77CEDA6C-A833-455D-8357-649BFD944724}
{054B3FFA-7196-466F-9A8A-593FFE037A69} = {F6B0C0E9-C346-49D0-B583-95B6CE04BB1B}
{D2E7A146-C39F-4302-8EA3-BFA8C1082939} = {77CEDA6C-A833-455D-8357-649BFD944724}
{77CEDA6C-A833-455D-8357-649BFD944724} = {0F647068-6602-4E24-B1DC-8ED91481A50A}
{E00E23B0-79B8-41E1-9998-57FECA1F2535} = {52D59F18-62D2-4D17-8CF2-BE192445AF8E}
{2C0D3053-1B4E-4654-A70E-13A9422D53E9} = {52D59F18-62D2-4D17-8CF2-BE192445AF8E}
{9102E676-B509-4A78-AD66-A479C50FD1C3} = {52D59F18-62D2-4D17-8CF2-BE192445AF8E}
{B72401D7-47F6-4A98-89D5-CCBFEFC5B2B8} = {F6B0C0E9-C346-49D0-B583-95B6CE04BB1B}
{E52361C9-1F0B-4229-86A0-E5C7C12A5429} = {F6B0C0E9-C346-49D0-B583-95B6CE04BB1B}
{054B3FFA-7196-466F-9A8A-593FFE037A69} = {F6B0C0E9-C346-49D0-B583-95B6CE04BB1B}
{6211450F-FFB8-431F-84E2-9A7620875260} = {77CEDA6C-A833-455D-8357-649BFD944724}
{D32483A4-B617-480C-81E6-49CD596B9A34} = {77CEDA6C-A833-455D-8357-649BFD944724}
{D2E7A146-C39F-4302-8EA3-BFA8C1082939} = {77CEDA6C-A833-455D-8357-649BFD944724}
EndGlobalSection
EndGlobal

Просмотреть файл

@ -125,7 +125,7 @@ namespace Microsoft.AspNet.Identity
}
// make sure email is not empty, valid, and unique
private async Task ValidateEmail(UserManager<TUser, TKey> manager, TUser user, List<string> errors)
private static async Task ValidateEmail(UserManager<TUser, TKey> manager, TUser user, List<string> errors)
{
var email = await manager.GetEmailStore().GetEmail(user).ConfigureAwait(false);
if (string.IsNullOrWhiteSpace(email))

Просмотреть файл

@ -19,6 +19,38 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
Assert.Null(await manager.FindById(user.Id));
}
[Fact]
public async Task CanUpdateUserName()
{
var manager = CreateManager();
var user = new InMemoryUser("Update");
IdentityResultAssert.IsSuccess(await manager.Create(user));
Assert.Null(await manager.FindByName("New"));
user.UserName = "New";
IdentityResultAssert.IsSuccess(await manager.Update(user));
Assert.NotNull(await manager.FindByName("New"));
Assert.Null(await manager.FindByName("Update"));
}
[Fact]
public async Task ValidatorCanBlockCreate()
{
var manager = CreateManager();
var user = new InMemoryUser("CreateBlocked");
manager.UserValidator = new AlwaysBadValidator();
IdentityResultAssert.IsFailure(await manager.Create(user), AlwaysBadValidator.ErrorMessage);
}
[Fact]
public async Task ValidatorCanBlockUpdate()
{
var manager = CreateManager();
var user = new InMemoryUser("UpdateBlocked");
IdentityResultAssert.IsSuccess(await manager.Create(user));
manager.UserValidator = new AlwaysBadValidator();
IdentityResultAssert.IsFailure(await manager.Update(user), AlwaysBadValidator.ErrorMessage);
}
[Fact]
public async Task CanCreateUserNoPassword()
{
@ -68,6 +100,16 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
Assert.Equal(user, await manager.Find(user.UserName, "password"));
}
[Fact]
public async Task AddPasswordFailsIfAlreadyHave()
{
var manager = CreateManager();
var user = new InMemoryUser("CannotAddAnotherPassword");
IdentityResultAssert.IsSuccess(await manager.Create(user, "Password"));
Assert.True(await manager.HasPassword(user.Id));
IdentityResultAssert.IsFailure(await manager.AddPassword(user.Id, "password"), "User already has a password set.");
}
[Fact]
public async Task CanCreateUserAddRemoveLogin()
{
@ -341,6 +383,18 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
Assert.False(await manager.IsEmailConfirmed(user.Id));
}
[Fact]
public async Task ConfirmEmailWithStaticTokenFailsWithWrongToken()
{
var manager = CreateManager();
manager.UserTokenProvider = new StaticTokenProvider();
var user = new InMemoryUser("test");
Assert.False(user.EmailConfirmed);
IdentityResultAssert.IsSuccess(await manager.Create(user));
IdentityResultAssert.IsFailure(await manager.ConfirmEmail(user.Id, "bogus"), "Invalid token.");
Assert.False(await manager.IsEmailConfirmed(user.Id));
}
// TODO: Can't reenable til we have a SecurityStamp linked token provider
//[Fact]
//public async Task ConfirmTokenFailsAfterPasswordChange()
@ -910,15 +964,19 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
private class EmailTokenProvider : IUserTokenProvider<InMemoryUser, string>
{
private static string MakeToken(string purpose)
{
return "email:" + purpose;
}
public Task<string> Generate(string purpose, UserManager<InMemoryUser, string> manager, InMemoryUser user)
{
return Task.FromResult(purpose);
return Task.FromResult(MakeToken(purpose));
}
public Task<bool> Validate(string purpose, string token, UserManager<InMemoryUser, string> manager, InMemoryUser user)
{
return Task.FromResult(token == purpose);
return Task.FromResult(token == MakeToken(purpose));
}
public Task Notify(string token, UserManager<InMemoryUser, string> manager, InMemoryUser user)
@ -926,23 +984,27 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
return manager.SendEmail(user.Id, token, token);
}
public Task<bool> IsValidProviderForUser(UserManager<InMemoryUser, string> manager, InMemoryUser user)
public async Task<bool> IsValidProviderForUser(UserManager<InMemoryUser, string> manager, InMemoryUser user)
{
return Task.FromResult(true);
return !string.IsNullOrEmpty(await manager.GetEmail(user.Id));
}
}
private class SmsTokenProvider : IUserTokenProvider<InMemoryUser, string>
{
private static string MakeToken(string purpose)
{
return "sms:" + purpose;
}
public Task<string> Generate(string purpose, UserManager<InMemoryUser, string> manager, InMemoryUser user)
{
return Task.FromResult(purpose);
return Task.FromResult(MakeToken(purpose));
}
public Task<bool> Validate(string purpose, string token, UserManager<InMemoryUser, string> manager, InMemoryUser user)
{
return Task.FromResult(token == purpose);
return Task.FromResult(token == MakeToken(purpose));
}
public Task Notify(string token, UserManager<InMemoryUser, string> manager, InMemoryUser user)
@ -950,9 +1012,9 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
return manager.SendSms(user.Id, token);
}
public Task<bool> IsValidProviderForUser(UserManager<InMemoryUser, string> manager, InMemoryUser user)
public async Task<bool> IsValidProviderForUser(UserManager<InMemoryUser, string> manager, InMemoryUser user)
{
return Task.FromResult(true);
return !string.IsNullOrEmpty(await manager.GetPhoneNumber(user.Id));
}
}
@ -1130,32 +1192,32 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
Assert.True(!factors.Any());
}
//[Fact]
//public async Task GetValidTwoFactorTest()
//{
// var manager = CreateManager();
// manager.RegisterTwoFactorProvider("phone", new PhoneNumberTokenProvider<InMemoryUser>());
// manager.RegisterTwoFactorProvider("email", new EmailTokenProvider<InMemoryUser>());
// var user = new InMemoryUser("test");
// IdentityResultAssert.IsSuccess(await manager.Create(user));
// var factors = await manager.GetValidTwoFactorProviders(user.Id);
// Assert.NotNull(factors);
// Assert.True(factors.Count() == 0);
// IdentityResultAssert.IsSuccess(await manager.SetPhoneNumber(user.Id, "111-111-1111"));
// factors = await manager.GetValidTwoFactorProviders(user.Id);
// Assert.NotNull(factors);
// Assert.True(factors.Count() == 1);
// Assert.Equal("phone", factors[0]);
// IdentityResultAssert.IsSuccess(await manager.SetEmail(user.Id, "test@test.com"));
// factors = await manager.GetValidTwoFactorProviders(user.Id);
// Assert.NotNull(factors);
// Assert.True(factors.Count() == 2);
// IdentityResultAssert.IsSuccess(await manager.SetEmail(user.Id, null));
// factors = await manager.GetValidTwoFactorProviders(user.Id);
// Assert.NotNull(factors);
// Assert.True(factors.Count() == 1);
// Assert.Equal("phone", factors[0]);
//}
[Fact]
public async Task GetValidTwoFactorTest()
{
var manager = CreateManager();
manager.RegisterTwoFactorProvider("phone", new SmsTokenProvider());
manager.RegisterTwoFactorProvider("email", new EmailTokenProvider());
var user = new InMemoryUser("test");
IdentityResultAssert.IsSuccess(await manager.Create(user));
var factors = await manager.GetValidTwoFactorProviders(user.Id);
Assert.NotNull(factors);
Assert.True(!factors.Any());
IdentityResultAssert.IsSuccess(await manager.SetPhoneNumber(user.Id, "111-111-1111"));
factors = await manager.GetValidTwoFactorProviders(user.Id);
Assert.NotNull(factors);
Assert.True(factors.Count() == 1);
Assert.Equal("phone", factors[0]);
IdentityResultAssert.IsSuccess(await manager.SetEmail(user.Id, "test@test.com"));
factors = await manager.GetValidTwoFactorProviders(user.Id);
Assert.NotNull(factors);
Assert.True(factors.Count() == 2);
IdentityResultAssert.IsSuccess(await manager.SetEmail(user.Id, null));
factors = await manager.GetValidTwoFactorProviders(user.Id);
Assert.NotNull(factors);
Assert.True(factors.Count() == 1);
Assert.Equal("phone", factors[0]);
}
//[Fact]
//public async Task PhoneFactorFailsAfterSecurityStampChangeTest()
@ -1174,38 +1236,29 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
// Assert.False(await manager.VerifyTwoFactorToken(user.Id, factorId, token));
//}
//[Fact]
//public async Task WrongTokenProviderFailsTest()
//{
// var manager = CreateManager();
// var factorId = "PhoneCode";
// manager.RegisterTwoFactorProvider(factorId, new PhoneNumberTokenProvider<InMemoryUser>());
// manager.RegisterTwoFactorProvider("EmailCode", new EmailTokenProvider<InMemoryUser>());
// var user = new InMemoryUser("PhoneCodeTest");
// user.PhoneNumber = "4251234567";
// IdentityResultAssert.IsSuccess(await manager.Create(user));
// var stamp = user.SecurityStamp;
// Assert.NotNull(stamp);
// var token = await manager.GenerateTwoFactorToken(user.Id, factorId);
// Assert.NotNull(token);
// Assert.False(await manager.VerifyTwoFactorToken(user.Id, "EmailCode", token));
//}
[Fact]
public async Task VerifyTokenFromWrongTokenProviderFails()
{
var manager = CreateManager();
manager.RegisterTwoFactorProvider("PhoneCode", new SmsTokenProvider());
manager.RegisterTwoFactorProvider("EmailCode", new EmailTokenProvider());
var user = new InMemoryUser("WrongTokenProviderTest") {PhoneNumber = "4251234567"};
IdentityResultAssert.IsSuccess(await manager.Create(user));
var token = await manager.GenerateTwoFactorToken(user.Id, "PhoneCode");
Assert.NotNull(token);
Assert.False(await manager.VerifyTwoFactorToken(user.Id, "EmailCode", token));
}
//[Fact]
//public async Task WrongTokenFailsTest()
//{
// var manager = CreateManager();
// var factorId = "PhoneCode";
// manager.RegisterTwoFactorProvider(factorId, new PhoneNumberTokenProvider<InMemoryUser>());
// var user = new InMemoryUser("PhoneCodeTest");
// user.PhoneNumber = "4251234567";
// IdentityResultAssert.IsSuccess(await manager.Create(user));
// var stamp = user.SecurityStamp;
// Assert.NotNull(stamp);
// var token = await manager.GenerateTwoFactorToken(user.Id, factorId);
// Assert.NotNull(token);
// Assert.False(await manager.VerifyTwoFactorToken(user.Id, factorId, "abc"));
//}
[Fact]
public async Task VerifyWithWrongSmsTokenFails()
{
var manager = CreateManager();
const string factorId = "PhoneCode";
manager.RegisterTwoFactorProvider(factorId, new SmsTokenProvider());
var user = new InMemoryUser("PhoneCodeTest") {PhoneNumber = "4251234567"};
IdentityResultAssert.IsSuccess(await manager.Create(user));
Assert.False(await manager.VerifyTwoFactorToken(user.Id, factorId, "bogus"));
}
private static UserManager<InMemoryUser, string> CreateManager()
{

Просмотреть файл

@ -16,5 +16,15 @@ namespace Microsoft.AspNet.Identity.Test
Assert.Equal(1, result.Errors.Count());
Assert.Equal("An unknown failure has occured.", result.Errors.First());
}
[Fact]
public void NullErrorListUsesDefaultError()
{
var result = new IdentityResult(null);
Assert.False(result.Succeeded);
Assert.Equal(1, result.Errors.Count());
Assert.Equal("An unknown failure has occured.", result.Errors.First());
}
}
}

Просмотреть файл

@ -19,10 +19,10 @@ namespace Microsoft.AspNet.Identity.Test
}
[Theory,
InlineData(""),
InlineData("abc"),
InlineData("abcde")]
[Theory]
[InlineData("")]
[InlineData("abc")]
[InlineData("abcde")]
public async Task FailsIfTooShortTests(string input)
{
const string error = "Passwords must be at least 6 characters.";
@ -30,27 +30,27 @@ namespace Microsoft.AspNet.Identity.Test
IdentityResultAssert.IsFailure(await valid.Validate(input), error);
}
[Theory,
InlineData("abcdef"),
InlineData("aaaaaaaaaaa")]
[Theory]
[InlineData("abcdef")]
[InlineData("aaaaaaaaaaa")]
public async Task SuccessIfLongEnoughTests(string input) {
var valid = new PasswordValidator {RequiredLength = 6};
IdentityResultAssert.IsSuccess(await valid.Validate(input));
}
[Theory,
InlineData("a"),
InlineData("aaaaaaaaaaa")]
[Theory]
[InlineData("a")]
[InlineData("aaaaaaaaaaa")]
public async Task FailsWithoutRequiredNonAlphanumericTests(string input)
{
var valid = new PasswordValidator { RequireNonLetterOrDigit = true };
IdentityResultAssert.IsFailure(await valid.Validate(input), "Passwords must have at least one non letter or digit character.");
}
[Theory,
InlineData("@"),
InlineData("abcd@e!ld!kajfd"),
InlineData("!!!!!!")]
[Theory]
[InlineData("@")]
[InlineData("abcd@e!ld!kajfd")]
[InlineData("!!!!!!")]
public async Task SucceedsWithRequiredNonAlphanumericTests(string input)
{
var valid = new PasswordValidator { RequireNonLetterOrDigit = true };
@ -68,13 +68,13 @@ namespace Microsoft.AspNet.Identity.Test
Digit = 32,
}
[Theory,
InlineData("abcde", Errors.Length | Errors.Alpha | Errors.Upper | Errors.Digit),
InlineData("a@B@cd", Errors.Digit),
InlineData("___", Errors.Length | Errors.Digit | Errors.Lower | Errors.Upper),
InlineData("a_b9de", Errors.Upper),
InlineData("abcd@e!ld!kaj9Fd", Errors.None),
InlineData("aB1@df", Errors.None)]
[Theory]
[InlineData("abcde", Errors.Length | Errors.Alpha | Errors.Upper | Errors.Digit)]
[InlineData("a@B@cd", Errors.Digit)]
[InlineData("___", Errors.Length | Errors.Digit | Errors.Lower | Errors.Upper)]
[InlineData("a_b9de", Errors.Upper)]
[InlineData("abcd@e!ld!kaj9Fd", Errors.None)]
[InlineData("aB1@df", Errors.None)]
public async Task UberMixedRequiredTests(string input, Errors errorMask)
{
const string alphaError = "Passwords must have at least one non letter or digit character.";

Просмотреть файл

@ -42,6 +42,20 @@ namespace Microsoft.AspNet.Identity.Test
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await manager.Update(null));
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await manager.Delete(null));
await Assert.ThrowsAsync<ArgumentNullException>("roleName", async () => await manager.FindByName(null));
await Assert.ThrowsAsync<ArgumentNullException>("roleName", async () => await manager.RoleExists(null));
}
[Fact]
public async Task RoleStoreMethodsThrowWhenDisposed()
{
var manager = new RoleManager<TestRole, string>(new NoopRoleStore());
manager.Dispose();
await Assert.ThrowsAsync<ObjectDisposedException>(() => manager.FindById(null));
await Assert.ThrowsAsync<ObjectDisposedException>(() => manager.FindByName(null));
await Assert.ThrowsAsync<ObjectDisposedException>(() => manager.RoleExists(null));
await Assert.ThrowsAsync<ObjectDisposedException>(() => manager.Create(null));
await Assert.ThrowsAsync<ObjectDisposedException>(() => manager.Update(null));
await Assert.ThrowsAsync<ObjectDisposedException>(() => manager.Delete(null));
}
private class NotImplementedStore : IRoleStore<TestRole, string>

Просмотреть файл

@ -0,0 +1,39 @@
using System;
using System.Threading.Tasks;
using Xunit;
namespace Microsoft.AspNet.Identity.Test
{
public class RoleValidatorTest
{
[Fact]
public async Task ValidateThrowsWithNull()
{
// Setup
var manager = new RoleManager<TestRole, string>(new NoopRoleStore());
var validator = new RoleValidator<TestRole, string>();
// Act
// Assert
await Assert.ThrowsAsync<ArgumentNullException>("manager", async () => await validator.Validate(null, null));
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await validator.Validate(manager, null));
}
[Theory]
[InlineData(null)]
[InlineData("")]
public async Task ValidateFailsWithTooShortRoleName(string input)
{
// Setup
var manager = new RoleManager<TestRole, string>(new NoopRoleStore());
var validator = new RoleValidator<TestRole, string>();
var user = new TestRole { Name = input };
// Act
var result = await validator.Validate(manager, user);
// Assert
IdentityResultAssert.IsFailure(result, "Name cannot be null or empty.");
}
}
}

Просмотреть файл

@ -39,7 +39,7 @@ namespace Microsoft.AspNet.Identity.Test
//}
[Fact]
public void UsersQueryableFailWhenStoreNotImplementedTest()
public void UsersQueryableFailWhenStoreNotImplemented()
{
var manager = new UserManager<TestUser, string>(new NoopUserStore());
Assert.False(manager.SupportsQueryableUsers);
@ -47,7 +47,7 @@ namespace Microsoft.AspNet.Identity.Test
}
[Fact]
public async Task UsersEmailMethodsFailWhenStoreNotImplementedTest()
public async Task UsersEmailMethodsFailWhenStoreNotImplemented()
{
var manager = new UserManager<TestUser, string>(new NoopUserStore());
Assert.False(manager.SupportsUserEmail);
@ -59,7 +59,7 @@ namespace Microsoft.AspNet.Identity.Test
}
[Fact]
public async Task UsersPhoneNumberMethodsFailWhenStoreNotImplementedTest()
public async Task UsersPhoneNumberMethodsFailWhenStoreNotImplemented()
{
var manager = new UserManager<TestUser, string>(new NoopUserStore());
Assert.False(manager.SupportsUserPhoneNumber);
@ -69,7 +69,7 @@ namespace Microsoft.AspNet.Identity.Test
}
[Fact]
public async Task TokenMethodsThrowWithNoTokenProviderTest()
public async Task TokenMethodsThrowWithNoTokenProvider()
{
var manager = new UserManager<TestUser, string>(new NoopUserStore());
await Assert.ThrowsAsync<NotSupportedException>(
@ -79,7 +79,7 @@ namespace Microsoft.AspNet.Identity.Test
}
[Fact]
public async Task PasswordMethodsFailWhenStoreNotImplementedTest()
public async Task PasswordMethodsFailWhenStoreNotImplemented()
{
var manager = new UserManager<TestUser, string>(new NoopUserStore());
Assert.False(manager.SupportsUserPassword);
@ -92,7 +92,7 @@ namespace Microsoft.AspNet.Identity.Test
}
[Fact]
public async Task SecurityStampMethodsFailWhenStoreNotImplementedTest()
public async Task SecurityStampMethodsFailWhenStoreNotImplemented()
{
var manager = new UserManager<TestUser, string>(new NoopUserStore());
Assert.False(manager.SupportsUserSecurityStamp);
@ -103,7 +103,7 @@ namespace Microsoft.AspNet.Identity.Test
}
[Fact]
public async Task LoginMethodsFailWhenStoreNotImplementedTest()
public async Task LoginMethodsFailWhenStoreNotImplemented()
{
var manager = new UserManager<TestUser, string>(new NoopUserStore());
Assert.False(manager.SupportsUserLogin);
@ -114,7 +114,7 @@ namespace Microsoft.AspNet.Identity.Test
}
[Fact]
public async Task ClaimMethodsFailWhenStoreNotImplementedTest()
public async Task ClaimMethodsFailWhenStoreNotImplemented()
{
var manager = new UserManager<TestUser, string>(new NoopUserStore());
Assert.False(manager.SupportsUserClaim);
@ -124,7 +124,7 @@ namespace Microsoft.AspNet.Identity.Test
}
[Fact]
public async Task TwoFactorStoreMethodsFailWhenStoreNotImplementedTest()
public async Task TwoFactorStoreMethodsFailWhenStoreNotImplemented()
{
var manager = new UserManager<TestUser, string>(new NoopUserStore());
Assert.False(manager.SupportsUserTwoFactor);
@ -133,7 +133,20 @@ namespace Microsoft.AspNet.Identity.Test
}
[Fact]
public async Task RoleMethodsFailWhenStoreNotImplementedTest()
public async Task LockoutStoreMethodsFailWhenStoreNotImplemented()
{
var manager = new UserManager<TestUser, string>(new NoopUserStore());
Assert.False(manager.SupportsUserLockout);
await Assert.ThrowsAsync<NotSupportedException>(async () => await manager.GetLockoutEnabled("bogus"));
await Assert.ThrowsAsync<NotSupportedException>(async () => await manager.SetLockoutEnabled("bogus", true));
await Assert.ThrowsAsync<NotSupportedException>(async () => await manager.AccessFailed("bogus"));
await Assert.ThrowsAsync<NotSupportedException>(async () => await manager.IsLockedOut("bogus"));
await Assert.ThrowsAsync<NotSupportedException>(async () => await manager.ResetAccessFailedCount("bogus"));
await Assert.ThrowsAsync<NotSupportedException>(async () => await manager.GetAccessFailedCount("bogus"));
}
[Fact]
public async Task RoleMethodsFailWhenStoreNotImplemented()
{
var manager = new UserManager<TestUser, string>(new NoopUserStore());
Assert.False(manager.SupportsUserRole);
@ -278,6 +291,8 @@ namespace Microsoft.AspNet.Identity.Test
async () => await manager.AccessFailed(null), error);
await ExceptionAssert.ThrowsAsync<InvalidOperationException>(
async () => await manager.ResetAccessFailedCount(null), error);
await ExceptionAssert.ThrowsAsync<InvalidOperationException>(
async () => await manager.GetAccessFailedCount(null), error);
await ExceptionAssert.ThrowsAsync<InvalidOperationException>(
async () => await manager.GetLockoutEnabled(null), error);
await ExceptionAssert.ThrowsAsync<InvalidOperationException>(

Просмотреть файл

@ -19,9 +19,9 @@ namespace Microsoft.AspNet.Identity.Test
await Assert.ThrowsAsync<ArgumentNullException>("user", () => validator.Validate(manager, null));
}
[Theory,
InlineData(null),
InlineData("")]
[Theory]
[InlineData(null)]
[InlineData("")]
public async Task ValidateFailsWithTooShortUserNames(string input)
{
// Setup
@ -36,13 +36,12 @@ namespace Microsoft.AspNet.Identity.Test
IdentityResultAssert.IsFailure(result, "UserName cannot be null or empty.");
}
[Theory,
InlineData("test_email@foo.com", true),
InlineData("hao", true),
InlineData("test123", true),
InlineData("!noway", false),
InlineData("foo@boz#.com", false),
]
[Theory]
[InlineData("test_email@foo.com", true)]
[InlineData("hao", true)]
[InlineData("test123", true)]
[InlineData("!noway", false)]
[InlineData("foo@boz#.com", false)]
public async Task DefaultAlphaNumericOnlyUserNameValidation(string userName, bool expectSuccess)
{
// Setup
@ -64,13 +63,12 @@ namespace Microsoft.AspNet.Identity.Test
}
}
[Theory,
InlineData("test_email@foo.com", true),
InlineData("hao", true),
InlineData("test123", true),
InlineData("!noway", true),
InlineData("foo@boz#.com", true),
]
[Theory]
[InlineData("test_email@foo.com", true)]
[InlineData("hao", true)]
[InlineData("test123", true)]
[InlineData("!noway", true)]
[InlineData("foo@boz#.com", true)]
public async Task CanAllowNonAlphaNumericUserName(string userName, bool expectSuccess)
{
// Setup
@ -91,6 +89,5 @@ namespace Microsoft.AspNet.Identity.Test
IdentityResultAssert.IsFailure(result);
}
}
}
}