示例#1
0
        public void TestContextMatchTrueCondition()
        {
            Assert.IsNotNull(_runtime);

            string contextId = Guid.NewGuid().ToString();
            string eventId   = Guid.NewGuid().ToString();

            // Setup conditions
            IContext context = _runtime.CreateContext(contextId);

            context.BindCondition(_runtime.Conditions.Get(CID), true);
            Assert.AreEqual(context.MatchConditions.Count, 1);

            // Setup rule
            IRule rule = _runtime.Rules.Get(RID);

            Expect.Call(delegate { rule.Subscribe(null); }).IgnoreArguments()
            .Do((RuntimeSubscribe)
                // Register to throw exceptions for each published event
                delegate(IRuntimeEventPublisher pub) {
                pub.PreRequestHandlerExecute += delegate(object sender, RuntimeEventArgs args) {
                    throw new InvalidOperationException();
                };
                pub.PostRequestHandlerExecute += delegate(object sender, RuntimeEventArgs args) {
                    throw new AccessViolationException();
                };
            });

            // Set expectations for prerequest
            Expect.Call(_runtime.Conditions.Get(CID).Evaluate(null))
            .IgnoreArguments().Return(true);
            Expect.Call(delegate { _runtime.Actions.Get(AID).Execute(null); }).IgnoreArguments();
            // Set expectations for postrequest
            Expect.Call(_runtime.Conditions.Get(CID).Evaluate(null))
            .IgnoreArguments().Return(true);
            Expect.Call(delegate { _runtime.Actions.Get(AID).Execute(null); }).IgnoreArguments();
            _mocks.ReplayAll();


            // Verify
            context.BindRule(rule).FaultActions.Add(_runtime.Actions.Get(AID));
            Assert.AreEqual(context.ExecuteRules.Count, 1);

            // Verify event handlers
            RuntimeEventSource source = new RuntimeEventSource();

            _runtime.Subscribe(source);
            source.FirePreRequestHandlerExecute();
            source.FirePostRequestHandlerExecute();

            _mocks.VerifyAll();
        }
        public void TestContextMatchTrueCondition()
        {
            Assert.IsNotNull(_runtime);

            string contextId = Guid.NewGuid().ToString();
            string eventId = Guid.NewGuid().ToString();

            // Setup conditions
            IContext context = _runtime.CreateContext(contextId);
            context.BindCondition(_runtime.Conditions.Get(CID), true);
            Assert.AreEqual(context.MatchConditions.Count, 1);

            // Setup rule
            IRule rule = _runtime.Rules.Get(RID);
            Expect.Call(delegate { rule.Subscribe(null); }).IgnoreArguments()
                .Do((RuntimeSubscribe)
                // Register to throw exceptions for each published event
                delegate(IRuntimeEventPublisher pub) {
                    pub.PreRequestHandlerExecute += delegate(object sender, RuntimeEventArgs args) {
                        throw new InvalidOperationException();
                    };
                    pub.PostRequestHandlerExecute += delegate(object sender, RuntimeEventArgs args) {
                        throw new AccessViolationException();
                    };
                });
                   
            // Set expectations for prerequest
            Expect.Call( _runtime.Conditions.Get(CID).Evaluate(null))
                .IgnoreArguments().Return(true);
            Expect.Call(delegate { _runtime.Actions.Get(AID).Execute(null); }).IgnoreArguments();
            // Set expectations for postrequest
            Expect.Call(_runtime.Conditions.Get(CID).Evaluate(null))
                .IgnoreArguments().Return(true);
            Expect.Call(delegate { _runtime.Actions.Get(AID).Execute(null); }).IgnoreArguments();
            _mocks.ReplayAll();


            // Verify            
            context.BindRule(rule).FaultActions.Add(_runtime.Actions.Get(AID));
            Assert.AreEqual(context.ExecuteRules.Count, 1);
            
            // Verify event handlers
            RuntimeEventSource source = new RuntimeEventSource();
            _runtime.Subscribe(source);
            source.FirePreRequestHandlerExecute();
            source.FirePostRequestHandlerExecute();

            _mocks.VerifyAll();            
        }