コード例 #1
0
        void VerifyLists()
        {
            var serializer = new ConfigurationContainer().EnableXmlText()
                             .Create()
                             .ForTesting();

            var instance = new ClassWithMixedContent {
                Value = new List <object> {
                    123, 345
                }
            };

            serializer.Cycle(instance)
            .ShouldBeEquivalentTo(instance);

            var second = new ClassWithMixedContent {
                Value = new List <object> {
                    123, "hello world?", 345
                }
            };
            var content = serializer.Cycle(second);

            content.ShouldBeEquivalentTo(second);
            content.Value.Should()
            .HaveCount(3);
            content.Value.Should()
            .Contain("hello world?");
        }
コード例 #2
0
ファイル: Issue192Tests.cs プロジェクト: wtf3505/home
        void VerifyLists()
        {
            var serializer = new ConfigurationContainer().EnableXmlText()
                             .Create()
                             .ForTesting();

            var instance = new ClassWithMixedContent {
                Value = new List <object> {
                    123, 345
                }
            };

            serializer.Assert(instance,
                              @"<?xml version=""1.0"" encoding=""utf-8""?><Issue192Tests-ClassWithMixedContent xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.ReportedIssues;assembly=ExtendedXmlSerializer.Tests.ReportedIssues""><int xmlns=""https://extendedxmlserializer.github.io/system"">123</int><int xmlns=""https://extendedxmlserializer.github.io/system"">345</int></Issue192Tests-ClassWithMixedContent>");

            serializer.Cycle(instance)
            .Should().BeEquivalentTo(instance);

            var second = new ClassWithMixedContent {
                Value = new List <object> {
                    123, "hello world?", 345
                }
            };
            var content = serializer.Cycle(second);

            content.Should().BeEquivalentTo(second);
            content.Value.Should()
            .HaveCount(3);
            content.Value.Should()
            .Contain("hello world?");
        }
コード例 #3
0
        void Verify()
        {
            var serializer = new ConfigurationContainer().EnableXmlText()
                             .Create()
                             .ForTesting();

            var instance = new Subject {
                Item = 123
            };

            serializer.Cycle(instance)
            .ShouldBeEquivalentTo(instance);

            var second = new SubjectWithMembers {
                Item = 123, Message = "Message", Time = DateTimeOffset.Now
            };

            serializer.Cycle(second)
            .ShouldBeEquivalentTo(second);

            var group = new Group2 {
                Type = GroupType.Large
            };

            serializer.Cycle(group)
            .ShouldBeEquivalentTo(group);

            var group3 = new Group3 {
                CreationTime = DateTime.Now
            };

            serializer.Cycle(group3)
            .ShouldBeEquivalentTo(group3);
        }
コード例 #4
0
        public void Verify()
        {
            int _one = 1, two = 2, three = 3;

            complex1D = new double[_one];
            complex2D = new double[_one][];
            complex3D = new double[_one][][];

            for (int i = 0; i < _one; i++)
            {
                complex1D[i] = i;
                complex2D[i] = new double[two];
                complex3D[i] = new double[two][];

                for (int j = 0; j < two; j++)
                {
                    complex2D[i][j] = j;
                    complex3D[i][j] = new double[three];
                    for (int k = 0; k < three; k++)
                    {
                        complex3D[i][j][k] = k;
                    }
                }
            }

            var support = new ConfigurationContainer().ForTesting();

            support
            .Cycle(complex3D)
            .ShouldBeEquivalentTo(complex3D);

            support
            .Cycle(complex2D)
            .ShouldBeEquivalentTo(complex2D);
        }
コード例 #5
0
        public void Verify()
        {
            var instance   = new Subject("Hello World", 123);
            var serializer = new ConfigurationContainer().EnableParameterizedContent().Create().ForTesting();

            serializer.Cycle(instance).Should().BeEquivalentTo(instance);

            var element = new Base[] { instance };

            serializer.Cycle(element).Should().BeEquivalentTo(element.Cast <Subject>());
        }
コード例 #6
0
        public void VerifyBasic()
        {
            var instance = new BasicSubject {
                Name = "Hello World", Number = 123
            };
            var serializer = new ConfigurationContainer().Create().ForTesting();

            serializer.Cycle(instance).Should().BeEquivalentTo(instance);

            var element = new Basic[] { instance };

            serializer.Cycle(element).Should().BeEquivalentTo(element.Cast <Basic>());
        }
コード例 #7
0
        public void VerifyExclude()
        {
            var subject = new ConfigurationContainer().EnableParameterizedContent()
                          .Type <Model>()
                          .EmitWhen(x => x.Entity is not Ignored)
                          .Create()
                          .ForTesting();
            var instance = new[]
            {
                new Model("First", new Implementation1()),
                new Model("Ignored", new Ignored()),
                new Model("Second", new Implementation2())
            };

            var cycled = subject.Cycle(instance);

            // If you want to use dictionary in memory:
            var index = instance.ToDictionary(x => x.Key);

            cycled.Should().HaveCount(2);
            index["First"].Entity.Should().BeOfType <Implementation1>();
            index["First"].Data.Should().NotBeNullOrEmpty();
            index["Second"].Entity.Should().BeOfType <Implementation2>();
            index["Second"].Data.Should().NotBeNullOrEmpty();
        }
コード例 #8
0
ファイル: Issue346Tests_Custom.cs プロジェクト: wtf3505/home
        void VerifyWithAutoFormatting()
        {
            var serializer = new ConfigurationContainer().UseAutoFormatting()
                             .Type <RootClass>()
                             .Register()
                             .Serializer()
                             .Composer()
                             .ByCalling(x => new Serializer(x))
                             .Create()
                             .ForTesting();
            var instance = new RootClass
            {
                SomeAttributeProperty = "Hello World!", ManyToOneReference = new A {
                    Name = "A"
                },
                OneToManyReference = new B {
                    Name = "B"
                }
            };

            serializer.Assert(instance,
                              @"<?xml version=""1.0"" encoding=""utf-8""?><Issue346Tests_Custom-RootClass Name=""A"" SomeAttributeProperty=""Hello World!"" xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.ReportedIssues;assembly=ExtendedXmlSerializer.Tests.ReportedIssues""><ManyToOneReference Name=""A"" /><OneToManyReference Name=""B"" /></Issue346Tests_Custom-RootClass>");

            serializer.Cycle(instance)
            .Should()
            .BeEquivalentTo(instance);
        }
コード例 #9
0
ファイル: Issue264Tests.cs プロジェクト: wtf3505/home
        void VerifyDefaultWithTypeSpecificRegistration()
        {
            var @default   = new List <(DeserializationStages, object)>();
            var specific   = new List <(DeserializationStages, string)>();
            var serializer = new ConfigurationContainer().WithDefaultMonitor(new DeserializationMonitor(@default))
                             .Type <string>()
                             .WithMonitor(new SpecificDeserializationMonitor(specific))
                             .Create();

            @default.Should()
            .BeEmpty();
            specific.Should()
            .BeEmpty();
            var instance = new Subject {
                Message = "Hello World!"
            };
            var cycled = serializer.Cycle(instance);

            cycled.Should().BeEquivalentTo(instance);
            @default.Select(x => x.Item1)
            .Should()
            .Equal(DeserializationStages.OnDeserializing,
                   DeserializationStages.OnActivating, DeserializationStages.OnActivated,
                   DeserializationStages.OnDeserialized);
            @default.Select(x => x.Item2)
            .Should()
            .Equal(cycled.GetType(), cycled.GetType(), cycled, cycled);

            specific.Select(x => x.Item1)
            .Should()
            .Equal(DeserializationStages.OnDeserialized);
            specific.Select(x => x.Item2)
            .Should()
            .Equal(cycled.Message);
        }
コード例 #10
0
ファイル: Issue264Tests.cs プロジェクト: wtf3505/home
        void VerifyMonitorDeserialization()
        {
            var list       = new List <(DeserializationStages, object)>();
            var serializer = new ConfigurationContainer().WithDefaultMonitor(new DeserializationMonitor(list))
                             .Create();

            list.Should()
            .BeEmpty();
            var instance = new Subject {
                Message = "Hello World!"
            };
            var cycled = serializer.Cycle(instance);

            cycled.Should().BeEquivalentTo(instance);
            list.Select(x => x.Item1)
            .Should()
            .Equal(DeserializationStages.OnDeserializing,
                   DeserializationStages.OnActivating, DeserializationStages.OnActivated,
                   DeserializationStages.OnDeserializing, DeserializationStages.OnDeserialized,
                   DeserializationStages.OnDeserialized);
            var objects = list.Select(x => x.Item2)
                          .ToArray();

            objects.Should()
            .Equal(cycled.GetType(), cycled.GetType(), cycled, typeof(string), cycled.Message, cycled);
        }
コード例 #11
0
        public void Verify()
        {
            var subject  = new ConfigurationContainer().EnableReferences().Create().ForTesting();
            var instance = new Subject();

            subject.Cycle(instance).Should().BeEquivalentTo(instance);
        }
コード例 #12
0
ファイル: Issue349Tests.cs プロジェクト: wtf3505/home
        void Verify()
        {
            var serializer = new ConfigurationContainer().Type <RootClass>()
                             .Register()
                             .Serializer()
                             .Composer()
                             .Of <Composer>()
                             .Member(x => x.SomeAttributeProperty)
                             .Attribute()
                             .Create()
                             .ForTesting();
            var instance = new RootClass
            {
                SomeAttributeProperty = "Hello World!", ManyToOneReference = new A {
                    Name = "A"
                },
                OneToManyReference = new B {
                    Name = "B"
                }
            };

            serializer.Assert(instance,
                              @"<?xml version=""1.0"" encoding=""utf-8""?><Issue349Tests-RootClass Name=""A"" SomeAttributeProperty=""Hello World!"" xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.ReportedIssues;assembly=ExtendedXmlSerializer.Tests.ReportedIssues""><ManyToOneReference><Name>A</Name></ManyToOneReference><OneToManyReference><Name>B</Name></OneToManyReference></Issue349Tests-RootClass>");

            serializer.Cycle(instance)
            .Should()
            .BeEquivalentTo(instance);
        }
コード例 #13
0
        public void VerifyOptimized()
        {
            var test = new SerializableProject
            {
                Cases = new List <Case>
                {
                    new SimpleCase
                    {
                        Name       = "Simple",
                        Number     = 1,
                        ModesCount = 2,
                        Records    = new List <LoadRecord>
                        {
                            new LoadRecord
                            {
                                Description = "DO NOT WORK :("
                            }
                        }
                    },
                    new CaseCombination()
                    {
                        Number = 2,
                        Name   = "A",
                        label  = "C"
                    }
                }
            };
            var support = new ConfigurationContainer()
                          .UseOptimizedNamespaces()             //WITHOUT IT WORKS
                          .ForTesting();

            // ShouldBeEquivalentTo doesn't work
            support.Cycle(test)
            .Should().BeEquivalentTo(test, options => options.RespectingRuntimeTypes());
        }
コード例 #14
0
        void VerifyExtension()
        {
            var support = new ConfigurationContainer().EnableClassicListNaming()
                          .Create()
                          .ForTesting();
            var subject = new[]
            {
                new TravelFile
                {
                    Name = "Hello World!", Participants = new[]
                    {
                        new Participant {
                            ParticipantId = 679556, Name = "xxxx"
                        },
                        new Participant {
                            ParticipantId = 679557, Name = "xxx"
                        }
                    }.ToList()
                }
            };

            support.Cycle(subject)
            // ReSharper disable once CoVariantArrayConversion
            .Should().BeEquivalentTo(subject);
        }
コード例 #15
0
        public void Verify()
        {
            List <TestSerialization> instance = new List <TestSerialization>();

            for (int i = 0; i < 2000; i++)
            {
                var newElement = new TestSerialization();
                if (i % 2 == 0)
                {
                    newElement.MyString  = "**********";
                    newElement.MyDouble  = Double.MaxValue;
                    newElement.MyBool    = true;
                    newElement.MyInteger = i;
                }
                else
                {
                    newElement.MyString  = "----------";
                    newElement.MyDouble  = Double.MinValue;
                    newElement.MyBool    = false;
                    newElement.MyInteger = i;
                }
                instance.Add(newElement);
            }

            var serializer = new ConfigurationContainer().EnableImplicitTyping(typeof(List <TestSerialization>))
                             .Create();

            var cycle = serializer.Cycle(instance);

            cycle.Should().BeEquivalentTo(instance);
            cycle[0].Should().BeEquivalentTo(instance[0]);
            cycle.Last().Should().BeEquivalentTo(instance.Last());
        }
コード例 #16
0
        void VerifyUnderlying()
        {
            var instance   = LogMessageSeverityAlternate.Debug | LogMessageSeverityAlternate.Informational;
            var serializer = new ConfigurationContainer().ForTesting();

            serializer.Cycle(instance).Should().Be(instance);
        }
コード例 #17
0
        void VerifyList()
        {
            var instance = new Foo {
                Bar = new Bar()
            };

            instance.Bar.Foos.Add(instance);

            var serializer = new ConfigurationContainer().EnableReferences()
                             .Create();

            var list = new List <Foo> {
                instance
            };

            var cycled = serializer.Cycle(list)
                         .Only();

            cycled.Should()
            .BeSameAs(cycled.Bar.Foos.Only());

            cycled.Bar.Should()
            .BeSameAs(cycled.Bar.Foos.Only()
                      .Bar);
        }
コード例 #18
0
        public void Verify()
        {
            var b1 = new Book();
            var b2 = new Book();

            var allBooks = new[] { b1, b2, };

            var fs = new BookStore()
            {
                AllBooks = allBooks,
                Genres   = new[]
                {
                    new Genre
                    {
                        Books = allBooks,
                    },
                    new Genre
                    {
                        Books = allBooks,
                    },
                }
            };

            var serializer = new ConfigurationContainer().Type <Book[]>()
                             .EnableReferences()
                             .Create()
                             .ForTesting();

            var cycled = serializer.Cycle(fs);

            cycled.AllBooks.Should().BeSameAs(cycled.Genres.ElementAt(0).Books);
            cycled.AllBooks.Should().BeSameAs(cycled.Genres.ElementAt(1).Books);
        }
コード例 #19
0
        public void VerifySortedDictionary()
        {
            var instance = new Dictionary <string, string>
            {
                ["First"]  = "Value1",
                ["Hello"]  = "World",
                ["Second"] = "Value2",
                ["Last"]   = "Value2",
            }.ToImmutableSortedDictionary();

            var serializer = new ConfigurationContainer().UseAutoFormatting()
                             .UseOptimizedNamespaces()
                             .EnableImmutableTypes()
                             .EnableParameterizedContent()
                             .Create()
                             .ForTesting();

            serializer.Assert(instance,
                              @"<?xml version=""1.0"" encoding=""utf-8""?><ImmutableSortedDictionary xmlns:sys=""https://extendedxmlserializer.github.io/system"" xmlns:exs=""https://extendedxmlserializer.github.io/v2"" exs:arguments=""sys:string,sys:string"" xmlns=""clr-namespace:System.Collections.Immutable;assembly=System.Collections.Immutable""><sys:Item Key=""First"" Value=""Value1"" /><sys:Item Key=""Hello"" Value=""World"" /><sys:Item Key=""Last"" Value=""Value2"" /><sys:Item Key=""Second"" Value=""Value2"" /></ImmutableSortedDictionary>");

            var dictionary = serializer.Cycle(instance);

            dictionary.Should().BeEquivalentTo(instance);

            dictionary["Hello"].Should().Be(instance["Hello"]);
        }
コード例 #20
0
        public void Verify()
        {
            var type = new PathogenType {
                Code = 'f', Description = "Fungus"
            };
            var instance = new List <object>
            {
                new LookupTable <PathogenDto>
                {
                    Models = new List <PathogenDto>
                    {
                        new Pathogen {
                            PathogenType = type
                        }
                    }
                },
                new LookupTable <PathogenTypeDto>
                {
                    Models = new List <PathogenTypeDto> {
                        type
                    }
                }
            };

            var serializer = new ConfigurationContainer().EnableReferences().ForTesting();

            var cycled   = serializer.Cycle(instance);
            var expected = cycled[1].To <LookupTable <PathogenTypeDto> >().Models.Only();

            cycled[0].To <LookupTable <PathogenDto> >()
            .Models[0].PathogenType.Should()
            .BeSameAs(expected);
        }
コード例 #21
0
        public void Verify()
        {
            var sut = new ConfigurationContainer().EnableImplicitTyping(typeof(Root))
                      .Type <Status?>()
                      .Register()
                      .Converter()
                      .Using(NullableStatusConverter.Default)
                      .Type <bool?>()
                      .Register()
                      .Converter()
                      .Using(NullableBoolConverter.Default)
                      .Create()
                      .ForTesting();

            {
                var instance = new Root {
                    On = true, Current = null
                };
                sut.Assert(instance, @"<?xml version=""1.0"" encoding=""utf-8""?><Issue532Tests-Root><On>1</On></Issue532Tests-Root>");
                sut.Cycle(instance).Should().BeEquivalentTo(instance);
            }

            {
                var instance = new Root {
                    On = false, Current = Status.Ok
                };
                sut.Assert(instance, @"<?xml version=""1.0"" encoding=""utf-8""?><Issue532Tests-Root><On>0</On><Current>0</Current></Issue532Tests-Root>");
                sut.Cycle(instance).Should().BeEquivalentTo(instance);
            }

            {
                var instance = new Root {
                    On = null, Current = Status.Not
                };
                sut.Assert(instance, @"<?xml version=""1.0"" encoding=""utf-8""?><Issue532Tests-Root><Current>1</Current></Issue532Tests-Root>");
                sut.Cycle(instance).Should().BeEquivalentTo(instance);
            }

            {
                var instance = new Root {
                    On = null, Current = null
                };
                sut.Assert(instance, @"<?xml version=""1.0"" encoding=""utf-8""?><Issue532Tests-Root />");
                sut.Cycle(instance).Should().BeEquivalentTo(instance);
            }
        }
コード例 #22
0
        public void Verify()
        {
            var          subject  = new ConfigurationContainer().EnableImplicitTyping(typeof(double)).Create().ForTesting();
            const double instance = 123d;

            subject.Assert(instance, @"<?xml version=""1.0"" encoding=""utf-8""?><double>123</double>");
            subject.Cycle(instance).Should().Be(instance);
        }
コード例 #23
0
        public void VerifyThreadAwareness()
        {
            var sut      = new ConfigurationContainer().EnableThreadAwareRecursionContent().Create().ForTesting();
            var instance = new Subject {
                Message = "Hello World!"
            };

            sut.Cycle(instance).Should().BeEquivalentTo(instance);
        }
コード例 #24
0
        public void Verify()
        {
            var sut      = new ConfigurationContainer().EnableStaticReferenceChecking(false).Create().ForTesting();
            var instance = new Subject {
                Other = new Other()
            };

            sut.Cycle(instance).Should().BeEquivalentTo(instance);
        }
コード例 #25
0
        public void Verify()
        {
            var element = new MyElementType
            {
                UniqueId = "Message"
            };
            var myMessage = new MyMessage
            {
                MyElement = element
            };
            var support = new ConfigurationContainer().InspectingType <MyMessage>().ForTesting();

            support.Assert(myMessage, @"<?xml version=""1.0"" encoding=""utf-8""?><myMessage xmlns=""http://namespace/file.xsd""><myElement uniqueId=""Message"" /></myMessage>");
            support.Cycle(myMessage)
            .ShouldBeEquivalentTo(myMessage);

            support.Cycle(element).ShouldBeEquivalentTo(element);
        }
コード例 #26
0
        public void Verify()
        {
            var b1 = new Book();
            var b2 = new Book();
            var b3 = new Book();
            var b4 = new Book();
            var b5 = new Book();
            var b6 = new Book();

            var historyBooks = new[] { b1, b2, };
            var artBooks     = new[] { b3, b4, };
            var scienceBooks = new[] { b5 };
            var comics       = new[] { b6 };

            var all = historyBooks.Concat(artBooks).Concat(scienceBooks).Concat(comics).ToList();

            var fs = new BookStore()
            {
                AllBooks = all,
                Genres   = new[]
                {
                    new Genre()
                    {
                        Books = historyBooks,
                    },
                    new Genre()
                    {
                        Books = historyBooks,
                    },
                    new Genre()
                    {
                        Books = artBooks,
                    },
                    new Genre()
                    {
                        Books = scienceBooks,
                    },
                    new Genre()
                    {
                        Books = comics,
                    },
                }
            };

            var serializer = new ConfigurationContainer().Type <Book>(b => b.EnableReferences())
                             .Create();
            var cycled = serializer.Cycle(fs);

            cycled.Genres.ElementAt(0).Books.ElementAt(0).Should().BeSameAs(cycled.AllBooks.ElementAt(0));
            cycled.Genres.ElementAt(0).Books.ElementAt(1).Should().BeSameAs(cycled.AllBooks.ElementAt(1));
            cycled.Genres.ElementAt(1).Books.ElementAt(0).Should().BeSameAs(cycled.AllBooks.ElementAt(0));
            cycled.Genres.ElementAt(1).Books.ElementAt(1).Should().BeSameAs(cycled.AllBooks.ElementAt(1));
            cycled.Genres.ElementAt(2).Books.ElementAt(0).Should().BeSameAs(cycled.AllBooks.ElementAt(2));
            cycled.Genres.ElementAt(2).Books.ElementAt(1).Should().BeSameAs(cycled.AllBooks.ElementAt(3));
            cycled.Genres.ElementAt(3).Books.ElementAt(0).Should().BeSameAs(cycled.AllBooks.ElementAt(4));
            cycled.Genres.ElementAt(4).Books.ElementAt(0).Should().BeSameAs(cycled.AllBooks.ElementAt(5));
        }
コード例 #27
0
        public void Verify()
        {
            var instance = new Subject {
                List = new List <string>()
            };

            var container = new ConfigurationContainer().Emit(EmitBehaviors.Classic).Create().ForTesting();

            container.Cycle(instance).Should().BeEquivalentTo(instance);
        }
コード例 #28
0
        public void Verify()
        {
            var serializer = new ConfigurationContainer().EnableParameterizedContent()
                             .Create()
                             .ForTesting();

            serializer.Cycle(new Subject(null))
            .Another.Should()
            .BeNull();
        }
コード例 #29
0
        void Verify()
        {
            var serializer = new ConfigurationContainer().UseOptimizedNamespaces()
                             .EnableParameterizedContent()
                             .Create()
                             .ForTesting();
            var instance = new KeyValuePair <string, object>("123", "123");

            serializer.Cycle(instance).Should().BeEquivalentTo(instance);
        }
コード例 #30
0
        public void Issue125()
        {
            var person = new Person {
                FirstName = "John", LastName = string.Empty, Nationality = "British", Married = true
            };
            var support = new ConfigurationContainer().ForTesting();

            support.Cycle(person)
            .ShouldBeEquivalentTo(person);
        }