Exemplo n.º 1
0
        public void ShouldInitializeToEmpty()
        {
            PolicySet policies = new PolicySet();

            Assert.IsFalse(policies.AppliesTo(this.GetType()));
            MethodInfo          thisMember = GetType().GetMethod("ShouldInitializeToEmpty");
            List <ICallHandler> handlers   = new List <ICallHandler>(policies.GetHandlersFor(thisMember));

            Assert.AreEqual(0, handlers.Count);
        }
Exemplo n.º 2
0
        public void ShouldNotMatchPolicyWhenNoRulesMatch()
        {
            PolicySet policies = GetMultiplePolicySet();

            Assert.IsFalse(policies.AppliesTo(typeof(NoMatchAnywhere)));

            MethodBase          noMatchMember   = typeof(NoMatchAnywhere).GetMethod("NoMatchHere");
            List <ICallHandler> noMatchHandlers =
                new List <ICallHandler>(policies.GetHandlersFor(noMatchMember));

            Assert.AreEqual(0, noMatchHandlers.Count);
        }
Exemplo n.º 3
0
        public void ShouldMatchPolicyByMethodName()
        {
            PolicySet policies = GetMultiplePolicySet();

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

            MethodInfo          noMatchMember   = typeof(MatchesByMemberName).GetMethod("NoMatch");
            MethodInfo          nameMatchMember = typeof(MatchesByMemberName).GetMethod("NameMatch");
            List <ICallHandler> noMatchHandlers =
                new List <ICallHandler>(policies.GetHandlersFor(noMatchMember));
            List <ICallHandler> nameMatchHandlers =
                new List <ICallHandler>(policies.GetHandlersFor(nameMatchMember));

            Assert.AreEqual(0, noMatchHandlers.Count);
            Assert.AreEqual(1, nameMatchHandlers.Count);
            Assert.IsTrue(typeof(Handler2) == nameMatchHandlers[0].GetType());
        }
Exemplo n.º 4
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.º 5
0
        public void ShouldBeAbleToAddOnePolicy()
        {
            PolicySet policies = new PolicySet();

            RuleDrivenPolicy p = new RuleDrivenPolicy("NameMatching");

            p.RuleSet.Add(new MemberNameMatchingRule("ShouldBeAbleToAddOnePolicy"));
            p.Handlers.Add(new Handler1());
            p.Handlers.Add(new Handler2());

            policies.Add(p);

            MethodBase          thisMember = GetType().GetMethod("ShouldBeAbleToAddOnePolicy");
            List <ICallHandler> handlers   =
                new List <ICallHandler>(policies.GetHandlersFor(thisMember));

            Assert.IsTrue(policies.AppliesTo(GetType()));
            Assert.AreEqual(2, handlers.Count);
            Assert.IsTrue(typeof(Handler1) == handlers[0].GetType());
            Assert.IsTrue(typeof(Handler2) == handlers[1].GetType());
        }