Exemplo n.º 1
0
        public void StringNameInPersonIsSerializingInScope()
        {
            var config = new SerializerConfig();

            var input = new Person
            {
                Name = "WORKS"
            };

            using (var scope = config.CreateScope())
            {
                scope.Match <string>();

                var serializer = scope.Create();


                using (var stream = CreateStream())
                {
                    serializer.Serialize(stream, input);
                    stream.Seek(0);
                    var result = serializer.Deserialize <Person>(stream);

                    Assert.Equal("WORKS", result.Name);
                }
            }
        }
Exemplo n.º 2
0
        public void ScopeTestss()
        {
            Base b = new Derived
            {
                Id  = 10,
                Age = 12
            };


            using (var config = new SerializerConfig())
            {
                using (var stream = CreateStream())
                {
                    using (var serializer = config.Create())
                    {
                        serializer.Serialize(stream, b);
                        stream.Seek(0);
                        var result = serializer.Deserialize <Base>(stream);

                        Assert.IsType <Base>(result);

                        Assert.Equal(10, result.Id);
                    }
                }

                using (var scope = config.CreateScope())
                {
                    scope.Match <Derived>();

                    using (var stream = CreateStream())
                    {
                        using (var serializer = scope.Create())
                        {
                            serializer.Serialize(stream, b);
                            stream.Seek(0);
                            var result = serializer.Deserialize <Base>(stream);

                            Assert.IsType <Derived>(result);
                        }
                    }
                }

                using (var stream = CreateStream())
                {
                    using (var serializer = config.Create())
                    {
                        serializer.Serialize(stream, b);
                        stream.Seek(0);
                        var result = serializer.Deserialize <Base>(stream);

                        Assert.IsType <Base>(result);
                    }
                }
            }
        }