81 lines
4.0 KiB
C#
81 lines
4.0 KiB
C#
// Copyright (c) Microsoft Open Technologies, Inc.
|
|
// All Rights Reserved
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR
|
|
// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
|
|
// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF
|
|
// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR
|
|
// NON-INFRINGEMENT.
|
|
// See the Apache 2 License for the specific language governing
|
|
// permissions and limitations under the License.
|
|
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using Xunit;
|
|
|
|
namespace Microsoft.AspNet.Identity.Entity.Test
|
|
{
|
|
public class RoleStoreTest
|
|
{
|
|
[Fact]
|
|
public async Task RoleStoreMethodsThrowWhenDisposedTest()
|
|
{
|
|
var store = new RoleStore<EntityRole, string>(new IdentityContext());
|
|
store.Dispose();
|
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.FindByIdAsync(null));
|
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.FindByNameAsync(null));
|
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.GetRoleIdAsync(null));
|
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.GetRoleNameAsync(null));
|
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.SetRoleNameAsync(null, null));
|
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.CreateAsync(null));
|
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.UpdateAsync(null));
|
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.DeleteAsync(null));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task RoleStorePublicNullCheckTest()
|
|
{
|
|
Assert.Throws<ArgumentNullException>("context", () => new RoleStore<EntityRole, string>(null));
|
|
var store = new RoleStore<EntityRole, string>(new IdentityContext());
|
|
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await store.GetRoleIdAsync(null));
|
|
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await store.GetRoleNameAsync(null));
|
|
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await store.SetRoleNameAsync(null, null));
|
|
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await store.CreateAsync(null));
|
|
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await store.UpdateAsync(null));
|
|
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await store.DeleteAsync(null));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task CanUpdateRoleName()
|
|
{
|
|
var manager = TestIdentityFactory.CreateRoleManager();
|
|
var role = new EntityRole("UpdateRoleName");
|
|
IdentityResultAssert.IsSuccess(await manager.CreateAsync(role));
|
|
Assert.Null(await manager.FindByNameAsync("New"));
|
|
role.Name = "New";
|
|
IdentityResultAssert.IsSuccess(await manager.UpdateAsync(role));
|
|
Assert.NotNull(await manager.FindByNameAsync("New"));
|
|
Assert.Null(await manager.FindByNameAsync("UpdateAsync"));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task CanSetUserName()
|
|
{
|
|
var manager = TestIdentityFactory.CreateRoleManager();
|
|
var role = new EntityRole("UpdateRoleName");
|
|
IdentityResultAssert.IsSuccess(await manager.CreateAsync(role));
|
|
Assert.Null(await manager.FindByNameAsync("New"));
|
|
IdentityResultAssert.IsSuccess(await manager.SetRoleNameAsync(role, "New"));
|
|
Assert.NotNull(await manager.FindByNameAsync("New"));
|
|
Assert.Null(await manager.FindByNameAsync("UpdateAsync"));
|
|
}
|
|
|
|
}
|
|
}
|