Beispiel #1
0
        public void AddPropertyToDerivedClass()
        {
            // Arrange
            _typeExtender = new TypeExtender("ClassA");
            _typeExtender.AddProperty("IsAdded", typeof(bool));
            _typeExtender.AddProperty("IsEnabled", typeof(bool), true);
            _typeExtender.AddProperty <double>("Length");
            _typeExtender.AddProperty <double>("Width", true);

            //Act
            var returnedClass     = _typeExtender.FetchType();
            var isAddedProperty   = returnedClass.GetProperty("IsAdded");
            var isEnabledProperty = returnedClass.GetProperty("IsEnabled");
            var lengthProperty    = returnedClass.GetProperty("Length");
            var widthProperty     = returnedClass.GetProperty("Width");

            //Assert
            Assert.AreEqual("IsAdded", isAddedProperty.Name);
            Assert.AreEqual(typeof(bool), isAddedProperty.PropertyType);

            Assert.AreEqual("IsEnabled", isEnabledProperty.Name);
            Assert.AreEqual(typeof(bool), isEnabledProperty.PropertyType);
            Assert.AreEqual(false, isEnabledProperty.CanWrite);

            Assert.AreEqual("Length", lengthProperty.Name);
            Assert.AreEqual(typeof(double), lengthProperty.PropertyType);

            Assert.AreEqual("Width", widthProperty.Name);
            Assert.AreEqual(typeof(double), widthProperty.PropertyType);
            Assert.AreEqual(false, widthProperty.CanWrite);
        }
Beispiel #2
0
        public void AddACollectionOfPropertiesWithSameType()
        {
            _typeExtender = new TypeExtender("ClassA");
            var properites1 = new string[] { "IsEnabled", "CanFollowUp", "IsAdded" };
            var properties2 = new string[] { "Length", "Width", "Height" };

            _typeExtender.AddProperty(properites1, typeof(bool));
            _typeExtender.AddProperty <double>(properties2);
            var returnedClass = _typeExtender.FetchType();

            var properties = returnedClass.GetProperties();
            var all        = properites1.Union(properties2);

            foreach (var prop in all)
            {
                Assert.Contains(prop, properties.Select(x => x.Name).ToList());
            }
        }
Beispiel #3
0
        public void AddPropertyWithAddributes()
        {
            var attributeType   = typeof(CustomAAttribute);
            var attributeParams = new object[] { "Jon Snow" };

            _typeExtender = new TypeExtender("ClassA");
            _typeExtender.AddProperty("IsAdded", typeof(bool), attributeType, attributeParams);

            var returnedClass = _typeExtender.FetchType();
            var property      = returnedClass.GetProperty("IsAdded");
            var attributes    = property.GetCustomAttributes(attributeType, false);
            var attribute     = attributes[0] as CustomAAttribute;

            Assert.AreEqual(1, attributes.Length);
            Assert.NotNull(attribute);
            Assert.AreEqual("Jon Snow", attribute.Name);
        }