public async Task IsInRoleAsync_NoDelegateRunSynchronously_ReturnTrue() { // Arrange var dataReader = roles.First((r => r.Name.Equals("Data Reader"))); var user = new UserAuthorisation(userName, new List<Role>() { dataReader }); // Act var result = await user.IsInRoleAsync("DATAREADER"); // Assert Assert.IsTrue(result); }
public async Task IsInRoleAsync_AddDelegateDuringInitialisation_ReturnTrue() { // Arrange var mockPredicate = new Mock<Func<UserAuthorisation, string, Task<bool>>>(); mockPredicate.SetReturnsDefault(Task.FromResult(true)); var user = new UserAuthorisation(userName) .AddAsyncIsInRoleDelegate(mockPredicate.Object); // Act var result = await user.IsInRoleAsync("DATAREADER"); // Assert Assert.IsTrue(result); mockPredicate.Verify(p => p(user, "DATAREADER"), Times.Once); }
public async Task IsInRoleAsync_NoDelegateRunSynchronously_ReturnFalse() { // Arrange var user = new UserAuthorisation(userName); // Act var result = await user.IsInRoleAsync("DATAREADER"); // Assert Assert.IsFalse(result); }