public void AttributeBehavior()
        {
            AttributeBehaviorCollection collection = new AttributeBehaviorCollection()
                                                     .Add <Test1Attribute, Target1, Test1Behavior>()
                                                     .Add <Test2Attribute, Target1, Test2Behavior>();

            IEnumerable <Type> types1 = collection.GetBehaviors(typeof(Target1));

            Assert.AreEqual(2, types1.Count());

            IEnumerable <Type> types2 = collection.GetBehaviors(typeof(Target2));

            Assert.AreEqual(1, types2.Count());
        }
Esempio n. 2
0
        public static void Test()
        {
            IBehaviorProvider behaviorProvider = new AttributeBehaviorCollection()
                                                 .Add(typeof(LogAttribute), typeof(LogBehavior));

            ReflectionPipeline <ProductQueryHandler> pipeline     = new ReflectionPipeline <ProductQueryHandler>(behaviorProvider, new DefaultReflectionBehaviorFactory());
            IQueryHandler <ProductQuery, Product>    queryHandler = new BehaviorQueryHandler <ProductQueryHandler, ProductQuery, Product>(pipeline, new DefaultFactory <ProductQueryHandler>());

            Task <Product> task = queryHandler.HandleAsync(new ProductQuery()
            {
                Name = "Test"
            });

            if (!task.IsCompleted)
            {
                task.RunSynchronously();
            }

            Console.WriteLine(task.Result.Price);
        }