コード例 #1
0
        public void ShouldHaveAttributesCauseMatchesOnMethods()
        {
            AttributeDrivenPolicy policy = new AttributeDrivenPolicy();

            Assert.IsTrue(policy.Matches(nothingSpecialMethod));
            Assert.IsFalse(policy.Matches(mustBeFastMethod));
        }
コード例 #2
0
        public void ShouldInheritHandlersFromBaseClass()
        {
            AttributeDrivenPolicy policy   = new AttributeDrivenPolicy();
            List <ICallHandler>   handlers = new List <ICallHandler>(policy.GetHandlersFor(aNewMethod));

            Assert.AreEqual(1, handlers.Count);
            Assert.AreSame(typeof(LogCallHandler), handlers[0].GetType());
        }
コード例 #3
0
        public void ShouldGetNoHandlersIfApplyNoPoliciesIsPresent()
        {
            AttributeDrivenPolicy policy   = new AttributeDrivenPolicy();
            List <ICallHandler>   handlers =
                new List <ICallHandler>(policy.GetHandlersFor(mustBeFastMethod, new UnityContainer()));

            Assert.AreEqual(0, handlers.Count);
        }
コード例 #4
0
        public void ShouldGetCorrectHandlersForMethods()
        {
            AttributeDrivenPolicy policy   = new AttributeDrivenPolicy();
            List <ICallHandler>   handlers =
                new List <ICallHandler>(policy.GetHandlersFor(nothingSpecialMethod, new UnityContainer()));

            Assert.AreEqual(1, handlers.Count);
            Assert.AreSame(typeof(CallHandler2), handlers[0].GetType());
        }
コード例 #5
0
        public void ShouldHaveAttributePolicyApplyToTypesWithAttributes()
        {
            AttributeDrivenPolicy policy = new AttributeDrivenPolicy();

            Assert.IsTrue(policy.AppliesTo(typeof(AttributeTestTarget)));
            Assert.IsTrue(policy.AppliesTo(typeof(SecondAttributeTestTarget)));
            Assert.IsTrue(policy.AppliesTo(typeof(DerivedAttributeTestTarget)));
            Assert.IsFalse(policy.AppliesTo(typeof(MockDal)));
        }
コード例 #6
0
        public void ShouldInheritHandlersFromInterface()
        {
            MethodInfo            getNewsMethod = typeof(NewsService).GetMethod("GetNews");
            AttributeDrivenPolicy policy        = new AttributeDrivenPolicy();
            List <ICallHandler>   handlers      = new List <ICallHandler>(policy.GetHandlersFor(getNewsMethod));

            Assert.AreEqual(1, handlers.Count);
            Assert.AreSame(typeof(CachingCallHandler), handlers[0].GetType());
        }
コード例 #7
0
        public void ShouldApplyHandlersToSetterIfAttributesAreOnSecondIndexedItemProperty()
        {
            AttributeDrivenPolicy policy   = new AttributeDrivenPolicy();
            List <ICallHandler>   handlers =
                new List <ICallHandler>(policy.GetHandlersFor(setItemStringMethod, new UnityContainer()));

            Assert.AreEqual(2, handlers.Count);
            Assert.AreSame(typeof(CallHandler2), handlers[0].GetType());
            Assert.AreSame(typeof(CallHandler3), handlers[1].GetType());
        }
コード例 #8
0
        public void ShouldApplyHandlersIfAttributesAreOnNewProperty()
        {
            AttributeDrivenPolicy policy   = new AttributeDrivenPolicy();
            List <ICallHandler>   handlers =
                new List <ICallHandler>(policy.GetHandlersFor(getNewNameMethod, new UnityContainer()));

            Assert.AreEqual(2, handlers.Count);
            Assert.AreSame(typeof(CallHandler2), handlers[0].GetType());
            Assert.AreSame(typeof(CallHandler1), handlers[1].GetType());
        }
コード例 #9
0
        public void ShouldHaveLoggingAndValidationForDoSomething()
        {
            AttributeDrivenPolicy policy = new AttributeDrivenPolicy();
            List <ICallHandler>   handlers
                = new List <ICallHandler>(policy.GetHandlersFor(doSomethingMethod, new UnityContainer()));

            Assert.AreEqual(2, handlers.Count);
            Assert.AreSame(typeof(CallHandler2), handlers[0].GetType());
            Assert.AreSame(typeof(CallHandler3), handlers[1].GetType());
        }
コード例 #10
0
        public void ShouldGetHandlersFromClassAndMethodAttributes()
        {
            AttributeDrivenPolicy policy   = new AttributeDrivenPolicy();
            List <ICallHandler>   handlers =
                new List <ICallHandler>(policy.GetHandlersFor(doSomethingMethod, new UnityContainer()));

            Assert.AreEqual(2, handlers.Count);
            Assert.AreSame(typeof(CallHandler2), handlers[0].GetType());
            Assert.AreSame(typeof(CallHandler3), handlers[1].GetType());
        }
コード例 #11
0
        public void ShouldApplyHandlersIfAttributesAreOnProperty()
        {
            AttributeDrivenPolicy policy   = new AttributeDrivenPolicy();
            List <ICallHandler>   handlers =
                new List <ICallHandler>(policy.GetHandlersFor(getNameMethod));

            Assert.AreEqual(2, handlers.Count);
            Assert.AreSame(typeof(LogCallHandler), handlers[0].GetType());
            Assert.AreSame(typeof(ValidationCallHandler), handlers[1].GetType());
        }
コード例 #12
0
        public void ShouldGetHandlersFromClassAndMethodAttributes()
        {
            AttributeDrivenPolicy policy   = new AttributeDrivenPolicy();
            List <ICallHandler>   handlers =
                new List <ICallHandler>(policy.GetHandlersFor(doSomethingMethod));

            Assert.AreEqual(2, handlers.Count);
            Assert.AreSame(typeof(LogCallHandler), handlers[0].GetType());
            Assert.AreSame(typeof(ValidationCallHandler), handlers[1].GetType());
        }
コード例 #13
0
        public void ShouldInheritHandlersFromInterface()
        {
            MethodImplementationInfo getNewsMethod = new MethodImplementationInfo(
                typeof(INewsService).GetMethod("GetNews"),
                typeof(NewsService).GetMethod("GetNews"));
            AttributeDrivenPolicy policy = new AttributeDrivenPolicy();
            List <ICallHandler>   handlers
                = new List <ICallHandler>(policy.GetHandlersFor(getNewsMethod, new UnityContainer()));

            Assert.AreEqual(1, handlers.Count);
            Assert.AreSame(typeof(CallHandler1), handlers[0].GetType());
        }