public EmployerAccountsApiClientTestsFixture() { CancellationToken = CancellationToken.None; MockSecureHttpClient = new Mock <ISecureHttpClient>(); MockApiMediator = new Mock <IReadStoreMediator>(); EmployerAccountsApiClient = new EmployerAccountsApiClient(MockSecureHttpClient.Object, MockApiMediator.Object); IsUserInRoleRequest = new IsUserInRoleRequest { AccountId = 112, UserRef = Guid.NewGuid(), Roles = new HashSet <UserRole> { UserRole.Owner, UserRole.Transactor } }; MockApiMediator .Setup(m => m.Send(It.IsAny <IsUserInRoleQuery>(), CancellationToken)) .ReturnsAsync(true); IsUserInAnyRoleRequest = new IsUserInAnyRoleRequest { AccountId = 112, UserRef = Guid.NewGuid() }; MockApiMediator .Setup(m => m.Send(It.IsAny <IsUserInAnyRoleQuery>(), CancellationToken)) .ReturnsAsync(true); }
private static async Task Test() { using (var container = IoC.Initialize()) { try { var apiClient = container.GetInstance <IEmployerAccountsApiClient>(); var userInRoleRequest = new IsUserInRoleRequest { AccountId = 2134, UserRef = Guid.Parse("45f8e859-337c-4a4f-a184-1e794ec91f4f"), Roles = new HashSet <UserRole> { UserRole.Owner } }; var inroleResponse = await apiClient.IsUserInRole(userInRoleRequest, CancellationToken.None); Console.WriteLine("IsUserInRole: " + inroleResponse); var anyRoleRequest = new IsUserInAnyRoleRequest { AccountId = 2134, UserRef = Guid.Parse("45f8e859-337c-4a4f-a184-1e794ec91f4f") }; var response = await apiClient.IsUserInAnyRole(anyRoleRequest, CancellationToken.None); Console.WriteLine("IsUserAnyRole: " + response); } catch (Exception exception) { Console.WriteLine(exception); throw; } } }
public async Task <bool> IsUserInAnyRole(IsUserInAnyRoleRequest roleRequest, CancellationToken cancellationToken) { var user = await GetUser(roleRequest.AccountId, roleRequest.UserRef, cancellationToken).ConfigureAwait(false);; return(user != null && user.Roles.Any()); }