public void DataClassHasCorrectDefaults()
        {
            PerformanceCounterCallHandlerData data =
                new PerformanceCounterCallHandlerData("Counter data");

            Assert.AreEqual(
                PerformanceCounterCallHandlerDefaults.UseTotalCounter,
                data.UseTotalCounter);
            Assert.AreEqual(
                PerformanceCounterCallHandlerDefaults.IncrementAverageCallDuration,
                data.IncrementAverageCallDuration);
            Assert.AreEqual(
                PerformanceCounterCallHandlerDefaults.IncrementCallsPerSecond,
                data.IncrementCallsPerSecond);
            Assert.AreEqual(
                PerformanceCounterCallHandlerDefaults.IncrementExceptionsPerSecond,
                data.IncrementExceptionsPerSecond);
            Assert.AreEqual(
                PerformanceCounterCallHandlerDefaults.IncrementNumberOfCalls,
                data.IncrementNumberOfCalls);
            Assert.AreEqual(
                PerformanceCounterCallHandlerDefaults.IncrementTotalExceptions,
                data.IncrementTotalExceptions);

            Assert.AreEqual(0, data.Order);
        }
        public void CanDeserializeCallHandlerData()
        {
            PerformanceCounterCallHandlerData data = new PerformanceCounterCallHandlerData("counter data");
            data.CategoryName = "My Category";
            data.InstanceName = "Method - {namespace}.{type}.{method}";
            data.UseTotalCounter = false;
            data.Order = 10;

            PerformanceCounterCallHandlerData deserialized =
                (PerformanceCounterCallHandlerData)SerializeAndDeserializeHandler(data);

            Assert.AreEqual(data.Name, deserialized.Name);
            Assert.AreEqual(data.CategoryName, deserialized.CategoryName);
            Assert.AreEqual(data.InstanceName, deserialized.InstanceName);
            Assert.AreEqual(data.Order, deserialized.Order);
        }
        public void CanCreateCategoriesFromConfiguration()
        {
            PolicyInjectionSettings settings = new PolicyInjectionSettings();
            PolicyData policyData = new PolicyData("Perfmon policy");
            //policyData.MatchingRules.Add(new TagAttributeMatchingRuleData("Match By Tag", "Perfmon"));
            PerformanceCounterCallHandlerData counterData = new PerformanceCounterCallHandlerData("{type}.{method}");
            counterData.CategoryName = firstCategory;
            policyData.Handlers.Add(counterData);
            settings.Policies.Add(policyData);

            DictionaryConfigurationSource configSource = new DictionaryConfigurationSource();
            configSource.Add(PolicyInjectionSettings.SectionName, settings);

            PerformanceCountersInstaller installer = new PerformanceCountersInstaller(configSource);
            CommitInstall(installer);

            Assert.IsTrue(PerformanceCounterCategory.Exists(firstCategory));
            Assert.IsFalse(PerformanceCounterCategory.Exists(secondCategory));
        }
        public void AssembledProperlyPerfCounterHandler()
        {
            PolicyInjectionSettings settings = new PolicyInjectionSettings();

            PolicyData policyData = new PolicyData("policy");
            PerformanceCounterCallHandlerData data = new PerformanceCounterCallHandlerData("FooCallHandler", 2);
            policyData.MatchingRules.Add(new CustomMatchingRuleData("match everything", typeof(AlwaysMatchingRule)));
            policyData.Handlers.Add(data);
            settings.Policies.Add(policyData);

            DictionaryConfigurationSource dictConfigurationSource = new DictionaryConfigurationSource();
            dictConfigurationSource.Add(PolicyInjectionSettings.SectionName, settings);

            IUnityContainer container = new UnityContainer().AddNewExtension<Interception>();
            settings.ConfigureContainer(container, dictConfigurationSource);

            InjectionFriendlyRuleDrivenPolicy policy = container.Resolve<InjectionFriendlyRuleDrivenPolicy>("policy");

            ICallHandler handler
                = (policy.GetHandlersFor(GetMethodImpl(MethodBase.GetCurrentMethod()), container)).ElementAt(0);

            Assert.IsNotNull(handler);
            Assert.AreEqual(handler.Order, data.Order);
        }
        static PolicyInjectionSettings GetInjectionSettings()
        {
            PolicyInjectionSettings settings = new PolicyInjectionSettings();

            PolicyData policy = new PolicyData("Intercept DoSomething");
            policy.MatchingRules.Add(new MemberNameMatchingRuleData("Match DoSomething", "DoSomething"));
            PerformanceCounterCallHandlerData handlerData =
                new PerformanceCounterCallHandlerData("Perfcounters");
            handlerData.CategoryName = "Category";
            handlerData.InstanceName = "Instance";
            policy.Handlers.Add(handlerData);

            settings.Policies.Add(policy);
            return settings;
        }