diff --git a/global.json b/global.json
new file mode 100644
index 0000000000..840c36f6ad
--- /dev/null
+++ b/global.json
@@ -0,0 +1,3 @@
+{
+ "sources": ["src"]
+}
\ No newline at end of file
diff --git a/src/Microsoft.AspNet.Identity/IUserValidator.cs b/src/Microsoft.AspNet.Identity/IUserValidator.cs
index 0480f91b1a..807b00cd60 100644
--- a/src/Microsoft.AspNet.Identity/IUserValidator.cs
+++ b/src/Microsoft.AspNet.Identity/IUserValidator.cs
@@ -1,3 +1,4 @@
+using System;
using System.Threading.Tasks;
namespace Microsoft.AspNet.Identity
@@ -5,14 +6,18 @@ namespace Microsoft.AspNet.Identity
///
/// Used to validate a user
///
- ///
- public interface IUserValidator
+ ///
+ ///
+ public interface IUserValidator
+ where TUser : class, IUser
+ where TKey : IEquatable
{
///
/// Validate the user
///
+ ///
///
///
- Task Validate(T user);
+ Task Validate(UserManager manager, TUser user);
}
}
\ No newline at end of file
diff --git a/src/Microsoft.AspNet.Identity/UserManager.cs b/src/Microsoft.AspNet.Identity/UserManager.cs
index f71c3d7663..c2df3c4f8a 100644
--- a/src/Microsoft.AspNet.Identity/UserManager.cs
+++ b/src/Microsoft.AspNet.Identity/UserManager.cs
@@ -36,11 +36,11 @@ namespace Microsoft.AspNet.Identity
{
throw new ArgumentNullException("serviceProvider");
}
- Store = serviceProvider.GetService>();
- ClaimsIdentityFactory = serviceProvider.GetService>();
PasswordHasher = serviceProvider.GetService();
- UserValidator = serviceProvider.GetService>();
+ UserValidator = serviceProvider.GetService>();
PasswordValidator = serviceProvider.GetService();
+ //TODO: Store = serviceProvider.GetService>();
+ //TODO: ClaimsIdentityFactory = serviceProvider.GetService>();
// TODO: maybe each optional store as well? Email and SMS services?
}
@@ -55,7 +55,7 @@ namespace Microsoft.AspNet.Identity
throw new ArgumentNullException("store");
}
Store = store;
- UserValidator = new UserValidator(this);
+ UserValidator = new UserValidator();
PasswordHasher = new PasswordHasher();
//TODO: ClaimsIdentityFactory = new ClaimsIdentityFactory();
}
@@ -89,7 +89,7 @@ namespace Microsoft.AspNet.Identity
///
/// Used to validate users before persisting changes
///
- public IUserValidator UserValidator { get; set; }
+ public IUserValidator UserValidator { get; set; }
///
/// Used to validate passwords before persisting changes
@@ -322,7 +322,7 @@ namespace Microsoft.AspNet.Identity
}
private async Task ValidateUserInternal(TUser user) {
- return (UserValidator == null) ? IdentityResult.Success : await UserValidator.Validate(user).ConfigureAwait(false);
+ return (UserValidator == null) ? IdentityResult.Success : await UserValidator.Validate(this, user).ConfigureAwait(false);
}
///
diff --git a/src/Microsoft.AspNet.Identity/UserValidator.cs b/src/Microsoft.AspNet.Identity/UserValidator.cs
index 3c673213af..0ef6ec13e2 100644
--- a/src/Microsoft.AspNet.Identity/UserValidator.cs
+++ b/src/Microsoft.AspNet.Identity/UserValidator.cs
@@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
using System.Globalization;
+using System.Linq;
#if NET45
using System.Net.Mail;
#endif
-using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Microsoft.AspNet.Identity
@@ -14,22 +14,17 @@ namespace Microsoft.AspNet.Identity
///
///
///
- public class UserValidator : IUserValidator
+ ///
+ public class UserValidator : IUserValidator
where TUser : class, IUser
where TKey : IEquatable
{
///
/// Constructor
///
- ///
- public UserValidator(UserManager manager)
+ public UserValidator()
{
- if (manager == null)
- {
- throw new ArgumentNullException("manager");
- }
AllowOnlyAlphanumericUserNames = true;
- Manager = manager;
}
///
@@ -42,24 +37,27 @@ namespace Microsoft.AspNet.Identity
///
public bool RequireUniqueEmail { get; set; }
- private UserManager Manager { get; set; }
-
///
/// Validates a user before saving
///
- ///
+ ///
+ ///
///
- public virtual async Task Validate(TUser item)
+ public virtual async Task Validate(UserManager manager, TUser user)
{
- if (item == null)
+ if (manager == null)
{
- throw new ArgumentNullException("item");
+ throw new ArgumentNullException("manager");
+ }
+ if (user == null)
+ {
+ throw new ArgumentNullException("user");
}
var errors = new List();
- await ValidateUserName(item, errors);
+ await ValidateUserName(manager, user, errors);
if (RequireUniqueEmail)
{
- await ValidateEmail(item, errors);
+ await ValidateEmail(manager, user, errors);
}
if (errors.Count > 0)
{
@@ -68,20 +66,60 @@ namespace Microsoft.AspNet.Identity
return IdentityResult.Success;
}
- private async Task ValidateUserName(TUser user, List errors)
+ ///
+ /// Returns true if the character is a digit between '0' and '9'
+ ///
+ ///
+ ///
+ public virtual bool IsDigit(char c)
+ {
+ return c >= '0' && c <= '9';
+ }
+
+ ///
+ /// Returns true if the character is between 'a' and 'z'
+ ///
+ ///
+ ///
+ public virtual bool IsLower(char c)
+ {
+ return c >= 'a' && c <= 'z';
+ }
+
+ ///
+ /// Returns true if the character is between 'A' and 'Z'
+ ///
+ ///
+ ///
+ public virtual bool IsUpper(char c)
+ {
+ return c >= 'A' && c <= 'Z';
+ }
+
+ ///
+ /// Returns true if the character is upper, lower, or a digit
+ ///
+ ///
+ ///
+ public virtual bool IsAlphaNumeric(char c)
+ {
+ return IsUpper(c) || IsLower(c) || IsDigit(c) || c == '@' || c == '_';
+ }
+
+ private async Task ValidateUserName(UserManager manager, TUser user, ICollection errors)
{
if (string.IsNullOrWhiteSpace(user.UserName))
{
errors.Add(String.Format(CultureInfo.CurrentCulture, Resources.PropertyTooShort, "Name"));
}
- else if (AllowOnlyAlphanumericUserNames && !Regex.IsMatch(user.UserName, @"^[A-Za-z0-9@_\.]+$"))
+ else if (AllowOnlyAlphanumericUserNames && !user.UserName.All(IsAlphaNumeric))
{
// If any characters are not letters or digits, its an illegal user name
errors.Add(String.Format(CultureInfo.CurrentCulture, Resources.InvalidUserName, user.UserName));
}
else
{
- var owner = await Manager.FindByName(user.UserName);
+ var owner = await manager.FindByName(user.UserName);
if (owner != null && !EqualityComparer.Default.Equals(owner.Id, user.Id))
{
errors.Add(String.Format(CultureInfo.CurrentCulture, Resources.DuplicateName, user.UserName));
@@ -90,9 +128,9 @@ namespace Microsoft.AspNet.Identity
}
// make sure email is not empty, valid, and unique
- private async Task ValidateEmail(TUser user, List errors)
+ private async Task ValidateEmail(UserManager manager, TUser user, List errors)
{
- var email = await Manager.GetEmailStore().GetEmail(user).ConfigureAwait(false);
+ var email = await manager.GetEmailStore().GetEmail(user).ConfigureAwait(false);
if (string.IsNullOrWhiteSpace(email))
{
errors.Add(String.Format(CultureInfo.CurrentCulture, Resources.PropertyTooShort, "Email"));
@@ -109,7 +147,7 @@ namespace Microsoft.AspNet.Identity
return;
}
#endif
- var owner = await Manager.FindByEmail(email);
+ var owner = await manager.FindByEmail(email);
if (owner != null && !EqualityComparer.Default.Equals(owner.Id, user.Id))
{
errors.Add(String.Format(CultureInfo.CurrentCulture, Resources.DuplicateEmail, email));
diff --git a/src/Microsoft.AspNet.Identity/project.json b/src/Microsoft.AspNet.Identity/project.json
index 07cc04355c..662afb86e8 100644
--- a/src/Microsoft.AspNet.Identity/project.json
+++ b/src/Microsoft.AspNet.Identity/project.json
@@ -1,28 +1,33 @@
{
- "version": "0.1-alpha-*",
+ "version" : "0.1-alpha-*",
"dependencies": {
"Microsoft.AspNet.DependencyInjection" : "0.1-alpha-*",
"System.Security.Claims" : "0.1-alpha-*",
"Microsoft.AspNet.Security.DataProtection" : "0.1-alpha-*"
},
"configurations": {
- "net45": {},
+ "net45": {
+ "dependencies": {
+ "System.Runtime": "",
+ "System.Collections": ""
+ }
+ },
"k10": {
"dependencies": {
"System.Collections": "4.0.0.0",
+ "System.Collections.Concurrent": "4.0.0.0",
"System.ComponentModel": "4.0.0.0",
+ "System.Console": "4.0.0.0",
"System.Diagnostics.Debug": "4.0.10.0",
- "System.Diagnostics.Tools": "4.0.0.0",
"System.Globalization": "4.0.10.0",
"System.Linq": "4.0.0.0",
"System.Linq.Expressions": "4.0.0.0",
"System.Reflection": "4.0.10.0",
+ "System.Reflection.Extensions": "4.0.0.0",
"System.Resources.ResourceManager": "4.0.0.0",
"System.Runtime": "4.0.20.0",
"System.Runtime.Extensions": "4.0.10.0",
- "System.Security.Principal": "4.0.0.0",
- "System.Text.Encoding": "4.0.10.0",
- "System.Text.RegularExpressions": "4.0.0.0",
+ "System.Threading": "4.0.0.0",
"System.Threading.Tasks": "4.0.0.0"
}
}
diff --git a/test/Microsoft.AspNet.Identity.InMemory.Test/project.json b/test/Microsoft.AspNet.Identity.InMemory.Test/project.json
index 00342e9cc1..a7b301866e 100644
--- a/test/Microsoft.AspNet.Identity.InMemory.Test/project.json
+++ b/test/Microsoft.AspNet.Identity.InMemory.Test/project.json
@@ -3,13 +3,40 @@
"dependencies": {
"Microsoft.AspNet.Identity" : "0.1-alpha-*",
"Microsoft.AspNet.Identity.InMemory" : "0.1-alpha-*",
- "Microsoft.AspNet.DependencyInjection" : "0.1-alpha-*"
+ "Microsoft.AspNet.DependencyInjection" : "0.1-alpha-*",
+ "Xunit.KRunner": "0.1-alpha-*",
+ "xunit.abstractions": "3.0.0-alpha-*",
+ "xunit2": "0.1-alpha-*",
+ "xunit2.assert": "0.1-alpha-*"
},
"configurations": {
"net45": {
"dependencies": {
- "xunit": "1.9.2"
+ "System.Runtime": "",
+ "System.Collections": ""
+ }
+ },
+ "k10": {
+ "dependencies": {
+ "System.Collections": "4.0.0.0",
+ "System.Collections.Concurrent": "4.0.0.0",
+ "System.ComponentModel": "4.0.0.0",
+ "System.Console": "4.0.0.0",
+ "System.Diagnostics.Debug": "4.0.10.0",
+ "System.Globalization": "4.0.10.0",
+ "System.Linq": "4.0.0.0",
+ "System.Linq.Expressions": "4.0.0.0",
+ "System.Reflection": "4.0.10.0",
+ "System.Reflection.Extensions": "4.0.0.0",
+ "System.Resources.ResourceManager": "4.0.0.0",
+ "System.Runtime": "4.0.20.0",
+ "System.Runtime.Extensions": "4.0.10.0",
+ "System.Threading": "4.0.0.0",
+ "System.Threading.Tasks": "4.0.0.0"
}
}
+ },
+ "commands": {
+ "test": "Xunit.KRunner"
}
}
\ No newline at end of file
diff --git a/test/Microsoft.AspNet.Identity.Test/TestServices.cs b/test/Microsoft.AspNet.Identity.Test/TestServices.cs
new file mode 100644
index 0000000000..821ddb281f
--- /dev/null
+++ b/test/Microsoft.AspNet.Identity.Test/TestServices.cs
@@ -0,0 +1,78 @@
+using System;
+using System.Collections.Generic;
+using Microsoft.AspNet.DependencyInjection;
+
+namespace Microsoft.AspNet.Identity.Test
+{
+ public static class TestServices
+ {
+ public static IServiceProvider DefaultServiceProvider()
+ where TUser : class,IUser
+ where TKey : IEquatable
+ {
+ return new ServiceProvider().Add(TestServices.DefaultServices());
+ }
+
+ public static IEnumerable DefaultServices()
+ where TUser : class,IUser
+ where TKey : IEquatable
+ {
+ return new IServiceDescriptor[]
+ {
+ new ServiceDescriptor(),
+ new ServiceDescriptor, UserValidator>(),
+ new ServiceDescriptor(),
+ };
+ }
+
+ public class ServiceDescriptor : IServiceDescriptor
+ {
+ public ServiceDescriptor(LifecycleKind lifecycle = LifecycleKind.Transient)
+ {
+ Lifecycle = lifecycle;
+ }
+
+ public LifecycleKind Lifecycle { get; private set; }
+
+ public Type ServiceType
+ {
+ get { return typeof (TService); }
+ }
+
+ public Type ImplementationType
+ {
+ get { return typeof (TImplementation); }
+ }
+
+ public object ImplementationInstance
+ {
+ get { return null; }
+ }
+ }
+
+ public class ServiceInstanceDescriptor : IServiceDescriptor
+ {
+ public ServiceInstanceDescriptor(object instance)
+ {
+ ImplementationInstance = instance;
+ }
+
+ public LifecycleKind Lifecycle
+ {
+ get { return LifecycleKind.Singleton; }
+ }
+
+ public Type ServiceType
+ {
+ get { return typeof (TService); }
+ }
+
+ public Type ImplementationType
+ {
+ get { return null; }
+ }
+
+ public object ImplementationInstance { get; private set; }
+ }
+ }
+}
\ No newline at end of file
diff --git a/test/Microsoft.AspNet.Identity.Test/UserManagerTest.cs b/test/Microsoft.AspNet.Identity.Test/UserManagerTest.cs
new file mode 100644
index 0000000000..fffe48a947
--- /dev/null
+++ b/test/Microsoft.AspNet.Identity.Test/UserManagerTest.cs
@@ -0,0 +1,341 @@
+using Moq;
+using System;
+using System.Linq;
+using System.Threading.Tasks;
+using Xunit;
+
+namespace Microsoft.AspNet.Identity.Test
+{
+ public class UserManagerTest
+ {
+ [Fact]
+ public void ServiceProviderWireupTest()
+ {
+ var manager = new UserManager(TestServices.DefaultServiceProvider());
+ Assert.NotNull(manager.PasswordHasher);
+ Assert.NotNull(manager.PasswordValidator);
+ Assert.NotNull(manager.UserValidator);
+ }
+
+ // TODO: Mock fails in K (this works fine in net45)
+ //[Fact]
+ //public async Task CreateTest()
+ //{
+ // // Setup
+ // var store = new Mock>();
+ // var user = new TestUser();
+ // store.Setup(s => s.Create(user)).Verifiable();
+ // var userManager = new UserManager(store.Object);
+
+ // // Act
+ // var result = await userManager.Create(user);
+
+ // // Assert
+ // Assert.True(result.Succeeded);
+ // store.VerifyAll();
+ //}
+
+ [Fact]
+ public void UsersQueryableFailWhenStoreNotImplementedTest()
+ {
+ var manager = new UserManager(new NoopUserStore());
+ Assert.False(manager.SupportsQueryableUsers);
+ Assert.Throws(() => manager.Users.Count());
+ }
+
+ [Fact]
+ public void UsersEmailMethodsFailWhenStoreNotImplementedTest()
+ {
+ var manager = new UserManager(new NoopUserStore());
+ Assert.False(manager.SupportsUserEmail);
+ //Assert.Throws(() => manager.FindByEmail(null));
+ //Assert.Throws(() => manager.SetEmail(null, null));
+ //Assert.Throws(() => manager.GetEmail(null));
+ //Assert.Throws(() => manager.IsEmailConfirmed(null));
+ //Assert.Throws(() => manager.ConfirmEmail(null, null));
+ }
+
+ [Fact]
+ public void UsersPhoneNumberMethodsFailWhenStoreNotImplementedTest()
+ {
+ var manager = new UserManager(new NoopUserStore());
+ Assert.False(manager.SupportsUserPhoneNumber);
+ //Assert.Throws(() => manager.SetPhoneNumber(null, null)));
+ //Assert.Throws(() => manager.SetPhoneNumber(null, null));
+ //Assert.Throws(() => manager.GetPhoneNumber(null));
+ }
+
+ //[Fact]
+ //public void TokenMethodsThrowWithNoTokenProviderTest()
+ //{
+ // var manager = new UserManager(new NoopUserStore());
+ // Assert.Throws(
+ // () => AsyncHelper.RunSync(() => manager.GenerateUserTokenAsync(null, null)));
+ // Assert.Throws(
+ // () => AsyncHelper.RunSync(() => manager.VerifyUserTokenAsync(null, null, null)));
+ //}
+
+ [Fact]
+ public void PasswordMethodsFailWhenStoreNotImplementedTest()
+ {
+ var manager = new UserManager(new NoopUserStore());
+ Assert.False(manager.SupportsUserPassword);
+ //Assert.Throws(() => AsyncHelper.RunSync(() => manager.CreateAsync(null, null)));
+ //Assert.Throws(
+ // () => AsyncHelper.RunSync(() => manager.ChangePasswordAsync(null, null, null)));
+ //Assert.Throws(() => AsyncHelper.RunSync(() => manager.AddPasswordAsync(null, null)));
+ //Assert.Throws(() => AsyncHelper.RunSync(() => manager.RemovePasswordAsync(null)));
+ //Assert.Throws(() => AsyncHelper.RunSync(() => manager.CheckPasswordAsync(null, null)));
+ //Assert.Throws(() => AsyncHelper.RunSync(() => manager.HasPasswordAsync(null)));
+ }
+
+ [Fact]
+ public void SecurityStampMethodsFailWhenStoreNotImplementedTest()
+ {
+ var manager = new UserManager(new NoopUserStore());
+ Assert.False(manager.SupportsUserSecurityStamp);
+ //Assert.Throws(
+ // () => AsyncHelper.RunSync(() => manager.UpdateSecurityStampAsync("bogus")));
+ //Assert.Throws(() => AsyncHelper.RunSync(() => manager.GetSecurityStampAsync("bogus")));
+ //Assert.Throws(
+ // () => AsyncHelper.RunSync(() => manager.VerifyChangePhoneNumberTokenAsync("bogus", "1", "111-111-1111")));
+ //Assert.Throws(
+ // () => AsyncHelper.RunSync(() => manager.GenerateChangePhoneNumberTokenAsync("bogus", "111-111-1111")));
+ }
+
+ [Fact]
+ public void LoginMethodsFailWhenStoreNotImplementedTest()
+ {
+ var manager = new UserManager(new NoopUserStore());
+ Assert.False(manager.SupportsUserLogin);
+ //Assert.Throws(() => AsyncHelper.RunSync(() => manager.AddLoginAsync("bogus", null)));
+ //Assert.Throws(
+ // () => AsyncHelper.RunSync(() => manager.RemoveLoginAsync("bogus", null)));
+ //Assert.Throws(() => AsyncHelper.RunSync(() => manager.GetLoginsAsync("bogus")));
+ //Assert.Throws(() => AsyncHelper.RunSync(() => manager.FindAsync(null)));
+ }
+
+ [Fact]
+ public void ClaimMethodsFailWhenStoreNotImplementedTest()
+ {
+ var manager = new UserManager(new NoopUserStore());
+ Assert.False(manager.SupportsUserClaim);
+ //Assert.Throws(() => manager.AddClaim("bogus", null));
+ //Assert.Throws(() => manager.RemoveClaim("bogus", null));
+ //Assert.Throws(() => manager.GetClaims("bogus"));
+ }
+
+ [Fact]
+ public void TwoFactorStoreMethodsFailWhenStoreNotImplementedTest()
+ {
+ var manager = new UserManager(new NoopUserStore());
+ Assert.False(manager.SupportsUserTwoFactor);
+ //Assert.Throws(() => manager.GetTwoFactorEnabled("bogus"));
+ //Assert.Throws(() => manager.SetTwoFactorEnabled("bogus", true));
+ }
+
+ [Fact]
+ public void RoleMethodsFailWhenStoreNotImplementedTest()
+ {
+ var manager = new UserManager(new NoopUserStore());
+ Assert.False(manager.SupportsUserRole);
+ //Assert.Throws(() => manager.AddToRole("bogus", null).Wait());
+ //Assert.Throws(async () => await manager.GetRoles("bogus"));
+ //Assert.Throws(async () => await manager.RemoveFromRole("bogus", null));
+ //Assert.Throws(async () => await manager.IsInRole("bogus", "bogus"));
+ }
+
+ [Fact]
+ public void DisposeAfterDisposeWorksTest()
+ {
+ var manager = new UserManager(new NoopUserStore());
+ manager.Dispose();
+ manager.Dispose();
+ }
+
+ [Fact]
+ public void ManagerPublicNullCheckTest()
+ {
+ Assert.Throws(() => new UserManager((IUserStore)null));
+ var manager = new UserManager(new NoopUserStore());
+ Assert.Throws(() => manager.ClaimsIdentityFactory = null);
+ Assert.Throws(() => manager.PasswordHasher = null);
+ //Assert.Throws(() => manager.CreateIdentity(null, "whatever"));
+ //Assert.Throws(() => manager.Create(null));
+ //Assert.Throws(() => manager.Create(null, null));
+ //Assert.Throws(() => manager.Create(new TestUser(), null));
+ //Assert.Throws(() => manager.Update(null));
+ //Assert.Throws(() => manager.Delete(null));
+ //Assert.Throws(() => manager.AddClaim("bogus", null));
+ //Assert.Throws(() => manager.FindByName(null));
+ //Assert.Throws(() => manager.Find(null, null));
+ //Assert.Throws(() => manager.AddLogin("bogus", null));
+ //Assert.Throws(() => manager.RemoveLogin("bogus", null));
+ //Assert.Throws(() => manager.FindByEmail(null));
+ Assert.Throws(() => manager.RegisterTwoFactorProvider(null, null));
+ Assert.Throws(() => manager.RegisterTwoFactorProvider("bogus", null));
+ }
+
+ //[Fact]
+ //public void MethodsFailWithUnknownUserTest()
+ //{
+ // var db = UnitTestHelper.CreateDefaultDb();
+ // var manager = new UserManager(new UserStore(db));
+ // manager.UserTokenProvider = new NoOpTokenProvider();
+ // var error = "UserId not found.";
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.AddClaimAsync(null, new Claim("a", "b"))), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.AddLoginAsync(null, new UserLoginInfo("", ""))), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.AddPasswordAsync(null, null)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.AddToRoleAsync(null, null)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.ChangePasswordAsync(null, null, null)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.GetClaimsAsync(null)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.GetLoginsAsync(null)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.GetRolesAsync(null)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.IsInRoleAsync(null, null)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.RemoveClaimAsync(null, new Claim("a", "b"))), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.RemoveLoginAsync(null, new UserLoginInfo("", ""))), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.RemovePasswordAsync(null)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.RemoveFromRoleAsync(null, null)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.UpdateSecurityStampAsync(null)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.GetSecurityStampAsync(null)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.HasPasswordAsync(null)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.GeneratePasswordResetTokenAsync(null)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.ResetPasswordAsync(null, null, null)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.IsEmailConfirmedAsync(null)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.GenerateEmailConfirmationTokenAsync(null)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.ConfirmEmailAsync(null, null)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.GetEmailAsync(null)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.SetEmailAsync(null, null)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.IsPhoneNumberConfirmedAsync(null)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.ChangePhoneNumberAsync(null, null, null)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.VerifyChangePhoneNumberTokenAsync(null, null, null)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.GetPhoneNumberAsync(null)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.SetPhoneNumberAsync(null, null)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.GetTwoFactorEnabledAsync(null)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.SetTwoFactorEnabledAsync(null, true)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.GenerateTwoFactorTokenAsync(null, null)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.VerifyTwoFactorTokenAsync(null, null, null)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.NotifyTwoFactorTokenAsync(null, null, null)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.GetValidTwoFactorProvidersAsync(null)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.VerifyUserTokenAsync(null, null, null)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.AccessFailedAsync(null)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.SetLockoutEnabledAsync(null, false)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.SetLockoutEndDateAsync(null, DateTimeOffset.UtcNow)), error);
+ // ExceptionHelper.ThrowsWithError(
+ // () => AsyncHelper.RunSync(() => manager.IsLockedOutAsync(null)), error);
+ //}
+
+ //[Fact]
+ //public void MethodsThrowWhenDisposedTest()
+ //{
+ // var manager = new UserManager(new NoopUserStore());
+ // manager.Dispose();
+ // Assert.Throws(() => manager.AddClaim("bogus", null));
+ // Assert.Throws(() => manager.AddLogin("bogus", null));
+ // Assert.Throws(() => manager.AddPassword("bogus", null));
+ // Assert.Throws(() => manager.AddToRole("bogus", null));
+ // Assert.Throws(() => manager.ChangePassword("bogus", null, null));
+ // Assert.Throws(() => manager.GetClaims("bogus"));
+ // Assert.Throws(() => manager.GetLogins("bogus"));
+ // Assert.Throws(() => manager.GetRoles("bogus"));
+ // Assert.Throws(() => manager.IsInRole("bogus", null));
+ // Assert.Throws(() => manager.RemoveClaim("bogus", null));
+ // Assert.Throws(() => manager.RemoveLogin("bogus", null));
+ // Assert.Throws(() => manager.RemovePassword("bogus"));
+ // Assert.Throws(() => manager.RemoveFromRole("bogus", null));
+ // Assert.Throws(() => manager.RemoveClaim("bogus", null));
+ // Assert.Throws(() => manager.Find("bogus", null));
+ // Assert.Throws(() => manager.Find(null));
+ // Assert.Throws(() => manager.FindById(null));
+ // Assert.Throws(() => manager.FindByName(null));
+ // Assert.Throws(() => manager.Create(null));
+ // Assert.Throws(() => manager.Create(null, null));
+ // Assert.Throws(() => manager.CreateIdentity(null, null));
+ // Assert.Throws(() => manager.Update(null));
+ // Assert.Throws(() => manager.Delete(null));
+ // Assert.Throws(() => manager.UpdateSecurityStamp(null));
+ // Assert.Throws(() => manager.GetSecurityStamp(null));
+ // Assert.Throws(() => manager.GeneratePasswordResetToken(null));
+ // Assert.Throws(() => manager.ResetPassword(null, null, null));
+ // Assert.Throws(() => manager.GenerateEmailConfirmationToken(null));
+ // Assert.Throws(() => manager.IsEmailConfirmed(null));
+ // Assert.Throws(() => manager.ConfirmEmail(null, null));
+ //}
+
+ private class TestUser : IUser
+ {
+ public string Id { get; private set; }
+ public string UserName { get; set; }
+ }
+
+ private class NoopUserStore : IUserStore
+ {
+ public Task Create(TestUser user)
+ {
+ return Task.FromResult(0);
+ }
+
+ public Task Update(TestUser user)
+ {
+ return Task.FromResult(0);
+ }
+
+ public Task FindById(string userId)
+ {
+ return Task.FromResult(null);
+ }
+
+ public Task FindByName(string userName)
+ {
+ return Task.FromResult(null);
+ }
+
+ public void Dispose()
+ {
+ }
+
+ public Task Delete(TestUser user)
+ {
+ return Task.FromResult(0);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/test/Microsoft.AspNet.Identity.Test/project.json b/test/Microsoft.AspNet.Identity.Test/project.json
index ff81ab618e..28b9a28c47 100644
--- a/test/Microsoft.AspNet.Identity.Test/project.json
+++ b/test/Microsoft.AspNet.Identity.Test/project.json
@@ -2,13 +2,41 @@
"version": "0.1-alpha-*",
"dependencies": {
"Microsoft.AspNet.Identity" : "0.1-alpha-*",
- "Microsoft.AspNet.DependencyInjection" : "0.1-alpha-*"
+ "Microsoft.AspNet.DependencyInjection" : "0.1-alpha-*",
+ "Xunit.KRunner": "0.1-alpha-*",
+ "xunit.abstractions": "3.0.0-alpha-*",
+ "xunit2": "0.1-alpha-*",
+ "xunit2.assert": "0.1-alpha-*"
},
"configurations": {
"net45": {
"dependencies": {
- "xunit": "1.9.2"
+ "Moq" : "4.2.1312.1622",
+ "System.Runtime": "",
+ "System.Collections": ""
+ }
+ },
+ "k10": {
+ "dependencies": {
+ "System.Collections": "4.0.0.0",
+ "System.Collections.Concurrent": "4.0.0.0",
+ "System.ComponentModel": "4.0.0.0",
+ "System.Console": "4.0.0.0",
+ "System.Diagnostics.Debug": "4.0.10.0",
+ "System.Globalization": "4.0.10.0",
+ "System.Linq": "4.0.0.0",
+ "System.Linq.Expressions": "4.0.0.0",
+ "System.Reflection": "4.0.10.0",
+ "System.Reflection.Extensions": "4.0.0.0",
+ "System.Resources.ResourceManager": "4.0.0.0",
+ "System.Runtime": "4.0.20.0",
+ "System.Runtime.Extensions": "4.0.10.0",
+ "System.Threading": "4.0.0.0",
+ "System.Threading.Tasks": "4.0.0.0"
}
}
+ },
+ "commands": {
+ "test": "Xunit.KRunner"
}
}
\ No newline at end of file