public void GetPoliciesTPolicy_with_predicate_should_return_multiple_policies_of_type_TPolicy_if_multiple_match_predicate() { Policy policyA = Policy.NoOp(); Policy policyB = Policy.Handle <Exception>().Retry(); Policy policyC = Policy.NoOp(); PolicyWrap wrap = policyA.Wrap(policyB.Wrap(policyC)); wrap.GetPolicies <NoOpPolicy>(_ => true).Should().BeEquivalentTo(new[] { policyA, policyC }, options => options .WithStrictOrdering() .Using <IsPolicy>(ctx => ctx.Subject.Should().BeSameAs(ctx.Expectation)) .WhenTypeIs <IsPolicy>()); }
public void Should_pass_all_nested_policies_from_PolicyWrap_in_same_order_they_were_added() { NoOpPolicy policy0 = Policy.NoOp(); NoOpPolicy policy1 = Policy.NoOp(); NoOpPolicy policy2 = Policy.NoOp(); PolicyWrap policyWrap = Policy.Wrap(policy0, policy1, policy2); List <IsPolicy> policies = policyWrap.GetPolicies().ToList(); policies.Count.Should().Be(3); policies[0].Should().Be(policy0); policies[1].Should().Be(policy1); policies[2].Should().Be(policy2); }
public void GetPoliciesTPolicy_should_return_policies_of_type_TPolicy_matching_predicate() { CircuitBreakerPolicy policyA = Policy.Handle <Exception>().CircuitBreaker(1, TimeSpan.Zero); Policy policyB = Policy.Handle <Exception>().Retry(); CircuitBreakerPolicy policyC = Policy.Handle <Exception>().CircuitBreaker(1, TimeSpan.Zero); policyA.Isolate(); PolicyWrap wrap = policyA.Wrap(policyB.Wrap(policyC)); wrap.GetPolicies <CircuitBreakerPolicy>(p => p.CircuitState == CircuitState.Closed).Should().BeEquivalentTo(new[] { policyC }, options => options .WithStrictOrdering() .Using <IsPolicy>(ctx => ctx.Subject.Should().BeSameAs(ctx.Expectation)) .WhenTypeIs <IsPolicy>()); }