public void Performance_test_get_properties_for_type_with_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>(); AttributeCache.GetAttributes(typeof(TypePoolFixture)); // Act for (int count = 0; count < _iterations; count++) { 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 a cached collection of filtered properties over {_iterations} iterations was {times.Sum() / times.Count}ms"); }
public void Get_attributes_from_generic_type() { // Act IEnumerable <Attribute> attributes = AttributeCache.GetAttributes <AttributeFixture, TypePoolFixture>(); // Assert Assert.IsTrue(attributes.Count() == 2); }
public void Get_attributes_of_T_from_type() { // Act IEnumerable <Attribute> attributes = AttributeCache.GetAttributes <AttributeFixture>(typeof(TypePoolFixture)); // Assert Assert.IsTrue(attributes.Count() == 2); Assert.AreEqual(typeof(AttributeFixture), attributes.FirstOrDefault().GetType()); }
public void Get_attributes_for_type() { // Arrange var type = typeof(TypePoolFixture); // Act IEnumerable <Attribute> attributes = AttributeCache.GetAttributes(type); // Assert Assert.IsTrue(attributes.Count() == 3); }
public void Get_attributes_from_generic_type_with_predicate() { // Act IEnumerable <Attribute> attributes = AttributeCache.GetAttributes <AttributeFixture, TypePoolFixture>( null, attribute => attribute.GetType() == typeof(AttributeFixture)); // Assert Assert.IsTrue(attributes.Count() == 2); Assert.AreEqual(typeof(AttributeFixture), attributes.FirstOrDefault().GetType()); }
public void Get_attributes_from_generic_type_from_property_info_lacking_attribute_returns_null() { // Arrange var fixture = new TypePoolFixture(); PropertyInfo property = typeof(TypePoolFixture).GetProperty(nameof(fixture.LongFixture)); // Act IEnumerable <Attribute> attributes = AttributeCache.GetAttributes <AttributeFixture, TypePoolFixture>(property); // Assert Assert.IsTrue(attributes.Count() == 0); }
public void Get_attribute_with_cache() { // Arrange var type = typeof(TypePoolFixture); var fixture = new TypePoolFixture(); var property = PropertyCache.GetProperty(type, p => p.Name == nameof(fixture.PropertyWithAttribute)); IEnumerable <Attribute> attributes = AttributeCache.GetAttributes(type, property); // Act // Assert Assert.IsTrue(attributes.Count() == 3); }
public void Get_generic_attribute_from_null_instance() { // Arrange var fixture = new TypePoolFixture(); // Act IEnumerable <Attribute> attributes = AttributeCache.GetAttributes <AttributeFixture, TypePoolFixture>(null, null, null); // Assert Assert.IsTrue(attributes.Count() == 2); Assert.AreEqual(typeof(AttributeFixture), attributes.FirstOrDefault().GetType()); }
public void Get_attributes_of_T_from_property_on_type() { // Arrange var fixture = new TypePoolFixture(); PropertyInfo property = typeof(TypePoolFixture).GetProperty(fixture.GetPropertyName(p => p.PropertyWithAttribute)); // Act IEnumerable <Attribute> attributes = AttributeCache.GetAttributes <AttributeFixture>(typeof(TypePoolFixture), property); // Assert Assert.IsTrue(attributes.Count() == 2); Assert.AreEqual(typeof(AttributeFixture), attributes.FirstOrDefault().GetType()); }
public void Get_generic_attributes_from_instance_property_with_predicate() { // Arrange var fixture = new TypePoolFixture(); var property = typeof(TypePoolFixture).GetProperty(fixture.GetPropertyName(p => p.PropertyWithAttribute)); // Act IEnumerable <Attribute> attributes = AttributeCache.GetAttributes <AttributeFixture, TypePoolFixture>( fixture, property, attribute => attribute is AttributeFixture); // Assert Assert.IsTrue(attributes.Count() == 2); Assert.AreEqual(typeof(AttributeFixture), attributes.FirstOrDefault().GetType()); }
public void Get_attributes_from_generic_type_from_property_info_and_predicate() { // Arrange var fixture = new TypePoolFixture(); PropertyInfo property = typeof(TypePoolFixture).GetProperty(nameof(fixture.PropertyWithAttribute)); // Act IEnumerable <Attribute> attributes = AttributeCache.GetAttributes <AttributeFixture, TypePoolFixture> (property, attribute => attribute.GetType() == typeof(AttributeFixture)); // Assert Assert.IsTrue(attributes.Count() == 2); Assert.AreEqual(typeof(AttributeFixture), attributes.FirstOrDefault().GetType()); }
public void Get_attributes_with_property_info_using_predicate() { // Arrange var type = typeof(TypePoolFixture); var fixture = new TypePoolFixture(); var property = PropertyCache.GetProperty(type, p => p.Name == nameof(fixture.PropertyWithAttribute)); // Act IEnumerable <Attribute> attributes = AttributeCache.GetAttributes( type, property, attribute => attribute.GetType() == typeof(AttributeFixture)); // Assert Assert.IsTrue(attributes.Count() == 2); }