public void Performance_test_get_properties_for_type_without_cache_using_predicate()
        {
            // Arrange
            // Pre-load all of the Types so we can test against a Pool containing existing objects.
            IEnumerable <Type> types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(assembly => assembly.GetTypes());

            types.AsParallel().ForAll(type => PropertyCache.GetPropertiesForType(type));
            const int _iterations = 1000;
            var       times       = new List <double>();


            // Act
            for (int count = 0; count < _iterations; count++)
            {
                TypeCache.ClearTypeFromPool <TypePoolFixture>();
                var timer = new Stopwatch();
                timer.Start();
                IEnumerable <PropertyInfo> results =
                    PropertyCache.GetPropertiesForType <TypePoolFixture>(info => Attribute.IsDefined(info, typeof(AttributeFixture)));
                timer.Stop();
                times.Add(timer.Elapsed.TotalMilliseconds);
            }

            Debug.WriteLine($"The average time to fetch an uncached collection of filtered properties over {_iterations} iterations was {times.Sum() / times.Count}ms");
        }
        public void Performance_test_get_properties_for_type_without_cache_from_large_cache_pool()
        {
            // Arrange
            // Pre-load all of the Types so we can test against a Pool containing existing objects.
            IEnumerable <Type> types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(assembly => assembly.GetTypes());

            types.AsParallel().ForAll(type => PropertyCache.GetPropertiesForType(type));
            const int _iterations = 1000;
            var       times       = new List <double>();

            // Act
            for (int count = 0; count < _iterations; count++)
            {
                // Remove PayItem so we can test it not existing in the Pool.
                TypeCache.ClearTypeFromPool <TypePoolFixture>();

                var timer = new Stopwatch();
                timer.Start();
                var results = PropertyCache.GetPropertiesForType <TypePoolFixture>();
                timer.Stop();
                times.Add(timer.Elapsed.TotalMilliseconds);
            }

            Debug.WriteLine($"The average time to fetch an uncached collection properties from a large pool over {_iterations} iterations was {times.Sum() / times.Count}ms");
        }
        public void Get_properties_for_type_without_cache()
        {
            // Act
            var properties = PropertyCache.GetPropertiesForType <TypePoolFixture>();

            // Assert
            Assert.IsTrue(properties.Count() == 11, "The number of properties expected back did not match the number of properties returned for the fixture.");
        }
        public void Get_properties_from_null_instance_throws_exception()
        {
            // Arrange
            var fixture = new TypePoolFixture();

            // Act
            IEnumerable <PropertyInfo> properties =
                PropertyCache.GetPropertiesForType <TypePoolFixture>(null, null);
        }
        public void Get_properties_from_instance()
        {
            // Arrange
            var fixture = new TypePoolFixture();

            // Act
            IEnumerable <PropertyInfo> properties = PropertyCache.GetPropertiesForType(fixture);

            // Assert
            Assert.IsNotNull(properties);
        }
        public void Remove_type_from_pool_with_existing_cache()
        {
            // Arrange
            PropertyCache.GetPropertiesForType(typeof(ComponentFixture));

            // Act
            TypeCache.ClearTypeFromPool <ComponentFixture>();

            // Assert
            Assert.IsFalse(TypeCache.HasTypeInCache <ComponentFixture>());
        }
        public void Get_properties_for_type_with_existing_cache()
        {
            //Arrange
            // Creates an initial cache for us
            var properties = PropertyCache.GetPropertiesForType <TypePoolFixture>();

            // Act
            properties = PropertyCache.GetPropertiesForType <TypePoolFixture>();

            // Assert
            Assert.IsTrue(properties.Count() == 11, "The number of properties expected back did not match the number of properties returned for the fixture.");
        }
        public void Get_properties_from_instance_with_predicate()
        {
            // Arrange
            var fixture = new TypePoolFixture();

            // Act
            IEnumerable <PropertyInfo> properties =
                PropertyCache.GetPropertiesForType(
                    fixture,
                    p => p.Name == fixture.GetPropertyName(pr => pr.IsEnabled));

            // Assert
            Assert.IsNotNull(properties);
        }
        public void Get_types_using_predicate()
        {
            // Arrange
            IEnumerable <Type> types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(assembly => assembly.GetTypes());

            types.AsParallel().ForAll(type => PropertyCache.GetPropertiesForType(type));

            // Act
            IEnumerable <Type> typeCollection = TypeCache.GetTypes(t => t.IsSubclassOf(typeof(ComponentFixture)));

            // Assert
            Assert.IsTrue(typeCollection.Any());
            Assert.IsTrue(typeCollection.All(t => t.IsSubclassOf(typeof(ComponentFixture))));
        }
        public void Get_properties_for_type_without_cache_using_predicate()
        {
            // Arrange
            var timer = new Stopwatch();

            timer.Start();

            // Act
            var properties =
                PropertyCache.GetPropertiesForType <TypePoolFixture>(
                    info => Attribute.IsDefined(info, typeof(AttributeFixture)));

            timer.Stop();

            Debug.WriteLine(timer.Elapsed.TotalMilliseconds);

            // Assert
            Assert.IsTrue(properties.Count() == 1);
        }