Exemplo n.º 1
0
 public TSelf Using(IMatchingRule matchingRule)
 {
     // The adapter forces the exclusion, but explicitly stating it here for clarity
     // and in case any thing external looks at the configuration setting
     ExcludingFields();
     return(AddMatchingRule(new ObsoleteMatchingRuleAdapter(matchingRule)));
 }
Exemplo n.º 2
0
        /// <summary>
        /// Create the <see cref="PolicySet"/> based on the configuration settings.
        /// </summary>
        /// <param name="context">Builder context.</param>
        /// <param name="name">Name of object to create.</param>
        /// <param name="configurationSource">Configuration source.</param>
        /// <param name="reflectionCache">reflection cache, unused in this method.</param>
        /// <returns>The constructed <see cref="PolicySet"/> object.</returns>
        public object CreateObject(IBuilderContext context, string name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
        {
            PolicyInjectionSettings injectionSettings = configurationSource.GetSection(PolicyInjectionSettings.SectionName) as PolicyInjectionSettings;

            if (injectionSettings == null)
            {
                return(new PolicySet());
            }

            PolicySet policySet = new PolicySet();

            foreach (PolicyData policyData in injectionSettings.Policies)
            {
                RuleDrivenPolicy policy = new RuleDrivenPolicy(policyData.Name);

                foreach (CallHandlerData handlerData in policyData.Handlers)
                {
                    ICallHandler callHandler = CallHandlerCustomFactory.Instance.Create(context, handlerData, configurationSource, reflectionCache);
                    policy.Handlers.Add(callHandler);
                }

                foreach (MatchingRuleData matchingRuleData in policyData.MatchingRules)
                {
                    IMatchingRule matchingRule = MatchingRuleCustomFactory.Instance.Create(context, matchingRuleData, configurationSource, reflectionCache);
                    policy.RuleSet.Add(matchingRule);
                }
                policySet.Add(policy);
            }
            return(policySet);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a new <see cref="RuleDrivenPolicy"/> object with a name, a set of matching rules
        /// and the names to use when resolving handlers.
        /// </summary>
        public RuleDrivenPolicy(string name, IMatchingRule[] matchingRules, string[] callHandlerNames)
            : base(name)
        {
            this.ruleSet = new MatchingRuleSet();
            this.ruleSet.AddRange(matchingRules);

            this.callHandlerNames = callHandlerNames;
        }
Exemplo n.º 4
0
 void AddValidationPolicy(IUnityContainer factory,
                          string ruleSet,
                          SpecificationSource specificationSource,
                          IMatchingRule matchingRule)
 {
     factory.Configure <Interception>().AddPolicy("Noop")
     .AddMatchingRule(matchingRule)
     .AddCallHandler(new ValidationCallHandler(ruleSet, specificationSource));
 }
Exemplo n.º 5
0
        public static RuleChaining Or(this RuleChaining rule, IMatchingRule innerCheck)
        {
            var checkOtherRule = Expression.Call(Expression.Constant(innerCheck), _methodInfo, source, target);

            return(new RuleChaining()
            {
                Expression = rule.Expression.Or(checkOtherRule)
            });
        }
Exemplo n.º 6
0
        public static RuleChaining Or(this IMatchingRule rule, RuleChaining innerCheck)
        {
            var checkRule = Expression.Call(Expression.Constant(rule), _methodInfo, source, target);

            return(new RuleChaining()
            {
                Expression = checkRule.Or(Expression.Invoke(innerCheck.Expression, source, target))
            });
        }
Exemplo n.º 7
0
        public static RuleChaining Or(this IMatchingRule rule, IMatchingRule otherRule)
        {
            var checkRule      = Expression.Call(Expression.Constant(rule), _methodInfo, source, target);
            var checkOtherRule = Expression.Call(Expression.Constant(otherRule), _methodInfo, source, target);

            return(new RuleChaining()
            {
                Expression = checkRule.Or(checkOtherRule)
            });
        }
Exemplo n.º 8
0
        public void AddInterceptor(string policy, IMatchingRule matchingRule, params Type[] classTypes)
        {
            Interception interception = uContainer.Configure <Interception>();

            foreach (Type classType in classTypes)
            {
                interception = interception.SetInterceptorFor(classType, new VirtualMethodInterceptor());
            }
            interception.AddPolicy(policy)
            .AddMatchingRule(matchingRule);
        }
Exemplo n.º 9
0
        public void SetUp()
        {
            _processor             = new RequestProcessor(_ruleThatReturnsFirstHandler, new RequestHandlerList());
            _requestHandlerFactory = new RequestHandlerFactory(_processor);
            _dataProducer          = MockRepository.GenerateStub <IDataProducer>();
            _httpResponseDelegate  = MockRepository.GenerateStub <IHttpResponseDelegate>();

            _ruleThatReturnsFirstHandler = MockRepository.GenerateStub <IMatchingRule>();
            _ruleThatReturnsFirstHandler.Stub(x => x.IsEndpointMatch(null, new HttpRequestHead())).IgnoreArguments().Return(true).Repeat.Once();

            _ruleThatReturnsNoHandlers = MockRepository.GenerateStub <IMatchingRule>();
            _ruleThatReturnsNoHandlers.Stub(x => x.IsEndpointMatch(null, new HttpRequestHead())).IgnoreArguments().Return(false);
        }
Exemplo n.º 10
0
 public RequestProcessor(IMatchingRule matchingRule, IRequestHandlerList requestHandlers)
 {
     _handlers = requestHandlers;
     _requestMatcher = new RequestMatcher(matchingRule);
 }
Exemplo n.º 11
0
 public RequestMatcher(IMatchingRule matchingRule)
 {
     _matchingRule = matchingRule;
 }
Exemplo n.º 12
0
 public RequestMatcher(IMatchingRule matchingRule)
 {
     _matchingRule = matchingRule;
 }
Exemplo n.º 13
0
 /// <summary>
 /// Creates a new empty policy with the given name.
 /// </summary>
 /// <param name="name">Name of the policy.</param>
 protected InjectionPolicy(string name)
 {
     this.name = name;
     doesNotHaveNoPoliciesAttributeRule = new ApplyNoPoliciesMatchingRule();
 }
 public CollectionMemberMatchingRuleDecorator(IMatchingRule matchingRule)
 {
     this.matchingRule = matchingRule;
 }
Exemplo n.º 15
0
        public void SetUp()
        {
            _processor = new RequestProcessor(_ruleThatReturnsFirstHandler, new RequestHandlerList());
            _requestHandlerFactory = new RequestHandlerFactory(_processor);
            _dataProducer = MockRepository.GenerateStub<IDataProducer>();
            _httpResponseDelegate = MockRepository.GenerateStub<IHttpResponseDelegate>();

            _ruleThatReturnsFirstHandler = MockRepository.GenerateStub<IMatchingRule>();
            _ruleThatReturnsFirstHandler.Stub(x => x.IsEndpointMatch(null, new HttpRequestHead())).IgnoreArguments().Return(true).Repeat.Once();

            _ruleThatReturnsNoHandlers = MockRepository.GenerateStub<IMatchingRule>();
            _ruleThatReturnsNoHandlers.Stub(x => x.IsEndpointMatch(null, new HttpRequestHead())).IgnoreArguments().Return(false);
        }
Exemplo n.º 16
0
 public ComparisonConfiguration <TSubject> AddRule(IMatchingRule matchingRule)
 {
     matchingRules.Add(matchingRule);
     return(this);
 }
        void AddValidationPolicy(IUnityContainer factory,
                                 string ruleSet,
                                 SpecificationSource specificationSource,
                                 IMatchingRule matchingRule)
        {

            factory.Configure<Interception>().AddPolicy("Noop")
                .AddMatchingRule(matchingRule)
                .AddCallHandler(new ValidationCallHandler(ruleSet, specificationSource));
        }
 public ObsoleteMatchingRuleAdapter(IMatchingRule obsoleteMatchingRule)
 {
     this.obsoleteMatchingRule = obsoleteMatchingRule;
 }
Exemplo n.º 19
0
 /// <summary>
 /// Adds a matching rule to the ones already added by default, and which is evaluated before all existing rules.
 /// </summary>
 public EquivalencyAssertionOptions <TSubject> Using(IMatchingRule matchingRule)
 {
     matchingRules.Insert(0, matchingRule);
     return(this);
 }
Exemplo n.º 20
0
 public RequestProcessor(IMatchingRule matchingRule, RequestHandlerList requestHandlers)
 {
     _matchingRule = matchingRule;
     _handlers = requestHandlers;
 }
Exemplo n.º 21
0
 /// <summary>
 /// Creates a new empty policy with the given name.
 /// </summary>
 /// <param name="name">Name of the policy.</param>
 protected InjectionPolicy(string name)
 {
     this.name = name;
     doesNotHaveNoPoliciesAttributeRule = new ApplyNoPoliciesMatchingRule();
 }
Exemplo n.º 22
0
 /// <summary>
 /// Creates a new <see cref="RuleDrivenPolicy"/> object with a set of matching rules
 /// and the names to use when resolving handlers.
 /// </summary>
 public RuleDrivenPolicy(IMatchingRule[] matchingRules, string[] callHandlerNames)
     : this("Unnamed policy", matchingRules, callHandlerNames)
 {
 }
Exemplo n.º 23
0
 public RequestProcessor(IMatchingRule matchingRule, IRequestHandlerList requestHandlers)
 {
     _handlers       = requestHandlers;
     _requestMatcher = new RequestMatcher(matchingRule);
 }
Exemplo n.º 24
0
 /// <summary>
 /// Makes <paramref name="instance"/> a matching rule in the current policy.
 /// </summary>
 /// <param name="instance">The new <see cref="IMatchingRule"/> for the policy.</param>
 /// <returns>
 /// The <see cref="PolicyDefinition"/> than allows further configuration of the policy.
 /// </returns>
 public PolicyDefinition AddMatchingRule(IMatchingRule instance)
 {
     return(AddElement(instance, UpdateRulesParameters));
 }
Exemplo n.º 25
0
 public ObsoleteMatchingRuleAdapter(IMatchingRule obsoleteMatchingRule)
 {
     this.obsoleteMatchingRule = obsoleteMatchingRule;
 }
Exemplo n.º 26
0
 public RequestProcessor(IMatchingRule matchingRule, ConcurrentDictionary <Guid, RequestHandlerList> requestHandlers)
 {
     _handlers       = requestHandlers;
     _requestMatcher = new RequestMatcher(matchingRule);
 }