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 Extension_throws_exception_when_used_with_invalid_expression()
        {
            var fixture = new TypePoolFixture();

            // Act
            string propertyName = fixture.GetPropertyName(p => p.IsEnabled && p.IsEnabled);

            // Assert
            Assert.AreEqual("CreationDate", propertyName);
        }
        public void Get_type_from_instance_returns_a_type()
        {
            // Arrange
            var fixture = new TypePoolFixture();

            // Act
            Type cachedType = TypeCache.GetType(fixture);

            // Assert
            Assert.AreEqual(typeof(TypePoolFixture), cachedType);
        }
        public void Has_type_in_cache_returns_false_when_type_is_never_cached()
        {
            // Arrange
            var fixture = new TypePoolFixture();

            // Act
            bool exists = TypeCache.HasTypeInCache(fixture);

            // Assert
            Assert.IsFalse(exists);
        }
        public void Get_properties_from_instance()
        {
            // Arrange
            var fixture = new TypePoolFixture();

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

            // Assert
            Assert.IsNotNull(properties);
        }
示例#6
0
        public void Get_generic_attribute_from_instance()
        {
            // Arrange
            var fixture = new TypePoolFixture();

            // Act
            AttributeFixture attribute =
                AttributeCache.GetAttribute <AttributeFixture, TypePoolFixture>();

            // Assert
            Assert.IsNotNull(attribute);
        }
示例#7
0
        public void Get_attribute_from_property_on_type_with_predicate()
        {
            // Arrange
            var fixture  = new TypePoolFixture();
            var property = typeof(TypePoolFixture).GetProperty(fixture.GetPropertyName(p => p.PropertyWithAttribute));

            // Act
            Attribute attribute =
                AttributeCache.GetAttribute(typeof(TypePoolFixture), property, a => a is AttributeFixture);

            // Assert
            Assert.IsNotNull(attribute);
        }
示例#8
0
        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 Clear_type_from_pool_clears_cache()
        {
            // Arrange
            var fixture = new TypePoolFixture();

            TypeCache.AddType(typeof(TypePoolFixture));

            // Act
            TypeCache.ClearTypeFromPool(fixture);

            // Assert
            Assert.IsFalse(TypeCache.HasTypeInCache <TypePoolFixture>());
        }
        public void Get_type_from_instance_returns_cached_type()
        {
            // Arrange
            var  fixture      = new TypePoolFixture();
            Type originalType = TypeCache.GetType(fixture);

            // Act
            Type cachedType = TypeCache.GetType(fixture);

            // Assert
            Assert.AreEqual(typeof(TypePoolFixture), cachedType);
            Assert.IsTrue(object.ReferenceEquals(originalType, cachedType), "The cached type was not returned.");
        }
示例#11
0
        public void Get_generic_single_attribute_from_instance_property()
        {
            // Arrange
            var fixture  = new TypePoolFixture();
            var property = typeof(TypePoolFixture).GetProperty(fixture.GetPropertyName(p => p.PropertyWithAttribute));

            // Act
            AttributeFixture attribute =
                AttributeCache.GetAttribute <AttributeFixture, TypePoolFixture>(property, fixture);

            // Assert
            Assert.IsNotNull(attribute);
        }
示例#12
0
        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 Has_type_in_cache_returns_true_when_type_is_cached()
        {
            // Arrange
            var fixture = new TypePoolFixture();

            TypeCache.AddType(typeof(TypePoolFixture));

            // Act
            bool exists = TypeCache.HasTypeInCache(fixture);

            // Assert
            Assert.IsTrue(exists);
        }
示例#14
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);
        }
示例#15
0
        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_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);
        }
示例#17
0
        public void Get_generic_attribute_from_null_property_and_null_instance_with_predicate()
        {
            // Arrange
            var fixture  = new TypePoolFixture();
            var property = typeof(TypePoolFixture).GetProperty(fixture.GetPropertyName(p => p.PropertyWithAttribute));

            // Act
            AttributeFixture attribute =
                AttributeCache.GetAttribute <AttributeFixture, TypePoolFixture>(
                    null, null, a => a.IsEnabled);

            // Assert
            Assert.IsNotNull(attribute);
        }
示例#18
0
        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());
        }
示例#19
0
        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());
        }
示例#20
0
        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);
        }