/// <summary> /// Delete a policy from the cluster /// </summary> /// <param name="source"></param> /// <param name="policyName">Policy name</param> /// <param name="vhost">vhost on which the policy resides</param> /// <param name="cancellationToken"></param> public static void DeletePolicy( [NotNull] this IManagementClient source, string policyName, Vhost vhost, CancellationToken cancellationToken = default ) { if (source == null) { throw new ArgumentNullException(nameof(source)); } source.DeletePolicyAsync(policyName, vhost, cancellationToken) .GetAwaiter() .GetResult(); }
public async Task Should_be_able_to_delete_policies() { const string policyName = "asamplepolicy"; await managementClient.CreatePolicyAsync(new Policy { Name = policyName, Pattern = "averyuncommonpattern", Vhost = vhostName, Definition = new PolicyDefinition { HaMode = HaMode.All, HaSyncMode = HaSyncMode.Automatic } }).ConfigureAwait(false); Assert.Equal(1, (await managementClient.GetPoliciesAsync().ConfigureAwait(false)).Count(p => p.Name == policyName && p.Vhost == vhostName)); await managementClient.DeletePolicyAsync(policyName, new Vhost { Name = vhostName }).ConfigureAwait(false); Assert.Equal(0, (await managementClient.GetPoliciesAsync().ConfigureAwait(false)).Count(p => p.Name == policyName && p.Vhost == vhostName)); }