public void ShouldBeAbleToSetAllAttributes()
        {
            PerformanceCounterCallHandlerAttribute attribute =
                new PerformanceCounterCallHandlerAttribute("My Category", "My instance");

            attribute.IncrementAverageCallDuration =
                !PerformanceCounterCallHandlerDefaults.IncrementAverageCallDuration;
            attribute.IncrementCallsPerSecond =
                !PerformanceCounterCallHandlerDefaults.IncrementCallsPerSecond;
            attribute.IncrementExceptionsPerSecond =
                !PerformanceCounterCallHandlerDefaults.IncrementExceptionsPerSecond;
            attribute.IncrementNumberOfCalls =
                !PerformanceCounterCallHandlerDefaults.IncrementNumberOfCalls;
            attribute.IncrementTotalExceptions =
                !PerformanceCounterCallHandlerDefaults.IncrementTotalExceptions;
            attribute.UseTotalCounter =
                !PerformanceCounterCallHandlerDefaults.UseTotalCounter;

            PerformanceCounterCallHandler handler = GetHandlerFromAttribute(attribute);

            Assert.AreEqual(attribute.IncrementAverageCallDuration,
                            handler.IncrementAverageCallDuration);

            Assert.AreEqual(attribute.IncrementCallsPerSecond,
                            handler.IncrementCallsPerSecond);
            Assert.AreEqual(attribute.IncrementExceptionsPerSecond,
                            handler.IncrementExceptionsPerSecond);
            Assert.AreEqual(attribute.IncrementNumberOfCalls,
                            handler.IncrementNumberOfCalls);
            Assert.AreEqual(attribute.IncrementTotalExceptions,
                            handler.IncrementTotalExceptions);
            Assert.AreEqual(attribute.UseTotalCounter,
                            handler.UseTotalCounter);
        }
Пример #2
0
        private PolicySet GetPerfMonPolicies()
        {
            RuleDrivenPolicy policy = new RuleDrivenPolicy("Monitor all methods");

            policy.RuleSet.Add(new TypeMatchingRule(typeof(MonitorTarget)));
            callHandler = new PerformanceCounterCallHandler(TestCategoryName, TestInstanceName);
            policy.Handlers.Add(callHandler);
            return(new PolicySet(policy));
        }
Пример #3
0
        /// <summary>
        /// Builds an instance of the subtype of <typeparamref name="TObject"/> type the receiver knows how to build,  based on
        /// an a configuration object.
        /// </summary>
        /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param>
        /// <param name="objectConfiguration">The configuration object that describes the object to build.</param>
        /// <param name="configurationSource">The source for configuration objects.</param>
        /// <param name="reflectionCache">The cache to use retrieving reflection information.</param>
        /// <returns>A fully initialized instance of the <typeparamref name="TObject"/> subtype.</returns>
        public ICallHandler Assemble(IBuilderContext context, CallHandlerData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
        {
            PerformanceCounterCallHandlerData configuration = (PerformanceCounterCallHandlerData)objectConfiguration;

            PerformanceCounterCallHandler callHandler = new PerformanceCounterCallHandler(
                configuration.CategoryName, configuration.InstanceName, configuration.UseTotalCounter,
                configuration.IncrementNumberOfCalls, configuration.IncrementCallsPerSecond,
                configuration.IncrementAverageCallDuration, configuration.IncrementTotalExceptions,
                configuration.IncrementExceptionsPerSecond);

            return(callHandler);
        }
        private IUnityContainer GetConfiguredContainer()
        {
            callHandler = new PerformanceCounterCallHandler(TestCategoryName, TestInstanceName);

            IUnityContainer container = new UnityContainer();

            container.AddNewExtension <Interception>();
            container.Configure <Interception>()
            .AddPolicy("Monitor all methods")
            .AddMatchingRule(new TypeMatchingRule(typeof(MonitorTarget)))
            .AddCallHandler(callHandler).Interception
            .SetDefaultInterceptorFor <MonitorTarget>(new TransparentProxyInterceptor());

            return(container);
        }
        public void ShouldCreateDefaultHandlerFromAttribute()
        {
            PerformanceCounterCallHandlerAttribute attribute =
                new PerformanceCounterCallHandlerAttribute("My Category", "My instance");

            PerformanceCounterCallHandler handler = GetHandlerFromAttribute(attribute);

            Assert.AreEqual("My Category", handler.Category);
            Assert.AreEqual("My instance", handler.InstanceName);
            Assert.AreEqual(PerformanceCounterCallHandlerDefaults.IncrementAverageCallDuration,
                            handler.IncrementAverageCallDuration);
            Assert.AreEqual(PerformanceCounterCallHandlerDefaults.IncrementCallsPerSecond,
                            handler.IncrementCallsPerSecond);
            Assert.AreEqual(PerformanceCounterCallHandlerDefaults.IncrementExceptionsPerSecond,
                            handler.IncrementExceptionsPerSecond);
            Assert.AreEqual(PerformanceCounterCallHandlerDefaults.IncrementNumberOfCalls,
                            handler.IncrementNumberOfCalls);
            Assert.AreEqual(PerformanceCounterCallHandlerDefaults.IncrementTotalExceptions,
                            handler.IncrementTotalExceptions);
            Assert.AreEqual(PerformanceCounterCallHandlerDefaults.UseTotalCounter,
                            handler.UseTotalCounter);
        }
        private IUnityContainer GetConfiguredContainer()
        {
            callHandler = new PerformanceCounterCallHandler(TestCategoryName, TestInstanceName);

            IUnityContainer container = new UnityContainer();
            container.AddNewExtension<Interception>();
            container.Configure<Interception>()
                .AddPolicy("Monitor all methods")
                    .AddMatchingRule(new TypeMatchingRule(typeof(MonitorTarget)))
                    .AddCallHandler(callHandler).Interception
                .SetDefaultInterceptorFor<MonitorTarget>(new TransparentProxyInterceptor());

            return container;
        }