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);
        }
        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);
        }
        public void CreatePerfCounterHandlerFromAttributes()
        {
            MethodInfo method = typeof(MonitorTarget).GetMethod("DoSomethingElse");

            object[] attributes = method.GetCustomAttributes(typeof(PerformanceCounterCallHandlerAttribute), false);

            Assert.AreEqual(1, attributes.Length);

            PerformanceCounterCallHandlerAttribute attr = attributes[0] as PerformanceCounterCallHandlerAttribute;
            ICallHandler handler = attr.CreateHandler(null);

            Assert.IsNotNull(handler);
            Assert.AreEqual(3, handler.Order);
        }
        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);
        }
        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);
        }