public void SetValue_AssigningAnInterfaceToAStruct_ValueShouldBeSet()
        {
            var container = new ClassWithPolymorphicFields();

            PropertyContainer.SetValue(ref container, nameof(ClassWithPolymorphicFields.InterfaceValue), new ClassDerivedA());

            Assert.That(container.InterfaceValue.GetType(), Is.EqualTo(typeof(ClassDerivedA)));
        }
        public void PathVisitor_NullValuesOnPath_ReturnsInvalidPath()
        {
            var container = new ClassWithPolymorphicFields();

            Assert.That(PropertyContainer.IsPathValid(ref container, new PropertyPath("ObjectValue")), Is.True);
            Assert.That(PropertyContainer.IsPathValid(ref container, new PropertyPath("ObjectValue.ObjectValue")), Is.False);
            container.ObjectValue = new ClassWithPolymorphicFields();
            Assert.That(PropertyContainer.IsPathValid(ref container, new PropertyPath("ObjectValue.ObjectValue")), Is.True);
            Assert.That(PropertyContainer.IsPathValid(ref container, new PropertyPath("ObjectValue.ObjectValue.ObjectValue")), Is.False);
        }
예제 #3
0
        public void IsPathValid_WithInvalidPath_ReturnFalse(string path)
        {
            var container = new ClassWithPolymorphicFields
            {
                ObjectValue    = new StructWithPrimitives(),
                InterfaceValue = new ClassDerivedA1(),
                AbstractValue  = new ClassDerivedB()
            };

            Assert.That(PropertyContainer.IsPathValid(ref container, new PropertyPath(path)), Is.False);
        }
        public void GetValue_WithInterface_ValueShouldBeAssigned()
        {
            var container = new ClassWithPolymorphicFields {
                InterfaceValue = new ClassDerivedA {
                    DerivedAInt32Value = 3
                }
            };

            var value = PropertyContainer.GetValue <ClassWithPolymorphicFields, IContainerInterface>(ref container, nameof(ClassWithPolymorphicFields.InterfaceValue));

            Assert.That(value.GetType(), Is.EqualTo(typeof(ClassDerivedA)));
        }
        public void GetValue_WithConcreteImplementationOfInterface_ValueShouldBeAssigned()
        {
            var container = new ClassWithPolymorphicFields {
                InterfaceValue = new ClassDerivedA {
                    DerivedAInt32Value = 3
                }
            };

            var value = PropertyContainer.GetValue <ClassWithPolymorphicFields, ClassDerivedA>(ref container, nameof(ClassWithPolymorphicFields.InterfaceValue));

            Assert.That(value.DerivedAInt32Value, Is.EqualTo(3));
        }
예제 #6
0
        public void IsPathValid_WithDynamicPaths_RemainsValid()
        {
            var container = new ClassWithPolymorphicFields();

            Assert.That(PropertyContainer.IsPathValid(ref container, new PropertyPath("ObjectValue")), Is.True);
            Assert.That(PropertyContainer.IsPathValid(ref container, new PropertyPath("ObjectValue.BoolValue")), Is.False);
            container.ObjectValue = new StructWithPrimitives();
            Assert.That(PropertyContainer.IsPathValid(ref container, new PropertyPath("ObjectValue.BoolValue")), Is.True);
            container.ObjectValue = new ClassDerivedA1();
            Assert.That(PropertyContainer.IsPathValid(ref container, new PropertyPath("ObjectValue.BoolValue")), Is.False);
            Assert.That(PropertyContainer.IsPathValid(ref container, new PropertyPath("ObjectValue.AbstractInt32Value")), Is.True);
        }
예제 #7
0
        public void PropertyContainer_VisitAtPath_VisitsCorrectPath(string path, string expected)
        {
            var visitor   = new AssertNameAtPath();
            var container = new ClassWithPolymorphicFields
            {
                ObjectValue    = new ClassDerivedB(),
                AbstractValue  = new ClassDerivedA(),
                InterfaceValue = new ClassDerivedA1()
            };

            PropertyContainer.Visit(ref container, visitor, new PropertyPath(path));
            visitor.Matches(expected);
            visitor.Reset();
        }