Esempio n. 1
0
        public void PropertiesCache_GetPropertiesOf_ShouldCacheProperties()
        {
            var stopwatch1 = new Stopwatch();

            stopwatch1.Start();
            for (var i = 0; i < 1000000; i++)
            {
                typeof(TestClass2).GetProperties();
            }
            stopwatch1.Stop();

            var cache2     = new PropertiesCache();
            var stopwatch2 = new Stopwatch();

            stopwatch2.Start();
            for (var i = 0; i < 1000000; i++)
            {
                cache2.GetPropertiesOf <TestClass2>();
            }
            stopwatch2.Stop();

            Console.WriteLine(stopwatch1.Elapsed);
            Console.WriteLine(stopwatch2.Elapsed);
            Assert.IsTrue(stopwatch1.Elapsed > stopwatch2.Elapsed, $"Uncached: {stopwatch1.Elapsed} vs. cached: {stopwatch2.Elapsed}.");
        }
Esempio n. 2
0
        public void PropertiesCache_GetPropertiesOf_ShouldReturnCorrectNumberOfProperties()
        {
            var cache = new PropertiesCache();

            var properties = cache.GetPropertiesOf <TestClass1>();

            Assert.AreEqual(3, properties.Length);
        }
Esempio n. 3
0
        public void PropertiesCache_GetPropertiesOf_ShouldReturnCorrectProperties()
        {
            var cache = new PropertiesCache();

            var properties = cache.GetPropertiesOf <TestClass1>();

            Assert.IsTrue(properties.Any(p => p.Name == "Property1"));
            Assert.IsTrue(properties.Any(p => p.Name == "Property2"));
            Assert.IsTrue(properties.Any(p => p.Name == "Property3"));
        }
Esempio n. 4
0
        public void PropertiesCache_GetPropertiesOf_ResultShouldEqualTypeGetProperties()
        {
            var cache = new PropertiesCache();

            var cachedProperties = cache.GetPropertiesOf <TestClass1>();
            var typeProperties   = typeof(TestClass1).GetProperties();

            Assert.AreEqual(typeProperties.Length, cachedProperties.Length);
            foreach (var typeProperty in typeProperties)
            {
                Assert.IsTrue(cachedProperties.Contains(typeProperty));
            }
        }