Ejemplo n.º 1
0
        public void CanCreateClassFromProperties()
        {
            var activator = new Activator(typeof(SomeClassWithProperties), new[] { nameof(SomeClassWithProperties.Number), nameof(SomeClassWithProperties.Text) });

            var values = new TestValueLookup(new Dictionary <string, object>
            {
                { nameof(SomeClassWithProperties.Number), 123 },
                { nameof(SomeClassWithProperties.Text), "HELLO" },
            });

            var instance = (SomeClassWithProperties)activator.CreateInstance(values);

            Assert.That(instance.Number, Is.EqualTo(123));
            Assert.That(instance.Text, Is.EqualTo("HELLO"));
        }
Ejemplo n.º 2
0
        public void SkipsPropertyWhenNotIncluded_Constructor()
        {
            var activator = new Activator(typeof(SomeClassWithConstructor), new[] { nameof(SomeClassWithConstructor.Number) });

            var values = new TestValueLookup(new Dictionary <string, object>
            {
                { nameof(SomeClassWithConstructor.Number), 123 },
                { nameof(SomeClassWithConstructor.Text), "HELLO" },
            });

            var instance = (SomeClassWithConstructor)activator.CreateInstance(values);

            Assert.That(instance.Number, Is.EqualTo(123));
            Assert.That(instance.Text, Is.EqualTo(null));
        }