public void ShouldGetNoHandlersIfApplyNoPoliciesIsPresent()
        {
            AttributeDrivenPolicy policy   = new AttributeDrivenPolicy();
            List <ICallHandler>   handlers =
                new List <ICallHandler>(policy.GetHandlersFor(mustBeFastMethod, new UnityContainer()));

            Assert.AreEqual(0, handlers.Count);
        }
Example #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());
        }
        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());
        }
Example #4
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());
        }
        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());
        }
        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());
        }
        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());
        }
        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());
        }
Example #9
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());
        }
Example #10
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());
        }
        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());
        }