Exemplo n.º 1
0
        public void ClassContainingStructWorks()
        {
            ContainerForExampleStructWithoutClass c = new ContainerForExampleStructWithoutClass()
            {
                ExampleStructWithoutClass = new ExampleStructWithoutClass()
                {
                    MyInt = 3
                }
            };

            var c2 = c.CloneLazinatorTyped();

            c2.ExampleStructWithoutClass.MyInt.Should().Be(3);
        }
Exemplo n.º 2
0
        public void BuffersUpdateInTandem_Struct()
        {
            ContainerForExampleStructWithoutClass e = new ContainerForExampleStructWithoutClass()
            {
                ExampleStructWithoutClass = new ExampleStructWithoutClass()
                {
                    MyInt = 19
                }
            };

            e = e.CloneLazinatorTyped();
            ConfirmBuffersUpdateInTandem(e);
            e.MyInt = 29; // make it dirty but leave child struct clean
            ConfirmBuffersUpdateInTandem(e);
        }
Exemplo n.º 3
0
        public void CopyPropertyForStructWorks()
        {
            ContainerForExampleStructWithoutClass c = new ContainerForExampleStructWithoutClass()
            {
                ExampleStructWithoutClass = new ExampleStructWithoutClass()
                {
                    MyInt = 3
                }
            };

            var c2           = c.CloneLazinatorTyped();
            var copyOfStruct = c2.ExampleStructWithoutClass;

            copyOfStruct.MyInt.Should().Be(3);
            copyOfStruct.MyInt = 4;
            c2.IsDirty.Should().BeFalse(); // no effect of change on copy
            c2.ExampleStructWithoutClass.MyInt.Should().Be(3);

            // let's confirm that this has been created on the stack (which is the purpose of the property)
            bool IsBoxed <T>(T value)
            {
                return
                    ((typeof(T).IsInterface || typeof(T) == typeof(object)) &&
                     value != null &&
                     value.GetType().IsValueType);
            }

            bool IsReferenceType <T>(T input)
            {
                object surelyBoxed = input;

                return(object.ReferenceEquals(surelyBoxed, input));
            }

            IsBoxed(copyOfStruct).Should().BeFalse();
            IsReferenceType(copyOfStruct).Should().BeFalse();
        }
Exemplo n.º 4
0
        public void RemoveBufferWorks_ExampleStructContainingStructContainer()
        {
            ContainerForExampleStructWithoutClass e = new ContainerForExampleStructWithoutClass();
            var x = e.ExampleStructWithoutClass;

            x.MyInt++;
            e.ExampleStructWithoutClass = x;
            e.SerializeLazinator();
            e.ExampleStructWithoutClass.LazinatorMemoryStorage.IsEmpty.Should().BeFalse();
            x = e.ExampleStructWithoutClass;
            x.MyInt++;
            var y = x.MyInt;

            e.ExampleStructWithoutClass = x;
            e.ExampleStructWithoutClass.LazinatorMemoryStorage.IsEmpty.Should().BeFalse();
            e.RemoveBufferInHierarchy();
            e.LazinatorMemoryStorage.IsEmpty.Should().BeTrue();
            e.ExampleStructWithoutClass.LazinatorMemoryStorage.IsEmpty.Should().BeTrue();
            e.ExampleStructWithoutClass.MyInt.Should().Be(y);

            e.SerializeLazinator();
            e.ExampleStructWithoutClass.LazinatorMemoryStorage.IsEmpty.Should().BeFalse();
            e.ExampleStructWithoutClass.MyInt.Should().Be(y);
        }