using System; using System.Linq; using System.Threading.Tasks; using Xunit; namespace Microsoft.AspNet.Identity.Test { public class RoleManagerTest { [Fact] public void ConstructorThrowsWithNullStore() { Assert.Throws("store", () => new RoleManager(null)); } [Fact] public void RolesQueryableFailWhenStoreNotImplemented() { var manager = new RoleManager(new NoopRoleStore()); Assert.False(manager.SupportsQueryableRoles); Assert.Throws(() => manager.Roles.Count()); } [Fact] public void DisposeAfterDisposeDoesNotThrow() { var manager = new RoleManager(new NoopRoleStore()); manager.Dispose(); manager.Dispose(); } [Fact] public async Task RoleManagerPublicNullChecks() { Assert.Throws("store", () => new RoleManager(null)); var manager = new RoleManager(new NotImplementedStore()); await Assert.ThrowsAsync("role", async () => await manager.Create(null)); await Assert.ThrowsAsync("role", async () => await manager.Update(null)); await Assert.ThrowsAsync("role", async () => await manager.Delete(null)); await Assert.ThrowsAsync("roleName", async () => await manager.FindByName(null)); await Assert.ThrowsAsync("roleName", async () => await manager.RoleExists(null)); } [Fact] public async Task RoleStoreMethodsThrowWhenDisposed() { var manager = new RoleManager(new NoopRoleStore()); manager.Dispose(); await Assert.ThrowsAsync(() => manager.FindById(null)); await Assert.ThrowsAsync(() => manager.FindByName(null)); await Assert.ThrowsAsync(() => manager.RoleExists(null)); await Assert.ThrowsAsync(() => manager.Create(null)); await Assert.ThrowsAsync(() => manager.Update(null)); await Assert.ThrowsAsync(() => manager.Delete(null)); } private class NotImplementedStore : IRoleStore { public Task Create(TestRole role) { throw new NotImplementedException(); } public Task Update(TestRole role) { throw new NotImplementedException(); } public Task Delete(TestRole role) { throw new NotImplementedException(); } public Task FindById(string roleId) { throw new NotImplementedException(); } public Task FindByName(string roleName) { throw new NotImplementedException(); } public void Dispose() { throw new NotImplementedException(); } } } }