public void ShouldSelect_ExpectedPolicy(Type requested, Type expected, Dictionary <Type, IExceptionPolicyGroup> policyGroups, string context) { this.outputHelper.WriteLine($"Requested policy for {requested.Name}"); this.outputHelper.WriteLine($"Expected matched policy: {expected.Name}"); this.outputHelper.WriteLine("Policies provided:"); foreach (var policyGroupsKey in policyGroups.Keys) { this.outputHelper.WriteLine($" {policyGroupsKey.Name}"); } var strategy = new DefaultPolicyMatchingStrategy(); var actual = strategy.MatchPolicy(policyGroups, requested, Context.Default); this.outputHelper.WriteLine($"Actual matched policy: {actual.Handles.Name}"); actual.Handles.Should().Be(expected); }
public void Should_FallbackToNextBaseType_IfNoExactPolicyIsAvailable_ForGivenContext() { var strategy = new DefaultPolicyMatchingStrategy(); var handlerDict = new Dictionary <Type, Type> { { typeof(FruitException), typeof(object) } }; var policyDict = new Dictionary <string, IExceptionPolicy> { { "bowl of fruits assembly", new ExceptionPolicy <FruitException, BerlinException>(handlerDict) } }; var policyGroupDict = new Dictionary <Type, IExceptionPolicyGroup> { { typeof(FruitException), new ExceptionPolicyGroup <FruitException>(policyDict) } }; var exceptionType = typeof(AppleException); var context = "bowl of fruits assembly"; var matchedPolicy = strategy.MatchPolicy(policyGroupDict, exceptionType, context); matchedPolicy.Handles.Should().Be(typeof(FruitException)); matchedPolicy.Returns.Should().Be(typeof(BerlinException)); }