Example #1
0
        public void TestPartialCreation()
        {
            foreach (var serializer in Serializers.OfType <ICommonSerializerWithContainer>())
            {
                var container = serializer.GenerateContainer();
                Assert.True(container.CanWrite);

                serializer.Serialize(container, "howdy");
                serializer.Serialize(container, 42);
                serializer.Serialize(container, 101.7);
                var st = new SubTestData {
                    Name = "nm1"
                };
                serializer.Serialize(container, st);

                Assert.Equal(4, container.Count);
                Assert.True(container.CanWrite);

                var wrapper = new ContainerWrapper {
                    Container = container
                };

                ContainerWrapper wrapper2;
                using (var ms = new MemoryStream())
                {
                    serializer.Serialize(ms, wrapper);
                    ms.Position = 0;
                    wrapper2    = serializer.Deserialize <ContainerWrapper>(ms);
                }

                container = wrapper2.Container;
                Assert.True(container.CanRead);
                Assert.Equal("howdy", serializer.Deserialize <string>(container));
                Assert.Equal(42, serializer.Deserialize <int>(container));
                Assert.Equal(101.7, serializer.Deserialize <double>(container));
                Assert.Equal(st, serializer.Deserialize <SubTestData>(container));

                Assert.False(container.CanRead);
            }
        }
        public void TestPartialCreation()
        {
            foreach (var serializer in Serializers.OfType<ICommonSerializerWithContainer>())
            {
                var container = serializer.GenerateContainer();
                Assert.True(container.CanWrite);

                serializer.Serialize(container, "howdy");
                serializer.Serialize(container, 42);
                serializer.Serialize(container, 101.7);
                var st = new SubTestData { Name = "nm1" };
                serializer.Serialize(container, st);

                Assert.Equal(4, container.Count);
                Assert.True(container.CanWrite);

                var wrapper = new ContainerWrapper { Container = container };

                ContainerWrapper wrapper2;
                using(var ms = new MemoryStream())
                {
                    serializer.Serialize(ms, wrapper);
                    ms.Position = 0;
                    wrapper2 = serializer.Deserialize<ContainerWrapper>(ms);
                }

                container = wrapper2.Container;
                Assert.True(container.CanRead);
                Assert.Equal("howdy", serializer.Deserialize<string>(container));
                Assert.Equal(42, serializer.Deserialize<int>(container));
                Assert.Equal(101.7, serializer.Deserialize<double>(container));
                Assert.Equal(st, serializer.Deserialize<SubTestData>(container));

                Assert.False(container.CanRead);
            }
        }