Exemplo n.º 1
0
        public void HaveAConstructorThatTakesTypeNameAndBaseType()
        {
            var className = "ClassA";
            var baseType  = typeof(List <string>);

            _typeExtender = new TypeExtender(className, baseType);

            Assert.AreEqual(className, _typeExtender.TypeName);
            Assert.AreEqual(baseType, _typeExtender.BaseType);
        }
Exemplo n.º 2
0
        public void ReturnATypeWithThePassedName()
        {
            var className = "ClassA";

            _typeExtender = new TypeExtender(className);

            var returnedClass = _typeExtender.FetchType();
            var name          = returnedClass.Name;

            Assert.AreEqual(className, name);
        }
Exemplo n.º 3
0
        public void AddAttributesWithParamsToDerivedClass()
        {
            _typeExtender = new TypeExtender("ClassA");
            _typeExtender.AddAttribute <CustomAAttribute>(new object[] { "Jon Snow" });

            var returnedClass = _typeExtender.FetchType();
            var attributes    = returnedClass.GetCustomAttributes(typeof(CustomAAttribute), false);
            var attribute     = attributes.Single().GetType();

            Assert.AreEqual(typeof(CustomAAttribute).Name, attribute.Name);
            Assert.AreEqual(typeof(CustomAAttribute).FullName, attribute.FullName);
        }
Exemplo n.º 4
0
        public void ReturnATypeWithThePassedNameAndBaseClass()
        {
            var className = "ClassA";
            var baseType  = typeof(List <string>);

            _typeExtender = new TypeExtender(className, baseType);

            var returnedClass    = _typeExtender.FetchType();
            var name             = returnedClass.Name;
            var basetypeReturned = returnedClass.BaseType;

            Assert.AreEqual(className, name);
            Assert.AreEqual(baseType, basetypeReturned);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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());
            }
        }