39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
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>(new NoopRoleStore());
|
|
var validator = new RoleValidator<TestRole>();
|
|
|
|
// Act
|
|
// Assert
|
|
await Assert.ThrowsAsync<ArgumentNullException>("manager", async () => await validator.ValidateAsync(null, null));
|
|
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await validator.ValidateAsync(manager, null));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(null)]
|
|
[InlineData("")]
|
|
public async Task ValidateFailsWithTooShortRoleName(string input)
|
|
{
|
|
// Setup
|
|
var manager = new RoleManager<TestRole>(new NoopRoleStore());
|
|
var validator = new RoleValidator<TestRole>();
|
|
var user = new TestRole {Name = input};
|
|
|
|
// Act
|
|
var result = await validator.ValidateAsync(manager, user);
|
|
|
|
// Assert
|
|
IdentityResultAssert.IsFailure(result, "Name cannot be null or empty.");
|
|
}
|
|
}
|
|
} |