AWSSDK.Tests.Framework.UtilityMethods.GetRoleIfExists C# (CSharp) Method

GetRoleIfExists() public static method

public static GetRoleIfExists ( IAmazonIdentityManagementService iamClient, string roleName ) : Role
iamClient IAmazonIdentityManagementService
roleName string
return Amazon.IdentityManagement.Model.Role
        public static Role GetRoleIfExists(IAmazonIdentityManagementService iamClient, string roleName)
        {
            AutoResetEvent ars = new AutoResetEvent(false);
            Exception responseException = new Exception();

            // Get role arn if it exists.
            Role iamRole = null;
            iamClient.GetRoleAsync(new GetRoleRequest()
            {
                RoleName = roleName
            }, (response) =>
            {
                responseException = response.Exception;
                if (responseException == null)
                {
                    iamRole = response.Response.Role;
                }
                ars.Set();
            }, new AsyncOptions { ExecuteCallbackOnMainThread = false });
            ars.WaitOne();

            if (responseException == null)
            {
                Assert.IsNotNull(iamRole);
            }
            else
            {
                Assert.IsInstanceOf(typeof(NoSuchEntityException), responseException);
            }
            return iamRole;
        }