Beispiel #1
0
        public void PropertyChangedInConstructorSerializes()
        {
            // Concrete3's constructor sets Example2 and Example3 to null. This means that their _Accessed fields will be true.
            // When we deserialize ContainerWithAbstract1, we also deserialize Concrete3. If we did not call FreeInMemoryObjects,
            // then when we access Example2, it would appear that no deserialization is necessary, and Example2 will stay at its null value.
            // Both of the following examples fail without FreeInMemoryObjects().

            var concrete = new Concrete3()
            {
                Example2 = GetTypicalExample(),
                Example3 = GetTypicalExample()
            };
            var concrete2 = concrete.CloneLazinatorTyped();

            concrete2.Example2.Should().NotBeNull();
            concrete2.Example3.Should().NotBeNull();

            ContainerWithAbstract1 c = new ContainerWithAbstract1()
            {
                AbstractProperty = new Concrete3()
                {
                    Example2 = GetTypicalExample(), Example3 = GetTypicalExample()
                }
            };
            var c2 = c.CloneLazinatorTyped();
            var c2_abstractProperty = (c2.AbstractProperty as Concrete3);

            c2_abstractProperty.Example2.Should().NotBeNull();
            c2_abstractProperty.Example3.Should().NotBeNull();
        }
Beispiel #2
0
        public void AbstractPropertySerializes()
        {
            ContainerWithAbstract1 c = new ContainerWithAbstract1()
            {
                AbstractProperty = new Concrete3()
                {
                    String1 = "1", String2 = "2", String3 = "3"
                }
            };
            var c2 = c.CloneLazinatorTyped();
            var c2_abstractProperty = (c2.AbstractProperty as Concrete3);

            c2_abstractProperty.String1.Should().Be("1");
            c2_abstractProperty.String2.Should().Be("2");
            c2_abstractProperty.String3.Should().Be("3");
        }