public void PropertyContainer_SetValue_Enums_As_String()
        {
            var container = new TestPrimitiveContainer();

            PropertyContainer.SetValue(ref container, nameof(TestPrimitiveContainer.FlagsEnum), FlagsEnum.Value2.ToString());

            Assert.AreEqual(FlagsEnum.Value2, container.FlagsEnum);
        }
        public void PropertyContainer_SetValue_Enums_As_String_ThrowsWhenStringNotParsed()
        {
            var container = new TestPrimitiveContainer();

            Assert.Throws <ArgumentException>(() => PropertyContainer.SetValue(ref container, nameof(TestPrimitiveContainer.FlagsEnum), "NotAValidValue"));

            Assert.AreEqual(FlagsEnum.None, container.FlagsEnum);
        }
        public void PropertyContainer_SetValue_Enums_As_Byte()
        {
            var container = new TestPrimitiveContainer();

            PropertyContainer.SetValue(ref container, nameof(TestPrimitiveContainer.SmallEnum), (byte)(SmallEnum.Value1 | SmallEnum.Value2));

            Assert.AreEqual(SmallEnum.Value1 | SmallEnum.Value2, container.SmallEnum);
        }
        public void PropertyVisitor_Visit_StructVisitorWithState()
        {
            var container = new TestPrimitiveContainer();
            var visitor   = new StructVisitorWithState();

            PropertyContainer.Visit(ref container, ref visitor);
            Assert.That(visitor.VisitCount, Is.EqualTo(14));
        }
        public void PropertyContainer_SetValue_InvalidName_Throws()
        {
            var container = new TestPrimitiveContainer();

            Assert.Throws <InvalidOperationException>(() =>
            {
                PropertyContainer.SetValue(ref container, "test", 10);
            });
        }
示例#6
0
        public void PropertyVisitor_Visit_BoxedStruct()
        {
            var container = new TestPrimitiveContainer();
            var boxed     = (object)container;

            PropertyContainer.Visit(ref boxed, new AssertConcreteTypeVisitor {
                ExpectedConcreteType = typeof(TestPrimitiveContainer)
            });
        }
        public void PropertyContainer_SetValue_Enums_As_Int()
        {
            var container = new TestPrimitiveContainer();

            PropertyContainer.SetValue(ref container, nameof(TestPrimitiveContainer.FlagsEnum), (int)(FlagsEnum.Value1 | FlagsEnum.Value4));
            PropertyContainer.SetValue(ref container, nameof(TestPrimitiveContainer.UnorderedIntEnum), (int)UnorderedIntEnum.Value4);

            Assert.AreEqual(FlagsEnum.Value1 | FlagsEnum.Value4, container.FlagsEnum);
            Assert.AreEqual(UnorderedIntEnum.Value4, container.UnorderedIntEnum);
        }
        public void PropertyContainer_SetValue_Primitives()
        {
            var container = new TestPrimitiveContainer();

            PropertyContainer.SetValue(ref container, nameof(TestPrimitiveContainer.Int32Value), 10);
            PropertyContainer.SetValue(ref container, nameof(TestPrimitiveContainer.Float32Value), 2.5f);

            Assert.AreEqual(10, container.Int32Value);
            Assert.AreEqual(2.5f, container.Float32Value);
        }
        public void PropertyContainer_SetValue_Conversion_Throws()
        {
            var container = new TestPrimitiveContainer();
            var value     = new NotSupportedType();

            Assert.Throws <InvalidOperationException>(() =>
            {
                PropertyContainer.SetValue(ref container, nameof(TestPrimitiveContainer.Int32Value), value);
            });
        }
        public void PropertyContainer_SetValue_Conversion_DoesNotThrow()
        {
            var container = new TestPrimitiveContainer();

            Assert.DoesNotThrow(() =>
            {
                PropertyContainer.SetValue(ref container, nameof(TestPrimitiveContainer.Int32Value), 10.5f);
            });

            Assert.AreEqual(10, container.Int32Value);
        }
        public void PropertyContainer_GetValue_Conversion_DoesNotThrow()
        {
            var container = new TestPrimitiveContainer
            {
                Float64Value = 12345.678
            };

            var value = PropertyContainer.GetValue <TestPrimitiveContainer, int>(ref container, nameof(TestPrimitiveContainer.Float64Value));

            Assert.AreEqual(12345, value);
        }
        public void PropertyContainer_GetValue_Primitives()
        {
            var container = new TestPrimitiveContainer
            {
                Int32Value   = 42,
                Float64Value = 12345.678
            };

            Assert.AreEqual(42, PropertyContainer.GetValue <TestPrimitiveContainer, int>(ref container, nameof(TestPrimitiveContainer.Int32Value)));
            Assert.AreEqual(12345.678, PropertyContainer.GetValue <TestPrimitiveContainer, double>(ref container, nameof(TestPrimitiveContainer.Float64Value)));
        }
        public void PropertyContainer_SetValue_ChangeTracker(int start, int end, bool expected)
        {
            var container = new TestPrimitiveContainer
            {
                Int32Value = start
            };

            var changeTracker = new ChangeTracker();

            PropertyContainer.SetValue(ref container, nameof(TestPrimitiveContainer.Int32Value), end, ref changeTracker);
            Assert.AreEqual(expected, changeTracker.IsChanged());
        }
        public void PropertyContainer_SetValue_Enums_As_NarrowingConversion()
        {
            var container = new TestPrimitiveContainer();

            PropertyContainer.SetValue(ref container, nameof(TestPrimitiveContainer.FlagsEnum), (ulong)(FlagsEnum.Value1 | FlagsEnum.Value4));
            PropertyContainer.SetValue(ref container, nameof(TestPrimitiveContainer.UnorderedIntEnum), (ulong)UnorderedIntEnum.Value4);

            PropertyContainer.SetValue(ref container, nameof(TestPrimitiveContainer.SmallEnum), (ulong)(SmallEnum.Value1 | SmallEnum.Value2));

            Assert.AreEqual(FlagsEnum.Value1 | FlagsEnum.Value4, container.FlagsEnum);
            Assert.AreEqual(UnorderedIntEnum.Value4, container.UnorderedIntEnum);
        }
示例#15
0
        public void PropertyContainer_Transfer_Primitive()
        {
            var src = new TestPrimitiveContainer
            {
                Int32Value = 10
            };

            var dst = new TestPrimitiveContainer
            {
                Int32Value = 20
            };

            PropertyContainer.Transfer(ref dst, ref src);

            Assert.AreEqual(10, dst.Int32Value);
        }
示例#16
0
        public void PropertyVisitor_Visit_Struct()
        {
            var container = new TestPrimitiveContainer();

            PropertyContainer.Visit(ref container, new DebugLogVisitor());
        }