コード例 #1
0
        public void Verify()
        {
            const string target = "I am Attribute, Hear me roar! #rawr!";

            var configuration = new ConfigurationContainer();

            configuration.Type <SimpleSubject>()
            .Member(x => x.Message)
            .Attribute(x => x == target);

            var support  = new SerializationSupport(configuration);
            var expected = new SimpleSubject {
                Message = "Hello World!", Number = 6776
            };
            var content = support.Assert(expected,
                                         @"<?xml version=""1.0"" encoding=""utf-8""?><AttributeSpecificationTests-SimpleSubject xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.ContentModel.Members;assembly=ExtendedXmlSerializer.Tests""><Message>Hello World!</Message><Number>6776</Number></AttributeSpecificationTests-SimpleSubject>");

            Assert.Equal(expected.Message, content.Message);
            Assert.Equal(expected.Number, content.Number);

            expected.Message = target;
            var attributes = support.Assert(expected,
                                            @"<?xml version=""1.0"" encoding=""utf-8""?><AttributeSpecificationTests-SimpleSubject Message=""I am Attribute, Hear me roar! #rawr!"" xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.ContentModel.Members;assembly=ExtendedXmlSerializer.Tests""><Number>6776</Number></AttributeSpecificationTests-SimpleSubject>");

            Assert.Equal(expected.Message, attributes.Message);
            Assert.Equal(expected.Number, attributes.Number);
        }
コード例 #2
0
        public void ConfigureEncrypt()
        {
            var configuration = new ConfigurationContainer();

            Assert.Null(configuration.Root.Find <EncryptionExtension>());
            configuration.UseEncryptionAlgorithm()
            .ConfigureType <TestClassWithEncryptedData>()
            .Member(p => p.Password, x => x.Encrypt())
            .Member(p => p.Salary)
            .Encrypt();

            var extension = configuration.Root.Find <EncryptionExtension>();

            Assert.NotNull(extension);
            var type = configuration.GetTypeConfiguration(typeof(TestClassWithEncryptedData));

            Assert.NotNull(type);

            var member   = type.Member(nameof(TestClassWithEncryptedData.Salary));
            var property = ((ISource <MemberInfo>)member).Get();

            Assert.NotNull(property);
            Assert.Contains(property, extension.Registered);

            const int salary   = 6776;
            var       instance = new TestClassWithEncryptedData {
                Salary = salary
            };
            var support = new SerializationSupport(configuration);
            var actual  = support.Assert(instance, @"<?xml version=""1.0"" encoding=""utf-8""?><TestClassWithEncryptedData xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.TestObject;assembly=ExtendedXmlSerializer.Tests""><Salary>Njc3Ng==</Salary></TestClassWithEncryptedData>");

            Assert.Equal(salary, actual.Salary);
        }
コード例 #3
0
        public void Verify()
        {
            var subject = new Subject {
                Message = "Hello World!"
            };

            NameProperty.Default.Assign(subject, "SubjectName");
            NumberProperty.Default.Assign(subject, 6776);

            var serializer = new SerializationSupport(
                new ConfigurationContainer()
                .EnableAttachedProperties(NameProperty.Default,
                                          NumberProperty.Default)
                );

            var actual = serializer.Assert(subject,
                                           @"<?xml version=""1.0"" encoding=""utf-8""?><AttachedPropertiesExtensionTests-Subject xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.ExtensionModel.AttachedProperties;assembly=ExtendedXmlSerializer.Tests""><Message>Hello World!</Message><AttachedPropertiesExtensionTests-NameProperty.Default>SubjectName</AttachedPropertiesExtensionTests-NameProperty.Default><AttachedPropertiesExtensionTests-NumberProperty.Default>6776</AttachedPropertiesExtensionTests-NumberProperty.Default></AttachedPropertiesExtensionTests-Subject>");

            actual.Should().BeEquivalentTo(subject);
            actual.Get(NameProperty.Default)
            .Should()
            .Be("SubjectName");
            actual.Get(NumberProperty.Default)
            .Should()
            .Be(6776);
        }
コード例 #4
0
        public void VerifyAttributes()
        {
            var subject = new Subject {
                Message = "Hello World!"
            };

            subject.Set(NameProperty.Default, "SubjectName");
            subject.Set(NumberProperty.Default, 6776);

            var serializer =
                new SerializationSupport(new ConfigurationContainer().UseAutoFormatting()
                                         .EnableAttachedProperties(NameProperty.Default,
                                                                   NumberProperty
                                                                   .Default));
            var actual = serializer.Assert(subject,
                                           @"<?xml version=""1.0"" encoding=""utf-8""?><AttachedPropertiesExtensionTests-Subject Message=""Hello World!"" AttachedPropertiesExtensionTests-NameProperty.Default=""SubjectName"" AttachedPropertiesExtensionTests-NumberProperty.Default=""6776"" xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.ExtensionModel.AttachedProperties;assembly=ExtendedXmlSerializer.Tests"" />");

            actual.Should().BeEquivalentTo(subject);
            actual.Get(NameProperty.Default)
            .Should()
            .Be("SubjectName");
            actual.Get(NumberProperty.Default)
            .Should()
            .Be(6776);
        }
コード例 #5
0
        public void Verify()
        {
            var container = new Optimizations();
            var sut       = new Alteration(container);
            var support   = new SerializationSupport(new ConfigurationContainer().Alter(sut)
                                                     .Create());

            const float number = 4.5678f;
            var         actual =
                support.Assert(number,
                               @"<?xml version=""1.0"" encoding=""utf-8""?><float xmlns=""https://extendedxmlserializer.github.io/system"">4.5678</float>");

            Assert.Equal(number, actual);

            var converter = sut.Get(FloatConverter.Default);
            var format    = converter.Format(number);

            for (var i = 0; i < 10; i++)
            {
                Assert.Same(format, converter.Format(number));
            }

            container.Clear();
            Assert.NotSame(format, converter.Format(number));
        }
コード例 #6
0
        public void VerifyConfiguration()
        {
            var subject = new Subject {
                Message = "Hello World!"
            };

            subject.Set(NumberProperty.Default, 6776);

            var container = new ConfigurationContainer();

            container.UseAutoFormatting()
            .Type <NumberProperty>()
            .Name("ConfiguredAttachedProperty");

            container.AttachedProperty(() => NumberProperty.Default)
            .Name("NewNumberPropertyName");
            var serializer = new SerializationSupport(container);

            var actual = serializer.Assert(subject,
                                           @"<?xml version=""1.0"" encoding=""utf-8""?><AttachedPropertiesExtensionTests-Subject Message=""Hello World!"" ConfiguredAttachedProperty.NewNumberPropertyName=""6776"" xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.ExtensionModel.AttachedProperties;assembly=ExtendedXmlSerializer.Tests"" />");

            actual.Should().BeEquivalentTo(subject);
            actual.Get(NumberProperty.Default)
            .Should()
            .Be(6776);
        }
コード例 #7
0
        public void VerifyAutoFormattingWithLongContent()
        {
            var support = new SerializationSupport(new ConfigurationContainer().UseAutoFormatting()
                                                   .Create());
            var instance = TestClassPrimitiveTypes.Create();

            instance.PropString =
                "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed urna sapien, pulvinar et consequat sit amet, fermentum in volutpat. This sentence should break the property out into content.";

#if CORE
            support.Assert(instance,
                           @"<?xml version=""1.0"" encoding=""utf-8""?><TestClassPrimitiveTypes PropInt=""-1"" PropuInt=""2234"" PropDecimal=""3.346"" PropDecimalMinValue=""-79228162514264337593543950335"" PropDecimalMaxValue=""79228162514264337593543950335"" PropFloat=""7.4432"" PropFloatNaN=""NaN"" PropFloatPositiveInfinity=""INF"" PropFloatNegativeInfinity=""-INF"" PropFloatMinValue=""-3.4028235E+38"" PropFloatMaxValue=""3.4028235E+38"" PropDouble=""3.4234"" PropDoubleNaN=""NaN"" PropDoublePositiveInfinity=""INF"" PropDoubleNegativeInfinity=""-INF"" PropDoubleMinValue=""-1.7976931348623157E+308"" PropDoubleMaxValue=""1.7976931348623157E+308"" PropEnum=""EnumValue1"" PropLong=""234234142"" PropUlong=""2345352534"" PropShort=""23"" PropUshort=""2344"" PropDateTime=""2014-01-23T00:00:00"" PropByte=""23"" PropSbyte=""33"" PropChar=""g"" xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.TestObject;assembly=ExtendedXmlSerializer.Tests""><PropString>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed urna sapien, pulvinar et consequat sit amet, fermentum in volutpat. This sentence should break the property out into content.</PropString></TestClassPrimitiveTypes>");
#else
            support.Assert(instance,
                           @"<?xml version=""1.0"" encoding=""utf-8""?><TestClassPrimitiveTypes PropInt=""-1"" PropuInt=""2234"" PropDecimal=""3.346"" PropDecimalMinValue=""-79228162514264337593543950335"" PropDecimalMaxValue=""79228162514264337593543950335"" PropFloat=""7.4432"" PropFloatNaN=""NaN"" PropFloatPositiveInfinity=""INF"" PropFloatNegativeInfinity=""-INF"" PropFloatMinValue=""-3.40282347E+38"" PropFloatMaxValue=""3.40282347E+38"" PropDouble=""3.4234"" PropDoubleNaN=""NaN"" PropDoublePositiveInfinity=""INF"" PropDoubleNegativeInfinity=""-INF"" PropDoubleMinValue=""-1.7976931348623157E+308"" PropDoubleMaxValue=""1.7976931348623157E+308"" PropEnum=""EnumValue1"" PropLong=""234234142"" PropUlong=""2345352534"" PropShort=""23"" PropUshort=""2344"" PropDateTime=""2014-01-23T00:00:00"" PropByte=""23"" PropSbyte=""33"" PropChar=""g"" xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.TestObject;assembly=ExtendedXmlSerializer.Tests""><PropString>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed urna sapien, pulvinar et consequat sit amet, fermentum in volutpat. This sentence should break the property out into content.</PropString></TestClassPrimitiveTypes>");
#endif
        }
コード例 #8
0
        public void Field()
        {
            var support  = new SerializationSupport();
            var expected = new Subject("Hello", "World!");
            var actual   = support.Assert(expected, @"<?xml version=""1.0"" encoding=""utf-8""?><CollectionContentOptionTests-Subject xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.ContentModel.Collections;assembly=ExtendedXmlSerializer.Tests""><_children><Capacity>4</Capacity><string xmlns=""https://extendedxmlserializer.github.io/system"">Hello</string><string xmlns=""https://extendedxmlserializer.github.io/system"">World!</string></_children></CollectionContentOptionTests-Subject>");

            Assert.Equal(expected.ToArray(), actual.ToArray());
        }
コード例 #9
0
        public void Verify()
        {
            var serializer = new SerializationSupport(new ConfigurationContainer().EnableParameterizedContent());
            var expected   = new Subject("Hello World!");
            var actual     = serializer.Assert(expected,
                                               @"<?xml version=""1.0"" encoding=""utf-8""?><ParameterizedMembersExtensionTests-Subject xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.ExtensionModel.Content.Members;assembly=ExtendedXmlSerializer.Tests""><Message>Hello World!</Message></ParameterizedMembersExtensionTests-Subject>");

            Assert.Equal(expected.Message, actual.Message);
        }
コード例 #10
0
        public void BasicTuple()
        {
            var serializer = new SerializationSupport(new ConfigurationContainer().EnableParameterizedContent());
            var expected   = new Tuple <string>("Hello World!");
            var actual     = serializer.Assert(expected,
                                               @"<?xml version=""1.0"" encoding=""utf-8""?><Tuple xmlns:exs=""https://extendedxmlserializer.github.io/v2"" exs:arguments=""string"" xmlns=""https://extendedxmlserializer.github.io/system""><Item1>Hello World!</Item1></Tuple>");

            actual.ShouldBeEquivalentTo(expected);
        }
コード例 #11
0
        public void Verify()
        {
            var instance = new byte[] { 1, 2, 3, 4, 5, 6, 7, 7, 6, 5, 4, 3, 2, 1 };

            var support = new SerializationSupport();
            var actual  = support.Assert(instance, @"<?xml version=""1.0"" encoding=""utf-8""?><Array xmlns:exs=""https://extendedxmlserializer.github.io/v2"" exs:item=""unsignedByte"" xmlns=""https://extendedxmlserializer.github.io/system"">AQIDBAUGBwcGBQQDAgE=</Array>");

            Assert.Equal(instance, actual);
        }
コード例 #12
0
        public void ComplexList()
        {
            var container = new ConfigurationContainer();

            container.Type <TestClassReference>()
            .EnableReferences(x => x.Id);
            var support = new SerializationSupport(container);

            var instance = new TestClassReferenceWithList {
                Parent = new TestClassReference {
                    Id = 1
                }
            };
            var other = new TestClassReference
            {
                Id = 2, ObjectA = instance.Parent, ReferenceToObjectA = instance.Parent
            };

            instance.All = new List <IReference>
            {
                new TestClassReference {
                    Id = 3, ObjectA = instance.Parent, ReferenceToObjectA = instance.Parent
                },
                new TestClassReference {
                    Id = 4, ObjectA = other, ReferenceToObjectA = other
                },
                other,
                instance.Parent
            };
            var actual = support.Assert(instance,
                                        @"<?xml version=""1.0"" encoding=""utf-8""?><TestClassReferenceWithList xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.TestObject;assembly=ExtendedXmlSerializer.Tests""><Parent xmlns:exs=""https://extendedxmlserializer.github.io/v2"" exs:type=""TestClassReference"" Id=""1"" /><All><Capacity>4</Capacity><TestClassReference Id=""3""><ObjectA xmlns:exs=""https://extendedxmlserializer.github.io/v2"" exs:type=""TestClassReference"" exs:entity=""1"" /><ReferenceToObjectA xmlns:exs=""https://extendedxmlserializer.github.io/v2"" exs:type=""TestClassReference"" exs:entity=""1"" /></TestClassReference><TestClassReference Id=""4""><ObjectA xmlns:exs=""https://extendedxmlserializer.github.io/v2"" exs:type=""TestClassReference"" Id=""2""><ObjectA exs:type=""TestClassReference"" exs:entity=""1"" /><ReferenceToObjectA exs:type=""TestClassReference"" exs:entity=""1"" /></ObjectA><ReferenceToObjectA xmlns:exs=""https://extendedxmlserializer.github.io/v2"" exs:type=""TestClassReference"" exs:entity=""2"" /></TestClassReference><TestClassReference xmlns:exs=""https://extendedxmlserializer.github.io/v2"" exs:entity=""2"" /><TestClassReference xmlns:exs=""https://extendedxmlserializer.github.io/v2"" exs:entity=""1"" /></All></TestClassReferenceWithList>");

            Assert.NotNull(actual.Parent);
            var list = actual.All.Cast <TestClassReference>()
                       .ToList();

            Assert.Same(actual.Parent, list[0]
                        .ObjectA);
            Assert.Same(actual.Parent, list[0]
                        .ReferenceToObjectA);
            Assert.Same(list[1]
                        .ObjectA, list[1]
                        .ReferenceToObjectA);
            Assert.Same(list[1]
                        .ObjectA.To <TestClassReference>()
                        .ObjectA,
                        list[1]
                        .ObjectA.To <TestClassReference>()
                        .ReferenceToObjectA);
            Assert.Same(actual.Parent, list[1]
                        .ObjectA.To <TestClassReference>()
                        .ObjectA);
            Assert.Same(list[2], list[1]
                        .ObjectA);
            Assert.Same(actual.Parent, list[3]);
        }
コード例 #13
0
        public void CreatedTuple()
        {
            var serializer = new SerializationSupport(new ConfigurationContainer().EnableParameterizedContent());
            var expected   = Tuple.Create("Hello World!", 6776, TypeCode.Empty);

            var actual = serializer.Assert(expected,
                                           @"<?xml version=""1.0"" encoding=""utf-8""?><Tuple xmlns:exs=""https://extendedxmlserializer.github.io/v2"" exs:arguments=""string,int,TypeCode"" xmlns=""https://extendedxmlserializer.github.io/system""><Item1>Hello World!</Item1><Item2>6776</Item2><Item3>Empty</Item3></Tuple>");

            actual.ShouldBeEquivalentTo(expected);
        }
コード例 #14
0
        public void Verify()
        {
            var expected  = ImmutableArray.Create("Hello", "World!");
            var container = new ConfigurationContainer();
            // container.EnableImmutableArrays();
            var serializer = new SerializationSupport(container);
            var actual     = serializer.Assert(expected, @"<?xml version=""1.0"" encoding=""utf-8""?><ImmutableArray xmlns:sys=""https://extendedxmlserializer.github.io/system"" xmlns:exs=""https://extendedxmlserializer.github.io/v2"" exs:arguments=""sys:string"" xmlns=""clr-namespace:System.Collections.Immutable;assembly=System.Collections.Immutable""><sys:string>Hello</sys:string><sys:string>World!</sys:string></ImmutableArray>");

            Assert.True(expected.SequenceEqual(actual));
        }
コード例 #15
0
        public void MultipleConstructors()
        {
            var serializer = new SerializationSupport(new ConfigurationContainer().EnableParameterizedContent());
            var expected   = new SubjectWithMultipleConstructors(6776, new DateTime(1976, 6, 7));
            var actual     = serializer.Assert(expected,
                                               @"<?xml version=""1.0"" encoding=""utf-8""?><ParameterizedMembersExtensionTests-SubjectWithMultipleConstructors xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.ExtensionModel.Content.Members;assembly=ExtendedXmlSerializer.Tests""><Number>6776</Number><DateTime>1976-06-07T00:00:00</DateTime></ParameterizedMembersExtensionTests-SubjectWithMultipleConstructors>");

            Assert.Equal(expected.Number, actual.Number);
            Assert.Equal(expected.DateTime, actual.DateTime);
            Assert.Equal(SubjectWithMultipleConstructors.Message, actual.Get());
        }
コード例 #16
0
        public void Verify()
        {
            var serializer = new ConfigurationContainer().Type <TestClassWithSerializer>()
                             .CustomSerializer(new CustomSerializer())
                             .Create();
            var support  = new SerializationSupport(serializer);
            var expected = new TestClassWithSerializer("String", 17);
            var actual   = support.Assert(expected,
                                          @"<?xml version=""1.0"" encoding=""utf-8""?><TestClassWithSerializer xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.TestObject;assembly=ExtendedXmlSerializer.Tests""><String>String</String><Int>17</Int></TestClassWithSerializer>"
                                          );

            Assert.Equal(expected.PropInt, actual.PropInt);
            Assert.Equal(expected.PropStr, actual.PropStr);
        }
コード例 #17
0
        public void EmitValuesBasedOnInstanceDefaults()
        {
            var instance = new SubjectWithDefaultValue();

            new SerializationSupport().Assert(instance,
                                              @"<?xml version=""1.0"" encoding=""utf-8""?><AllowedAssignedInstanceValuesTests-SubjectWithDefaultValue xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.ContentModel.Members;assembly=ExtendedXmlSerializer.Tests""><SomeValue>This is a Default Value!</SomeValue></AllowedAssignedInstanceValuesTests-SubjectWithDefaultValue>");

            var configuration = new ConfigurationContainer().Emit(EmitBehaviors.WhenModified);

            var support = new SerializationSupport(configuration);

            support.Assert(instance,
                           @"<?xml version=""1.0"" encoding=""utf-8""?><AllowedAssignedInstanceValuesTests-SubjectWithDefaultValue xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.ContentModel.Members;assembly=ExtendedXmlSerializer.Tests"" />");
        }
コード例 #18
0
        public void ConfiguredTuple()
        {
            var container = new ConfigurationContainer();

            container.EnableParameterizedContent()
            .Type <Tuple <string> >()
            .Member(x => x.Item1)
            .Name("NewName");
            var serializer = new SerializationSupport(container);
            var expected   = new Tuple <string>("Hello World!");
            var actual     = serializer.Assert(expected,
                                               @"<?xml version=""1.0"" encoding=""utf-8""?><Tuple xmlns:exs=""https://extendedxmlserializer.github.io/v2"" exs:arguments=""string"" xmlns=""https://extendedxmlserializer.github.io/system""><NewName>Hello World!</NewName></Tuple>");

            actual.ShouldBeEquivalentTo(expected);
        }
コード例 #19
0
        public void SimpleIdentity()
        {
            var support = new SerializationSupport(new ConfigurationContainer().EnableReferences()
                                                   .Create());
            var instance = new Subject {
                Id = new Guid("{0E2DECA4-CC38-46BA-9C47-94B8070D7353}"), PropertyName = "Hello World!"
            };

            instance.Self = instance;
            var actual = support.Assert(instance,
                                        @"<?xml version=""1.0"" encoding=""utf-8""?><ReferencesExtensionTests-Subject xmlns:exs=""https://extendedxmlserializer.github.io/v2"" exs:identity=""1"" xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.ExtensionModel.References;assembly=ExtendedXmlSerializer.Tests""><Id>0e2deca4-cc38-46ba-9c47-94b8070d7353</Id><Self exs:reference=""1"" /><PropertyName>Hello World!</PropertyName></ReferencesExtensionTests-Subject>");

            Assert.NotNull(actual.Self);
            Assert.Same(actual, actual.Self);
        }
コード例 #20
0
        public void SimpleStringAsAttribute()
        {
            const string message = "Hello World!  This is my encrypted message!";
            var          support = new SerializationSupport(new ConfigurationContainer().Emit(EmitBehaviors.Assigned)
                                                            .Type <SimpleSubject>()
                                                            .Member(x => x.Message).Attribute().Encrypt()
                                                            .Create());
            var expected = new SimpleSubject {
                Message = message
            };
            var actual = support.Assert(expected,
                                        @"<?xml version=""1.0"" encoding=""utf-8""?><EncryptionExtensionTests-SimpleSubject Message=""SGVsbG8gV29ybGQhICBUaGlzIGlzIG15IGVuY3J5cHRlZCBtZXNzYWdlIQ=="" xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.ExtensionModel.Encryption;assembly=ExtendedXmlSerializer.Tests"" />");

            Assert.Equal(message, actual.Message);
        }
コード例 #21
0
        public void SimpleNonStringAsAttribute()
        {
            const string message    = "Hello World!  This is my unencrypted message!";
            var          identifier = new Guid("B496F7F5-58F8-41BF-AF18-117B8F3743BF");

            var support  = new SerializationSupport(new ConfigurationContainer().Type <SimpleSubject>().Member(x => x.Identifier).Attribute().Encrypt().Create());
            var expected = new SimpleSubject {
                Identifier = identifier, Message = message
            };
            var actual = support.Assert(expected,
                                        @"<?xml version=""1.0"" encoding=""utf-8""?><EncryptionExtensionTests-SimpleSubject Identifier=""YjQ5NmY3ZjUtNThmOC00MWJmLWFmMTgtMTE3YjhmMzc0M2Jm"" xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.ExtensionModel.Encryption;assembly=ExtendedXmlSerializer.Tests""><Message>Hello World!  This is my unencrypted message!</Message></EncryptionExtensionTests-SimpleSubject>");

            Assert.Equal(identifier, actual.Identifier);
            Assert.Equal(message, actual.Message);
        }
コード例 #22
0
        public void List()
        {
            var container = new ConfigurationContainer();

            container.Type <TestClassReference>()
            .EnableReferences(x => x.Id);
            var support = new SerializationSupport(container);

            var parent = new TestClassReference {
                Id = 1
            };
            var other = new TestClassReference {
                Id = 2, ObjectA = parent, ReferenceToObjectA = parent
            };

            var instance = new List <IReference>
            {
                new TestClassReference {
                    Id = 3, ObjectA = parent, ReferenceToObjectA = parent
                },
                new TestClassReference {
                    Id = 4, ObjectA = other, ReferenceToObjectA = other
                },
                other,
                parent
            };

            var actual = support.Assert(instance,
                                        @"<?xml version=""1.0"" encoding=""utf-8""?><List xmlns:ns1=""clr-namespace:ExtendedXmlSerializer.Tests.TestObject;assembly=ExtendedXmlSerializer.Tests"" xmlns:exs=""https://extendedxmlserializer.github.io/v2"" exs:arguments=""ns1:IReference"" xmlns=""https://extendedxmlserializer.github.io/system""><Capacity>4</Capacity><ns1:TestClassReference Id=""3""><ObjectA exs:type=""ns1:TestClassReference"" Id=""1"" /><ReferenceToObjectA exs:type=""ns1:TestClassReference"" exs:entity=""1"" /></ns1:TestClassReference><ns1:TestClassReference Id=""4""><ObjectA exs:type=""ns1:TestClassReference"" Id=""2""><ObjectA exs:type=""ns1:TestClassReference"" exs:entity=""1"" /><ReferenceToObjectA exs:type=""ns1:TestClassReference"" exs:entity=""1"" /></ObjectA><ReferenceToObjectA exs:type=""ns1:TestClassReference"" exs:entity=""2"" /></ns1:TestClassReference><ns1:TestClassReference exs:entity=""2"" /><ns1:TestClassReference exs:entity=""1"" /></List>");

            Assert.Same(actual[0]
                        .To <TestClassReference>()
                        .ObjectA, actual[0]
                        .To <TestClassReference>()
                        .ReferenceToObjectA);
            Assert.Same(actual[1]
                        .To <TestClassReference>()
                        .ObjectA, actual[1]
                        .To <TestClassReference>()
                        .ReferenceToObjectA);
            Assert.Same(actual[2], actual[1]
                        .To <TestClassReference>()
                        .ObjectA);
            Assert.Same(actual[3], actual[0]
                        .To <TestClassReference>()
                        .ObjectA);
        }
コード例 #23
0
        public void ConfiguredCreatedTuple()
        {
            var container = new ConfigurationContainer();

            container.UseAutoFormatting()
            .EnableParameterizedContent()
            .Type <Tuple <string, int, TypeCode> >()
            .Member(x => x.Item1, m => m.Name("Message"))
            .Member(x => x.Item2, m => m.Name("Number"))
            .Member(x => x.Item3, m => m.Name("Codez"));
            var serializer = new SerializationSupport(container);
            var expected   = Tuple.Create("Hello World!", 6776, TypeCode.Empty);
            var actual     = serializer.Assert(expected,
                                               @"<?xml version=""1.0"" encoding=""utf-8""?><Tuple xmlns:exs=""https://extendedxmlserializer.github.io/v2"" exs:arguments=""string,int,TypeCode"" Message=""Hello World!"" Number=""6776"" Codez=""Empty"" xmlns=""https://extendedxmlserializer.github.io/system"" />");

            actual.ShouldBeEquivalentTo(expected);
        }
コード例 #24
0
        public void VerifyExplicit()
        {
            var types = new HashSet <Type> {
                typeof(string), typeof(Subject), typeof(ExtendedList)
            };
            var serializer = new SerializationSupport(new ConfigurationContainer().EnableImplicitTyping(types));
            var expected   = new Subject {
                Items = new ExtendedList {
                    "Hello", "World!"
                }
            };

            var actual = serializer.Assert(expected,
                                           @"<?xml version=""1.0"" encoding=""utf-8""?><ImplicitTypingExtensionTests-Subject><Items xmlns:exs=""https://extendedxmlserializer.github.io/v2"" exs:type=""ImplicitTypingExtensionTests-ExtendedList""><Capacity>4</Capacity><string>Hello</string><string>World!</string></Items></ImplicitTypingExtensionTests-Subject>");

            Assert.Equal(expected.Items, actual.Items);
        }
コード例 #25
0
        public void ConfigureNameForProperty()
        {
            var configuration =
                Configure(cfg => cfg.ConfigureType <SimpleTestSubject>().Member(p => p.BasicProperty).Name(MemberName));

            var member =
                configuration.GetTypeConfiguration(typeof(SimpleTestSubject)).Member(nameof(SimpleTestSubject.BasicProperty));

            Assert.Equal(configuration.Root.Find <MemberPropertiesExtension>().Names[((ISource <MemberInfo>)member).Get()], MemberName);

            var support  = new SerializationSupport(configuration);
            var instance = new SimpleTestSubject {
                BasicProperty = "Hello World!  Testing Member."
            };

            support.Assert(instance,
                           @"<?xml version=""1.0"" encoding=""utf-8""?><ConfigurationContainerTests-SimpleTestSubject xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.Configuration;assembly=ExtendedXmlSerializer.Tests""><UpdatedMemberName>Hello World!  Testing Member.</UpdatedMemberName></ConfigurationContainerTests-SimpleTestSubject>");
        }
コード例 #26
0
        public void ConfigureNameForType()
        {
            var configuration = new ConfigurationContainer();

            configuration.Type <SimpleTestSubject>().Name(Testclass);

            var names = configuration.Root.Find <TypeNamesExtension>()
                        .Names;

            Assert.Equal(names[typeof(SimpleTestSubject).GetTypeInfo()], Testclass);
            Assert.False(names.ContainsKey(typeof(TestClassPrimitiveTypesNullable).GetTypeInfo()));

            var support  = new SerializationSupport(configuration);
            var expected = new SimpleTestSubject {
                BasicProperty = "Hello World!"
            };
            var actual = support.Assert(expected,
                                        @"<?xml version=""1.0"" encoding=""utf-8""?><UpdatedTestClassName xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.Configuration;assembly=ExtendedXmlSerializer.Tests""><BasicProperty>Hello World!</BasicProperty></UpdatedTestClassName>");

            Assert.Equal(expected.BasicProperty, actual.BasicProperty);
        }
コード例 #27
0
        public void EnabledWithoutConfiguration()
        {
            var support = new SerializationSupport(new ConfigurationContainer().EnableReferences()
                                                   .Create());
            var expected = new Subject
            {
                Id           = Guid,
                PropertyName = "Primary Root",
                Self         = new Subject {
                    Id = Guid, PropertyName = "Another subject"
                }
            };
            var actual = support.Assert(expected,
                                        @"<?xml version=""1.0"" encoding=""utf-8""?><ReferencesExtensionTests-Subject xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.ExtensionModel.References;assembly=ExtendedXmlSerializer.Tests""><Id>6dbb618f-dbbd-4909-9644-a1d955f06249</Id><Self><Id>6dbb618f-dbbd-4909-9644-a1d955f06249</Id><PropertyName>Another subject</PropertyName></Self><PropertyName>Primary Root</PropertyName></ReferencesExtensionTests-Subject>");

            Assert.NotNull(actual.Self);
            Assert.NotSame(actual, actual.Self);
            Assert.StrictEqual(expected.Id, actual.Id);
            Assert.StrictEqual(expected.Self.Id, actual.Self.Id);
            Assert.StrictEqual(expected.Id, expected.Self.Id);
        }
コード例 #28
0
        public void Verify()
        {
            var container = new ConfigurationContainer();

            container.Type <Subject>()
            .AddMigration(new PropertyMigration("OldPropertyName", nameof(Subject.PropertyName)));
            var support  = new SerializationSupport(container);
            var instance = new Subject {
                PropertyName = "Hello World!"
            };

            support.Assert(instance,
                           @"<?xml version=""1.0"" encoding=""utf-8""?><MigrationsExtensionTests-Subject xmlns:exs=""https://extendedxmlserializer.github.io/v2"" exs:version=""1"" xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.ExtensionModel.Xml;assembly=ExtendedXmlSerializer.Tests""><PropertyName>Hello World!</PropertyName></MigrationsExtensionTests-Subject>");

            var data =
                @"<?xml version=""1.0"" encoding=""utf-8""?><MigrationsExtensionTests-Subject xmlns:exs=""https://extendedxmlserializer.github.io/v2"" xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.ExtensionModel.Xml;assembly=ExtendedXmlSerializer.Tests""><OldPropertyName>Hello World from Old Property!</OldPropertyName></MigrationsExtensionTests-Subject>";
            var migrated = support.Deserialize <Subject>(data);

            Assert.NotNull(migrated);
            Assert.Equal("Hello World from Old Property!", migrated.PropertyName);
        }
コード例 #29
0
        public void SimpleEntity()
        {
            var configuration = new ConfigurationContainer();

            configuration.Type <Subject>()
            .Member(x => x.Id)
            .Identity();
            var support  = new SerializationSupport(configuration);
            var expected = new Subject
            {
                Id           = Guid,
                PropertyName = "Primary Root"
            };

            expected.Self = expected;
            var actual = support.Assert(expected,
                                        @"<?xml version=""1.0"" encoding=""utf-8""?><ReferencesExtensionTests-Subject Id=""6dbb618f-dbbd-4909-9644-a1d955f06249"" xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.ExtensionModel.References;assembly=ExtendedXmlSerializer.Tests""><Self xmlns:exs=""https://extendedxmlserializer.github.io/v2"" exs:entity=""6dbb618f-dbbd-4909-9644-a1d955f06249"" /><PropertyName>Primary Root</PropertyName></ReferencesExtensionTests-Subject>");

            Assert.NotNull(actual.Self);
            Assert.Same(actual, actual.Self);
        }
コード例 #30
0
        public void ComplexInstance()
        {
            var configuration = new ConfigurationContainer();

            configuration.Type <TestClassReference>()
            .EnableReferences(x => x.Id);
            var support = new SerializationSupport(configuration);

            var instance = new TestClassReference
            {
                Id      = 1,
                ObjectA = new TestClassReference {
                    Id = 2
                }
            };

            instance.CyclicReference    = instance;
            instance.ReferenceToObjectA = instance.ObjectA;
            instance.Lists = new List <IReference>
            {
                new TestClassReference {
                    Id = 3
                },
                new TestClassReference {
                    Id = 4
                }
            };

            var actual = support.Assert(instance,
                                        @"<?xml version=""1.0"" encoding=""utf-8""?><TestClassReference Id=""1"" xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.TestObject;assembly=ExtendedXmlSerializer.Tests""><CyclicReference xmlns:exs=""https://extendedxmlserializer.github.io/v2"" exs:type=""TestClassReference"" exs:entity=""1"" /><ObjectA xmlns:exs=""https://extendedxmlserializer.github.io/v2"" exs:type=""TestClassReference"" Id=""2"" /><ReferenceToObjectA xmlns:exs=""https://extendedxmlserializer.github.io/v2"" exs:type=""TestClassReference"" exs:entity=""2"" /><Lists><Capacity>4</Capacity><TestClassReference Id=""3"" /><TestClassReference Id=""4"" /></Lists></TestClassReference>");

            Assert.NotNull(actual.ObjectA);
            Assert.Same(instance, instance.CyclicReference);
            Assert.Same(instance.ObjectA, instance.ReferenceToObjectA);
            Assert.Equal(3, instance.Lists.First()
                         .Id);
            Assert.Equal(4, instance.Lists.Last()
                         .Id);
        }