Beispiel #1
0
        public void CounterCategoryFactory_GetInstance_CachedByName()
        {
            var expected = CounterCategoryFactory <FakeCounterCategory> .GetInstance("category1");

            var actual = CounterCategoryFactory <FakeCounterCategory> .GetInstance("category1");

            Assert.AreEqual(expected, actual);
        }
Beispiel #2
0
        public void CounterCategoryFactory_GetInstance_UniqueByName()
        {
            var notExpected = CounterCategoryFactory <FakeCounterCategory> .GetInstance("category1");

            var actual = CounterCategoryFactory <FakeCounterCategory> .GetInstance("category2");

            Assert.AreNotEqual(notExpected, actual);
        }
Beispiel #3
0
        public void CounterCategoryMonitor_ctor_EmptyCategoryWillThrow()
        {
            try
            {
                var actual = CounterCategoryFactory <FakeEmptyCounterCategory> .GetInstance("category1");

                Assert.Fail("CounterCategoryMonitor is accepting empty types, which is not supported.");
            }
            catch (TargetInvocationException ex)
            {
                Assert.IsTrue(ex.InnerException?.Message?.Contains("does not expose any `public readonly` counters") == true);
            }
        }
        public void CounterCategoryBase_ctor_UnsealedTypeWillThrow()
        {
            try
            {
                var actual = CounterCategoryFactory <FakeUnsealedCounterCategory> .GetInstance("category1");

                Assert.Fail("CounterCategoryBase is not preventing unsealed types, which is not supported.");
            }
            catch (TargetInvocationException ex)
            {
                Assert.IsNotNull(ex.InnerException as NotSupportedException);
                Assert.IsTrue(ex.InnerException.Message?.Contains("must be a sealed type") == true);
            }
        }
Beispiel #5
0
 /// <summary>
 /// Get a <typeparamref name="TCounterCategory"/> instance for the <paramref name="type"/>.
 /// <para>
 /// Internally uses <see cref="CounterCategoryBase{TCounterCategory}.GetInstance(Type)"/>.</para>
 /// </summary>
 /// <typeparam name="TCounterCategory">implements <see cref="CounterCategoryBase{TCategory}"/></typeparam>
 /// <param name="type"></param>
 /// <returns></returns>
 public static TCounterCategory GetCounterCategory <TCounterCategory>(
     this Type type)
     where TCounterCategory : CounterCategoryBase <TCounterCategory>
 {
     return(CounterCategoryFactory <TCounterCategory> .GetInstance(type));
 }