Exemplo n.º 1
0
        public void HandlerCanShortcutMethodExecution()
        {
            RemotingPolicyInjector factory = new RemotingPolicyInjector();

            factory.Policies.Add(GetShortcutPolicy());

            MockDal dal = factory.Create <MockDal>();

            Assert.AreEqual(42, dal.DoSomething("should return 42"));
            Assert.AreEqual(-1, dal.DoSomething("shortcut"));
        }
Exemplo n.º 2
0
        public void ShouldCallHandlersWhenCallingMethods()
        {
            RemotingPolicyInjector factory = GetFactoryWithPolicies();
            MockDal dal = factory.Create <MockDal>();

            Assert.AreEqual(0, countHandler.CallCount);
            dal.DoSomething("43");
            dal.DoSomething("63");
            dal.DoSomething("Hike!");
            Assert.AreEqual(3, countHandler.CallCount);
        }
Exemplo n.º 3
0
        public void ShouldInterceptMethodsIfTypeImplementsMatchingInterface()
        {
            PolicySet policies = new PolicySet(GetPolicyThatMatchesInterface());

            Assert.IsTrue(policies.AppliesTo(typeof(MockDal)));

            RemotingPolicyInjector factory =
                new RemotingPolicyInjector(new PolicySet(GetPolicyThatMatchesInterface()));

            MockDal mockDal = factory.Create <MockDal>();
            IDal    dal     = mockDal;

            dal.Deposit(123.45);
            dal.Withdraw(54.32);
            mockDal.DoSomething("foo");

            Assert.AreEqual(2, countHandler.CallCount);
        }
Exemplo n.º 4
0
        public void ShouldCreateAllPipelinesForTargetWhenCreatingViaInterface()
        {
            RuleDrivenPolicy policy = new RuleDrivenPolicy("MockDal Policy");

            policy.RuleSet.Add(new TypeMatchingRule(typeof(MockDal)));
            countHandler = new CallCountHandler();
            policy.Handlers.Add(countHandler);

            RemotingPolicyInjector factory = new RemotingPolicyInjector(new PolicySet(policy));
            IDal dal = factory.Create <MockDal, IDal>();

            IMonitor monitor = (IMonitor)dal;

            monitor.Log("one");
            monitor.Log("two");
            monitor.Log("tree");

            MockDal target = (MockDal)dal;

            target.DoSomething("something");

            Assert.AreEqual(4, countHandler.CallCount);
        }