Example #1
0
        public void CanGetCategoryHelpTextForNonExistingName()
        {
            PerformanceCountersDefinitionAttribute attribute = new PerformanceCountersDefinitionAttribute("category", "MissingCategoryHelp");
            string translatedHelp = PerformanceCounterInstallerBuilder.GetCategoryHelp(attribute, GetType().Assembly);

            Assert.AreEqual(string.Empty, translatedHelp);
        }
Example #2
0
        public void IntersectingCountersForDifferentCategoriesInDifferentTypesCreatesMultipleInstallers()
        {
            Installer parentInstaller = new Installer();
            PerformanceCounterInstallerBuilder builder
                = new PerformanceCounterInstallerBuilder(
                      new Type[]
            {
                typeof(MultipleCounterTypeForCategoryA),
                typeof(MultipleCounterTypeForCategoryB)
            });

            builder.Fill(parentInstaller);

            Assert.AreEqual(2, parentInstaller.Installers.Count);
            Assert.AreSame(typeof(PerformanceCounterInstaller), parentInstaller.Installers[0].GetType());
            Assert.AreSame(typeof(PerformanceCounterInstaller), parentInstaller.Installers[1].GetType());

            PerformanceCounterInstaller installer1 = (PerformanceCounterInstaller)parentInstaller.Installers[0];

            Assert.AreEqual(PerformanceCounterCategoryType.MultiInstance, installer1.CategoryType);
            Assert.AreEqual("CategoryName", installer1.CategoryName);
            Assert.AreEqual("This is the help", installer1.CategoryHelp);
            Assert.AreEqual(2, installer1.Counters.Count);
            Assert.IsFalse(ReferenceEquals(installer1.Counters[0], installer1.Counters[1]));
            Assert.IsFalse(installer1.Counters[0].Equals(installer1.Counters[1]));

            PerformanceCounterInstaller installer2 = (PerformanceCounterInstaller)parentInstaller.Installers[1];

            Assert.AreEqual(PerformanceCounterCategoryType.MultiInstance, installer2.CategoryType);
            Assert.AreEqual("CategoryNameB", installer2.CategoryName);
            Assert.AreEqual("This is the help", installer2.CategoryHelp);
            Assert.AreEqual(2, installer2.Counters.Count);
            Assert.IsFalse(ReferenceEquals(installer2.Counters[0], installer2.Counters[1]));
            Assert.IsFalse(installer2.Counters[0].Equals(installer2.Counters[1]));
        }
Example #3
0
        public void CanGetCategoryHelpTextFromArbitraryResource()
        {
            PerformanceCountersDefinitionAttribute attribute = new PerformanceCountersDefinitionAttribute("category", "CategoryHelpFromArbitraryResource");
            string translatedHelp = PerformanceCounterInstallerBuilder.GetCategoryHelp(attribute, GetType().Assembly);

            Assert.AreEqual(ExtraResources.CategoryHelpFromArbitraryResource, translatedHelp);
        }
Example #4
0
        public void CanGetCounterHelpTextFromArbitraryResource()
        {
            PerformanceCounterAttribute attribute = new PerformanceCounterAttribute("counter", "CategoryHelpFromArbitraryResource", PerformanceCounterType.NumberOfItems64);
            string translatedHelp = PerformanceCounterInstallerBuilder.GetCounterHelp(attribute.CounterHelp, GetType().Assembly);

            Assert.AreEqual(ExtraResources.CategoryHelpFromArbitraryResource, translatedHelp);
        }
Example #5
0
        public void NoExceptionThrownIfNoInstrumentedTypesInList()
        {
            PerformanceCounterInstaller        installer = new PerformanceCounterInstaller();
            PerformanceCounterInstallerBuilder builder   =
                new PerformanceCounterInstallerBuilder(new Type[] { typeof(NonInstrumentedClass) });

            builder.Fill(installer);
        }
        public void PerformanceCountersFromNonInstrumentedClassesAreNotAdded()
        {
            PerformanceCounterInstaller parentInstaller = new PerformanceCounterInstaller();
            PerformanceCounterInstallerBuilder builder
                = new PerformanceCounterInstallerBuilder(new Type[] { typeof(NonInstrumentedClass) });
            builder.Fill(parentInstaller);

            Assert.AreEqual(0, parentInstaller.Installers.Count);
        }
        public void TypeWithNoCountersReturnsEmptyInstallers()
        {
            Installer parentInstaller = new Installer();
            PerformanceCounterInstallerBuilder builder
                = new PerformanceCounterInstallerBuilder(new Type[] { typeof(NoCountersType) });
            builder.Fill(parentInstaller);

            Assert.AreEqual(0, parentInstaller.Installers.Count);
        }
Example #8
0
        public void TypeWithNoCountersReturnsEmptyInstallers()
        {
            Installer parentInstaller = new Installer();
            PerformanceCounterInstallerBuilder builder
                = new PerformanceCounterInstallerBuilder(new Type[] { typeof(NoCountersType) });

            builder.Fill(parentInstaller);

            Assert.AreEqual(0, parentInstaller.Installers.Count);
        }
Example #9
0
        public void PerformanceCountersFromNonInstrumentedClassesAreNotAdded()
        {
            PerformanceCounterInstaller        parentInstaller = new PerformanceCounterInstaller();
            PerformanceCounterInstallerBuilder builder
                = new PerformanceCounterInstallerBuilder(new Type[] { typeof(NonInstrumentedClass) });

            builder.Fill(parentInstaller);

            Assert.AreEqual(0, parentInstaller.Installers.Count);
        }
Example #10
0
        public void IntersectingDifferentCountersForSameCategoriesInDifferentTypesThrows()
        {
            Installer parentInstaller = new Installer();
            PerformanceCounterInstallerBuilder builder
                = new PerformanceCounterInstallerBuilder(
                      new Type[] {
                typeof(MultipleCounterTypeForCategoryA),
                typeof(AlternativeMultipleCounterTypeForCategoryAWithRepeatedDifferentCounterDefinition)
            });

            builder.Fill(parentInstaller);
        }
        public void SingleCounterIsAddedToInstaller()
        {
            Installer parentInstaller = new Installer();
            PerformanceCounterInstallerBuilder builder
                = new PerformanceCounterInstallerBuilder(new Type[] { typeof(SingleCounterType) });
            builder.Fill(parentInstaller);

            Assert.AreEqual(1, parentInstaller.Installers.Count);
            Assert.AreSame(typeof(PerformanceCounterInstaller), parentInstaller.Installers[0].GetType());

            PerformanceCounterInstaller installer = (PerformanceCounterInstaller)parentInstaller.Installers[0];

            CounterCreationData createdCounterData = installer.Counters[0];
            Assert.AreEqual("Bill", createdCounterData.CounterName);
            Assert.AreEqual("Help Bill", createdCounterData.CounterHelp);
            Assert.AreEqual(PerformanceCounterType.CounterMultiTimer, createdCounterData.CounterType);
        }
Example #12
0
        public void CounterCategoryInformationIsPopulatedIntoCreatedInstaller()
        {
            Installer parentInstaller = new Installer();
            PerformanceCounterInstallerBuilder builder
                = new PerformanceCounterInstallerBuilder(new Type[] { typeof(MultipleCounterTypeForCategoryA) });

            builder.Fill(parentInstaller);

            Assert.AreEqual(1, parentInstaller.Installers.Count);
            Assert.AreSame(typeof(PerformanceCounterInstaller), parentInstaller.Installers[0].GetType());

            PerformanceCounterInstaller installer = (PerformanceCounterInstaller)parentInstaller.Installers[0];

            Assert.AreEqual(PerformanceCounterCategoryType.MultiInstance, installer.CategoryType);
            Assert.AreEqual("CategoryName", installer.CategoryName);
            Assert.AreEqual("This is the help", installer.CategoryHelp);
        }
        public void MultipleCountersInSingleTypeAreAllAddedToInstaller()
        {
            Installer parentInstaller = new Installer();
            PerformanceCounterInstallerBuilder builder
                = new PerformanceCounterInstallerBuilder(new Type[] { typeof(MultipleCounterTypeForCategoryA) });
            builder.Fill(parentInstaller);

            Assert.AreEqual(1, parentInstaller.Installers.Count);
            Assert.AreSame(typeof(PerformanceCounterInstaller), parentInstaller.Installers[0].GetType());

            PerformanceCounterInstaller installer = (PerformanceCounterInstaller)parentInstaller.Installers[0];

            Assert.AreEqual(2, installer.Counters.Count);
            CounterCreationData firstCounter = installer.Counters[0];
            CounterCreationData secondCounter = installer.Counters[1];
            Assert.IsFalse(ReferenceEquals(firstCounter, secondCounter));
            Assert.IsFalse(firstCounter.Equals(secondCounter));
        }
Example #14
0
        public void DisjointCountersForSameCategoriesInDifferentTypesCreatesSingleInstaller()
        {
            Installer parentInstaller = new Installer();
            PerformanceCounterInstallerBuilder builder
                = new PerformanceCounterInstallerBuilder(new Type[] { typeof(MultipleCounterTypeForCategoryA), typeof(AlternativeMultipleCounterTypeForCategoryA) });

            builder.Fill(parentInstaller);

            Assert.AreEqual(1, parentInstaller.Installers.Count);
            Assert.AreSame(typeof(PerformanceCounterInstaller), parentInstaller.Installers[0].GetType());

            PerformanceCounterInstaller installer = (PerformanceCounterInstaller)parentInstaller.Installers[0];

            Assert.AreEqual(PerformanceCounterCategoryType.MultiInstance, installer.CategoryType);
            Assert.AreEqual("CategoryName", installer.CategoryName);
            Assert.AreEqual("This is the help", installer.CategoryHelp);

            Assert.AreEqual(4, installer.Counters.Count);
        }
Example #15
0
        public void SingleCounterIsAddedToInstaller()
        {
            Installer parentInstaller = new Installer();
            PerformanceCounterInstallerBuilder builder
                = new PerformanceCounterInstallerBuilder(new Type[] { typeof(SingleCounterType) });

            builder.Fill(parentInstaller);

            Assert.AreEqual(1, parentInstaller.Installers.Count);
            Assert.AreSame(typeof(PerformanceCounterInstaller), parentInstaller.Installers[0].GetType());

            PerformanceCounterInstaller installer = (PerformanceCounterInstaller)parentInstaller.Installers[0];

            CounterCreationData createdCounterData = installer.Counters[0];

            Assert.AreEqual("Bill", createdCounterData.CounterName);
            Assert.AreEqual("Help Bill", createdCounterData.CounterHelp);
            Assert.AreEqual(PerformanceCounterType.CounterMultiTimer, createdCounterData.CounterType);
        }
Example #16
0
        public void MultipleCountersInSingleTypeAreAllAddedToInstaller()
        {
            Installer parentInstaller = new Installer();
            PerformanceCounterInstallerBuilder builder
                = new PerformanceCounterInstallerBuilder(new Type[] { typeof(MultipleCounterTypeForCategoryA) });

            builder.Fill(parentInstaller);

            Assert.AreEqual(1, parentInstaller.Installers.Count);
            Assert.AreSame(typeof(PerformanceCounterInstaller), parentInstaller.Installers[0].GetType());

            PerformanceCounterInstaller installer = (PerformanceCounterInstaller)parentInstaller.Installers[0];

            Assert.AreEqual(2, installer.Counters.Count);
            CounterCreationData firstCounter  = installer.Counters[0];
            CounterCreationData secondCounter = installer.Counters[1];

            Assert.IsFalse(ReferenceEquals(firstCounter, secondCounter));
            Assert.IsFalse(firstCounter.Equals(secondCounter));
        }
Example #17
0
        public void CountersWithBaseCountersAreAddedToInstallerInCorrectOrder()
        {
            Installer parentInstaller = new Installer();
            PerformanceCounterInstallerBuilder builder = new PerformanceCounterInstallerBuilder(new Type[] { typeof(TypeWithComplexCounter) });

            builder.Fill(parentInstaller);

            PerformanceCounterInstaller installer = (PerformanceCounterInstaller)parentInstaller.Installers[0];

            Assert.AreEqual(2, installer.Counters.Count);

            CounterCreationData realCounter = installer.Counters[0];
            CounterCreationData baseCounter = installer.Counters[1];

            Assert.AreEqual("real name", realCounter.CounterName);
            Assert.AreEqual(PerformanceCounterType.RawFraction, realCounter.CounterType);

            Assert.AreEqual("base name", baseCounter.CounterName);
            Assert.AreEqual(PerformanceCounterType.RawBase, baseCounter.CounterType);
        }
Example #18
0
        public void IntersectingIdenticalCountersForSameCategoriesInDifferentTypesKeepsSingleCounter()
        {
            Installer parentInstaller = new Installer();
            PerformanceCounterInstallerBuilder builder
                = new PerformanceCounterInstallerBuilder(
                      new Type[] {
                typeof(MultipleCounterTypeForCategoryA),
                typeof(AlternativeMultipleCounterTypeForCategoryAWithRepeatedIdenticalCounterDefinition)
            });

            builder.Fill(parentInstaller);

            Assert.AreEqual(1, parentInstaller.Installers.Count);
            Assert.AreSame(typeof(PerformanceCounterInstaller), parentInstaller.Installers[0].GetType());

            PerformanceCounterInstaller installer = (PerformanceCounterInstaller)parentInstaller.Installers[0];

            Assert.AreEqual(PerformanceCounterCategoryType.MultiInstance, installer.CategoryType);
            Assert.AreEqual("CategoryName", installer.CategoryName);
            Assert.AreEqual("This is the help", installer.CategoryHelp);

            Assert.AreEqual(3, installer.Counters.Count);
        }
        public void DisjointCountersForSameCategoriesInDifferentTypesCreatesSingleInstaller()
        {
            Installer parentInstaller = new Installer();
            PerformanceCounterInstallerBuilder builder
                = new PerformanceCounterInstallerBuilder(new Type[] { typeof(MultipleCounterTypeForCategoryA), typeof(AlternativeMultipleCounterTypeForCategoryA) });
            builder.Fill(parentInstaller);

            Assert.AreEqual(1, parentInstaller.Installers.Count);
            Assert.AreSame(typeof(PerformanceCounterInstaller), parentInstaller.Installers[0].GetType());

            PerformanceCounterInstaller installer = (PerformanceCounterInstaller)parentInstaller.Installers[0];
            Assert.AreEqual(PerformanceCounterCategoryType.MultiInstance, installer.CategoryType);
            Assert.AreEqual("CategoryName", installer.CategoryName);
            Assert.AreEqual("This is the help", installer.CategoryHelp);

            Assert.AreEqual(4, installer.Counters.Count);
        }
Example #20
0
 public void GetCategoryHelpTextWithNullAttributeThrows()
 {
     string translatedHelp = PerformanceCounterInstallerBuilder.GetCategoryHelp(null, GetType().Assembly);
 }
        public void IntersectingIdenticalCountersForSameCategoriesInDifferentTypesKeepsSingleCounter()
        {
            Installer parentInstaller = new Installer();
            PerformanceCounterInstallerBuilder builder
                = new PerformanceCounterInstallerBuilder(
                    new Type[]
                        {
                            typeof(MultipleCounterTypeForCategoryA),
                            typeof(AlternativeMultipleCounterTypeForCategoryAWithRepeatedIdenticalCounterDefinition)
                        });
            builder.Fill(parentInstaller);

            Assert.AreEqual(1, parentInstaller.Installers.Count);
            Assert.AreSame(typeof(PerformanceCounterInstaller), parentInstaller.Installers[0].GetType());

            PerformanceCounterInstaller installer = (PerformanceCounterInstaller)parentInstaller.Installers[0];
            Assert.AreEqual(PerformanceCounterCategoryType.MultiInstance, installer.CategoryType);
            Assert.AreEqual("CategoryName", installer.CategoryName);
            Assert.AreEqual("This is the help", installer.CategoryHelp);

            Assert.AreEqual(3, installer.Counters.Count);
        }
 public void IntersectingDifferentCountersForSameCategoriesInDifferentTypesThrows()
 {
     Installer parentInstaller = new Installer();
     PerformanceCounterInstallerBuilder builder
         = new PerformanceCounterInstallerBuilder(
             new Type[]
                 {
                     typeof(MultipleCounterTypeForCategoryA),
                     typeof(AlternativeMultipleCounterTypeForCategoryAWithRepeatedDifferentCounterDefinition)
                 });
     builder.Fill(parentInstaller);
 }
        public void IntersectingCountersForDifferentCategoriesInDifferentTypesCreatesMultipleInstallers()
        {
            Installer parentInstaller = new Installer();
            PerformanceCounterInstallerBuilder builder
                = new PerformanceCounterInstallerBuilder(
                    new Type[]
                        {
                            typeof(MultipleCounterTypeForCategoryA),
                            typeof(MultipleCounterTypeForCategoryB)
                        });
            builder.Fill(parentInstaller);

            Assert.AreEqual(2, parentInstaller.Installers.Count);
            Assert.AreSame(typeof(PerformanceCounterInstaller), parentInstaller.Installers[0].GetType());
            Assert.AreSame(typeof(PerformanceCounterInstaller), parentInstaller.Installers[1].GetType());

            PerformanceCounterInstaller installer1 = (PerformanceCounterInstaller)parentInstaller.Installers[0];
            Assert.AreEqual(PerformanceCounterCategoryType.MultiInstance, installer1.CategoryType);
            Assert.AreEqual("CategoryName", installer1.CategoryName);
            Assert.AreEqual("This is the help", installer1.CategoryHelp);
            Assert.AreEqual(2, installer1.Counters.Count);
            Assert.IsFalse(ReferenceEquals(installer1.Counters[0], installer1.Counters[1]));
            Assert.IsFalse(installer1.Counters[0].Equals(installer1.Counters[1]));

            PerformanceCounterInstaller installer2 = (PerformanceCounterInstaller)parentInstaller.Installers[1];
            Assert.AreEqual(PerformanceCounterCategoryType.MultiInstance, installer2.CategoryType);
            Assert.AreEqual("CategoryNameB", installer2.CategoryName);
            Assert.AreEqual("This is the help", installer2.CategoryHelp);
            Assert.AreEqual(2, installer2.Counters.Count);
            Assert.IsFalse(ReferenceEquals(installer2.Counters[0], installer2.Counters[1]));
            Assert.IsFalse(installer2.Counters[0].Equals(installer2.Counters[1]));
        }
 public void NoExceptionThrownIfNoInstrumentedTypesInList()
 {
     PerformanceCounterInstaller installer = new PerformanceCounterInstaller();
     PerformanceCounterInstallerBuilder builder =
         new PerformanceCounterInstallerBuilder(new Type[] { typeof(NonInstrumentedClass) });
     builder.Fill(installer);
 }
        public void CountersWithBaseCountersAreAddedToInstallerInCorrectOrder()
        {
            Installer parentInstaller = new Installer();
            PerformanceCounterInstallerBuilder builder = new PerformanceCounterInstallerBuilder(new Type[] { typeof(TypeWithComplexCounter) });
            builder.Fill(parentInstaller);

            PerformanceCounterInstaller installer = (PerformanceCounterInstaller)parentInstaller.Installers[0];

            Assert.AreEqual(2, installer.Counters.Count);

            CounterCreationData realCounter = installer.Counters[0];
            CounterCreationData baseCounter = installer.Counters[1];

            Assert.AreEqual("real name", realCounter.CounterName);
            Assert.AreEqual(PerformanceCounterType.RawFraction, realCounter.CounterType);

            Assert.AreEqual("base name", baseCounter.CounterName);
            Assert.AreEqual(PerformanceCounterType.RawBase, baseCounter.CounterType);
        }
        public void CounterCategoryInformationIsPopulatedIntoCreatedInstaller()
        {
            Installer parentInstaller = new Installer();
            PerformanceCounterInstallerBuilder builder
                = new PerformanceCounterInstallerBuilder(new Type[] { typeof(MultipleCounterTypeForCategoryA) });
            builder.Fill(parentInstaller);

            Assert.AreEqual(1, parentInstaller.Installers.Count);
            Assert.AreSame(typeof(PerformanceCounterInstaller), parentInstaller.Installers[0].GetType());

            PerformanceCounterInstaller installer = (PerformanceCounterInstaller)parentInstaller.Installers[0];

            Assert.AreEqual(PerformanceCounterCategoryType.MultiInstance, installer.CategoryType);
            Assert.AreEqual("CategoryName", installer.CategoryName);
            Assert.AreEqual("This is the help", installer.CategoryHelp);
        }