Esempio n. 1
0
        public void XmlCompareConstraintSimpleEqualsTest()
        {
            var expected = XmlSamples.GetContent("attr");
            var actual   = XmlSamples.GetContent("attr-with-another-order");

            Assert.That(expected, IsXml.Equals(actual));
        }
        public void WriteElementTest(BasicSample sample)
        {
            var expected = string.Format("<xml>{0}</xml>", sample.StringValue);
            var actual   = GetConverter().ToXml(sample.Value);

            Assert.That(actual, IsXml.Equals(expected));
        }
Esempio n. 3
0
        public void XmlCompareConstrainsXDocumentEqual()
        {
            var expected = XDocument.Parse(XmlSamples.GetContent("elements"));
            var actual   = XDocument.Parse(XmlSamples.GetContent("elements-with-comment"));

            Assert.That(expected, IsXml.Equals(actual).WithIgnoreComment());
        }
        public void WriteCollectionWithDifferentItemTypeTest()
        {
            var value = GetCollection(new List <Foo>
            {
                new Foo {
                    Id = 1, Name = "foo"
                },
                new FooBar {
                    Id = 2, Name = "foo-bar"
                }
            });

            var actual   = CreateConverter().ToXml(value.GetType(), value);
            var expected = string.Format(
                @"<xml>
  <foo>
    <id>1</id>
    <name>foo</name>
  </foo>
  <foo xsi:type=""{0}"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
    <id>2</id>
    <name>foo-bar</name>
  </foo>
</xml>",
                typeof(FooBar));

            Assert.That(actual, IsXml.Equals(expected).WithIgnore(XmlComparisonType.NamespacePrefix));
        }
Esempio n. 5
0
        public void SerializeEnumerableTest()
        {
            var value = new List <Foo>
            {
                new Foo {
                    Id = 1
                },
                new Foo {
                    Id = 2
                }
            };

            var actual   = GetSerializer().ToXml <IEnumerable <Foo> >(value);
            var expected = string.Format(@"
<ienumerable xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xsi:type=""{0}"">
  <foo>
    <id>1</id>
  </foo>
  <foo>
    <id>2</id>
</foo>
</ienumerable>", value.GetType().FullName);

            Assert.That(actual, IsXml.Equals(expected).WithIgnoreDeclaration());
        }
        public void WriteAttributeTest(BasicSample sample)
        {
            var expected = string.Format("<xml value=\"{0}\" />", sample.StringValue);
            var actual   = GetConverter().ToXml(sample.Value, member: GetAttributeMember());

            Assert.That(actual, IsXml.Equals(expected));
        }
        public void WriteNullAttributeTest()
        {
            var serializer = new XmlSerializer();
            var actual     = serializer.ToXml(new TestClass2());
            var expected   = "<TestClass2 />";

            Assert.That(actual, IsXml.Equals(expected).WithIgnoreDeclaration());
        }
        public void WriteNullTest()
        {
            var converter = new XmlOptionalConverter();
            var actual    = converter.ToXml <Optional <int?> >(null);
            var expected  = "<xml />";

            Assert.That(actual, IsXml.Equals(expected));
        }
        public void WriteNullableAttributeTest()
        {
            var converter = new XmlOptionalConverter();
            var actual    = converter.ToXml <Optional <int?> >(1, member: GetAttributeMember <int?>());
            var expected  = "<xml value=\"1\" />";

            Assert.That(actual, IsXml.Equals(expected));
        }
        public void WriteNullableTest()
        {
            var converter = new XmlNullableConverter();
            var actual    = converter.ToXml <int?>(1);
            var expected  = "<xml>1</xml>";

            Assert.That(actual, IsXml.Equals(expected));
        }
Esempio n. 11
0
        public void XmlCompareConstrainsEqualsWithDifferentOrder()
        {
            var expected = XmlSamples.GetContent("elements");
            var actual   = XmlSamples.GetContent("elements-with-different-order");

            Assert.That(
                expected,
                IsXml.Equals(actual).UseAnalizer(XmlAnalyzer.Custom().SetEqual(XmlComparisonType.NodeListSequence)));
        }
        public void WriteInt32CollectionTest()
        {
            var value = GetCollection(new List <int> {
                1, 2, 3
            });
            var actual   = CreateConverter().ToXml(value.GetType(), value);
            var expected = "<xml><int>1</int><int>2</int><int>3</int></xml>";

            Assert.That(actual, IsXml.Equals(expected));
        }
Esempio n. 13
0
        public void XmlCompareConstrainWithXsdReference()
        {
            var actual   = XmlSamples.GetContent("with-xsd-reference");
            var expected = XmlSamples.GetContent("with-xsd-another-reference");

            Assert.That(
                expected,
                IsXml.Equals(actual)
                .UseAnalizer(XmlAnalyzer.Custom().SetEqual(XmlComparisonType.SchemaLocation)));
        }
        public void WriteNullWithNullIncludeHandlingTest()
        {
            var serializer = new XmlSerializer();

            serializer.Settings.OmitXmlDeclaration = true;
            serializer.Settings.NullValueHandling  = XmlNullValueHandling.Include;
            var actual   = serializer.ToXml(new TestClass());
            var expected = @"<TestClass xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""><Value xsi:nil=""true"" /></TestClass>";

            Assert.That(actual, IsXml.Equals(expected));
        }
Esempio n. 15
0
        public void SerializeNullTest()
        {
            var serializer = GetSerializer();

            serializer.Settings.NullValueHandling = XmlNullValueHandling.Include;

            var actual = serializer.ToXml <Foo>(null);

            var expected = @"<?xml version=""1.0"" encoding=""utf-16""?>
<foo xsi:nil=""true"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" />";

            Assert.That(actual, IsXml.Equals(expected));
        }
Esempio n. 16
0
        public void XmlCompareConstrainCustomAnalyzerIgnoreNodeMissing()
        {
            var expected = XmlSamples.GetContent("elements");
            var actual   = XmlSamples.GetContent("elements-with-comment");

            Assert.That(
                expected,
                IsXml.Equals(actual)
                .WithIgnoreComment(false)
                .UseAnalizer(XmlAnalyzer.Custom()
                             .SetEqual(XmlComparisonType.NodeList)
                             .SetEqual(XmlComparisonType.NodeListLookup)));
        }
Esempio n. 17
0
        public void WriteFooTest()
        {
            var value = new Foo
            {
                Id   = 1,
                Name = "test"
            };

            var actual   = GetConverter().ToXml(value);
            var expected = "<xml><id>1</id><name>test</name></xml>";

            Assert.That(actual, IsXml.Equals(expected));
        }
Esempio n. 18
0
        public void WriteFooAttributesTest()
        {
            var value = new Foo
            {
                Id   = 1,
                Name = "test"
            };

            var contract = GetContractWithAttributes();
            var actual   = GetConverter().ToXml(value, contract: contract);
            var expected = "<xml id=\"1\" name=\"test\" />";

            Assert.That(actual, IsXml.Equals(expected));
        }
Esempio n. 19
0
        public void WriteFooWithIgnoreNullHandlingTest()
        {
            var value = new Foo
            {
                Id   = 1,
                Name = null
            };

            var contract = GetContractWithIgnoreNull();
            var actual   = GetConverter().ToXml(value, contract: contract);
            var expected = "<xml><id>1</id></xml>";

            Assert.That(actual, IsXml.Equals(expected));
        }
Esempio n. 20
0
        public void WriteFooWithIncludeNullHandlingTest()
        {
            var value = new Foo
            {
                Id   = 1,
                Name = null
            };

            var contract = GetContractWithIncludeNull();
            var actual   = GetConverter().ToXml(value, contract: contract);
            var expected = @"<xml><id>1</id><name xsi:nil=""true"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" /></xml>";

            Assert.That(actual, IsXml.Equals(expected).WithIgnore(XmlComparisonType.NamespacePrefix));
        }
        public void WriteXmlTest()
        {
            var converter = new XmlSerializableConverter();
            var value     = new TestClass
            {
                Id   = 1,
                Name = "hello"
            };

            var actual   = converter.ToXml(value);
            var expected = "<xml id=\"1\"><name>hello</name></xml>";

            Assert.That(actual, IsXml.Equals(expected));
        }
Esempio n. 22
0
        public void WriteXmlWithCollectionPropertyTest()
        {
            var value = new ClassWithCollectionProperty
            {
                Name    = "two",
                Numbers = new List <int> {
                    1, 2
                }
            };

            var actual   = GetConverter().ToXml(value);
            var expected = @"<xml><name>two</name><number>1</number><number>2</number></xml>";

            Assert.That(actual, IsXml.Equals(expected));
        }
Esempio n. 23
0
        public void WriteFooInnerTextTest()
        {
            var contract = GetContractWithInnerText();

            var value = new Foo
            {
                Id   = 1,
                Name = "test"
            };

            var actual   = GetConverter().ToXml(value, contract: contract);
            var expected = @"<xml id=""1"">test</xml>";

            Assert.That(actual, IsXml.Equals(expected));
        }
Esempio n. 24
0
        public void WriteDictionaryWithCustomContractTest()
        {
            var converter = new XmlDictionaryConverter();

            var value = new Dictionary <int, string>
            {
                { 1, "one" },
                { 2, "two" }
            };

            var expected = "<xml><item><key>1</key><value>one</value></item><item><key>2</key><value>two</value></item></xml>";
            var actual   = converter.ToXml(value.GetType(), value, contract: GetCustomContract());

            Assert.That(actual, IsXml.Equals(expected));
        }
Esempio n. 25
0
        public void WriteFooWithDefaultsTest()
        {
            var contract = GetContractWithDefaults();

            var value = new Foo
            {
                Id   = 1,
                Name = "test"
            };

            var actual   = GetConverter().ToXml(value, contract: contract);
            var expected = "<xml><name>test</name></xml>";

            Assert.That(actual, IsXml.Equals(expected));
        }
Esempio n. 26
0
        public void SerializeFooTest()
        {
            var actual = GetSerializer().ToXml(new Foo
            {
                Id   = 1,
                Name = "test"
            });

            var expected = @"<?xml version=""1.0"" encoding=""utf-16""?>
<foo xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
  <id>1</id>
  <name>test</name>
</foo>";

            Assert.That(actual, IsXml.Equals(expected));
        }
        public void WriteFooCollectionTest()
        {
            var value = GetCollection(new List <Foo>
            {
                new Foo {
                    Id = 1, Name = "foo-1"
                },
                new Foo {
                    Id = 2, Name = "foo-2"
                }
            });

            var actual   = CreateConverter().ToXml(value.GetType(), value);
            var expected = "<xml><foo><id>1</id><name>foo-1</name></foo><foo><id>2</id><name>foo-2</name></foo></xml>";

            Assert.That(actual, IsXml.Equals(expected));
        }
Esempio n. 28
0
        public void SerializeFooContainerTest()
        {
            var value = new FooContainer
            {
                Foo = new FooBar
                {
                    Id          = 1,
                    Description = "test"
                }
            };

            var serializer = GetSerializer();
            var actual     = serializer.ToXml(value);
            var expected   = @"<fooContainer xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""><foo xsi:type=""NetBike.Xml.Tests.Samples.FooBar""><description>test</description><id>1</id></foo></fooContainer>";

            Assert.That(actual, IsXml.Equals(expected).WithIgnoreDeclaration());
        }
Esempio n. 29
0
        public void SerializeFooCollectionWithFooBarTypeTest()
        {
            var value = new List <Foo>
            {
                new Foo {
                    Id = 1
                },
                new FooBar {
                    Id = 2, Description = "test"
                }
            };

            var actual   = GetSerializer().ToXml(value);
            var expected = @"<list xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""><foo><id>1</id></foo><foo xsi:type=""NetBike.Xml.Tests.Samples.FooBar""><description>test</description><id>2</id></foo></list>";

            Assert.That(actual, IsXml.Equals(expected).WithIgnoreDeclaration());
        }
Esempio n. 30
0
        public void WriteXmlWithKnownTypePropertyTest()
        {
            var value = new ClassWithKnownTypeProperty
            {
                Name = "test",
                Foo  = new FooBar
                {
                    Id   = 1,
                    Name = "foobar"
                }
            };

            var actual   = GetConverter().ToXml(value);
            var expected = @"<xml><name>test</name><fooBar><id>1</id><name>foobar</name></fooBar></xml>";

            Assert.That(actual, IsXml.Equals(expected));
        }