public static bool DoesRoleHavePolicy(IAmazonIdentityManagementService iamClient, string policyName, string roleName)
{
AutoResetEvent ars = new AutoResetEvent(false);
Exception responseException = new Exception();
List<string> policyNames = null;
iamClient.ListRolePoliciesAsync(new ListRolePoliciesRequest()
{
RoleName = roleName,
}, (response) =>
{
responseException = response.Exception;
if (responseException == null)
{
policyNames = response.Response.PolicyNames;
}
ars.Set();
}, new AsyncOptions { ExecuteCallbackOnMainThread = false });
ars.WaitOne();
Assert.IsNull(responseException);
Assert.IsNotNull(policyNames);
return policyNames.Contains(policyName);
}