Exemple #1
0
        public void TestCallHandlerCustomFactory()
        {
            PolicyInjectionSettings settings = new PolicyInjectionSettings();
            PolicyData policyData            = new PolicyData("policy");
            ExceptionCallHandlerData data    = new ExceptionCallHandlerData("exceptionhandler", "Swallow Exceptions");

            data.Order = 5;
            policyData.Handlers.Add(data);
            policyData.MatchingRules.Add(new CustomMatchingRuleData("matchesEverything", typeof(AlwaysMatchingRule)));
            settings.Policies.Add(policyData);

            ExceptionPolicyData swallowExceptions = new ExceptionPolicyData("Swallow Exceptions");

            swallowExceptions.ExceptionTypes.Add(new ExceptionTypeData("Exception", typeof(Exception), PostHandlingAction.None));

            DictionaryConfigurationSource dictConfigurationSource = new DictionaryConfigurationSource();

            IUnityContainer container = new UnityContainer().AddNewExtension <Interception>();

            settings.ConfigureContainer(container);
            container.RegisterInstance("Swallow Exceptions", swallowExceptions.BuildExceptionPolicy());


            RuleDrivenPolicy policy = container.Resolve <RuleDrivenPolicy>("policy");

            ICallHandler handler
                = (policy.GetHandlersFor(new MethodImplementationInfo(null, (MethodInfo)MethodBase.GetCurrentMethod()), container)).ElementAt(0);

            Assert.IsNotNull(handler);
            Assert.AreEqual(handler.Order, data.Order);
        }
Exemple #2
0
        public void CanCreateCustomAttributeMatchingRuleNodeFromData()
        {
            ExceptionCallHandlerData handlerData = new ExceptionCallHandlerData();

            handlerData.Name = "exceptionHandler";

            ExceptionCallHandlerNode handlerNode = new ExceptionCallHandlerNode(handlerData);

            Assert.AreEqual(handlerData.Name, handlerNode.Name);
        }
Exemple #3
0
        /// <summary>
        /// Converts the information stored in the node and generate
        /// the corresponding configuration element to store in
        /// an <see cref="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.IConfigurationSource" />.
        /// </summary>
        /// <returns>Newly created <see cref="ExceptionCallHandlerData"/> containing
        /// the configuration data from this node.</returns>
        public override CallHandlerData CreateCallHandlerData()
        {
            ExceptionCallHandlerData callHandlerData = new ExceptionCallHandlerData(Name);

            if (exceptionPolicyNode != null)
            {
                callHandlerData.ExceptionPolicyName = exceptionPolicyNode.Name;
            }
            return(callHandlerData);
        }
Exemple #4
0
        public void CanSerializeExceptionCallHandler()
        {
            ExceptionCallHandlerData handlerData =
                new ExceptionCallHandlerData("CallHandler", "Swallow Exceptions");

            ExceptionCallHandlerData deserializedHandler =
                SerializeAndDeserializeHandler(handlerData) as ExceptionCallHandlerData;

            Assert.IsNotNull(deserializedHandler);
            Assert.AreEqual(handlerData.Name, deserializedHandler.Name);
            Assert.AreEqual(handlerData.ExceptionPolicyName, deserializedHandler.ExceptionPolicyName);
        }
Exemple #5
0
        public void CanCreateRuleDataFromCustomAttributeMatchingRuleNode()
        {
            ExceptionCallHandlerNode handlerNode = new ExceptionCallHandlerNode();

            handlerNode.Name = "exceptionHandler";


            ExceptionCallHandlerData handlerData = handlerNode.CreateCallHandlerData() as ExceptionCallHandlerData;

            Assert.IsNotNull(handlerData);
            Assert.AreEqual(handlerData.Name, handlerNode.Name);
        }
Exemple #6
0
 /// <summary>
 /// Create a new <see cref="ExceptionCallHandlerNode"/> with the supplied settings.
 /// </summary>
 /// <param name="callHandlerData">Configuration settings for this call handler.</param>
 public ExceptionCallHandlerNode(ExceptionCallHandlerData callHandlerData)
     : base(callHandlerData)
 {
     exceptionPolicyName = callHandlerData.ExceptionPolicyName;
     exceptionPolicyNodeRemovedHandler = new EventHandler <ConfigurationNodeChangedEventArgs>(OnExceptionPolicyNodeRemoved);
 }