public void XmlRoundtrip()
        {
            var uv  = UnitVector3D.Create(0.2672612419124244, -0.53452248382484879, 0.80178372573727319);
            var xml = "<UnitVector3D X=\"0.2672612419124244\" Y=\"-0.53452248382484879\" Z=\"0.80178372573727319\" />";

            AssertXml.XmlRoundTrips(uv, xml, (expected, actual) => AssertGeometry.AreEqual(expected, actual));
        }
예제 #2
0
        public void TestWinMdExpData_AnonymousTypes()
        {
            #region "Source"
            var text = @"
namespace X
{ 
	public sealed class TestCase
	{
		public void M() 
		{ 
			var a = new { x = 1, y = new { a = 1 } };
			var b = new { t = new { t = new { t = new { t = new { a = 1 } } } } };
		}
	}
}";
            #endregion

            string expected = @"<?xml version=""1.0"" encoding=""utf-16""?>
<token-map>
  <token-location token=""0x02xxxxxx"" file=""source.cs"" start-line=""4"" start-column=""22"" end-line=""4"" end-column=""30"" />
  <token-location token=""0x06xxxxxx"" file=""source.cs"" start-line=""4"" start-column=""22"" end-line=""4"" end-column=""30"" />
  <token-location token=""0x06xxxxxx"" file=""source.cs"" start-line=""6"" start-column=""15"" end-line=""6"" end-column=""16"" />
</token-map>";

            var compilation = CreateCompilationWithMscorlib45(
                text,
                options: TestOptions.ReleaseWinMD,
                sourceFileName: "source.cs").VerifyDiagnostics();

            string actual = PdbTestUtilities.GetTokenToLocationMap(compilation, true);
            AssertXml.Equal(expected, actual);
        }
예제 #3
0
        private static void VerifyPdbImpl(
            this Compilation compilation,
            IMethodSymbol debugEntryPoint,
            string qualifiedMethodName,
            string expectedPdb,
            DebugInformationFormat format,
            PdbToXmlOptions options,
            int expectedValueSourceLine,
            string expectedValueSourcePath,
            bool expectedIsXmlLiteral)
        {
            Assert.NotEqual(DebugInformationFormat.Embedded, format);

            if (format == 0 || format == DebugInformationFormat.Pdb)
            {
                var actualPdb = GetPdbXml(compilation, debugEntryPoint, options, qualifiedMethodName, portable: false);
                var(actualXml, expectedXml) = AdjustToPdbFormat(actualPdb, expectedPdb, actualIsPortable: false);

                AssertXml.Equal(expectedXml, actualXml, $"PDB format: Windows{Environment.NewLine}", expectedValueSourcePath, expectedValueSourceLine, expectedIsXmlLiteral);
            }

            if (format == 0 || format == DebugInformationFormat.PortablePdb)
            {
                string actualPdb = GetPdbXml(compilation, debugEntryPoint, options, qualifiedMethodName, portable: true);
                var(actualXml, expectedXml) = AdjustToPdbFormat(actualPdb, expectedPdb, actualIsPortable: true);

                AssertXml.Equal(expectedXml, actualXml, $"PDB format: Portable{Environment.NewLine}", expectedValueSourcePath, expectedValueSourceLine, expectedIsXmlLiteral);
            }
        }
예제 #4
0
        public void AngleXml(string vs, string xml)
        {
            var angle  = Angle.Parse(vs);
            var result = AssertXml.XmlSerializerRoundTrip(angle, xml);

            Assert.AreEqual(angle.Radians, result.Radians, Tolerance);
        }
예제 #5
0
        public void PlaneXml(string rootPoint, string unitVector, string xml)
        {
            var plane  = new Plane(Point3D.Parse(rootPoint), UnitVector3D.Parse(unitVector));
            var result = AssertXml.XmlSerializerRoundTrip(plane, xml);

            Assert.AreEqual(plane, result);
        }
예제 #6
0
        public void XmlRoundtrip()
        {
            var p   = new Point3D(1, -2, 3);
            var xml = @"<Point3D X=""1"" Y=""-2"" Z=""3"" />";

            AssertXml.XmlRoundTrips(p, xml, (expected, actual) => AssertGeometry.AreEqual(expected, actual));
        }
예제 #7
0
        private static void VerifyPdbImpl(
            this Compilation compilation,
            IMethodSymbol debugEntryPoint,
            string qualifiedMethodName,
            XElement expectedPdb,
            DebugInformationFormat format,
            PdbToXmlOptions options,
            int expectedValueSourceLine,
            string expectedValueSourcePath,
            bool expectedIsXmlLiteral)
        {
            Assert.NotEqual(DebugInformationFormat.Embedded, format);

            if (format == 0 || format == DebugInformationFormat.Pdb)
            {
                var actualNativePdb = XElement.Parse(GetPdbXml(compilation, debugEntryPoint, options, qualifiedMethodName, portable: false));
                AssertXml.Equal(expectedPdb, actualNativePdb, expectedValueSourcePath, expectedValueSourceLine, expectedIsXmlLiteral);
            }

            if (format == 0 || format == DebugInformationFormat.PortablePdb)
            {
                var actualPortablePdb = XElement.Parse(GetPdbXml(compilation, debugEntryPoint, options, qualifiedMethodName, portable: true));

                // If format is not specified, we share expected output between portable and non-portable.
                // The output is then non-portable since it contains more information (such as cdi).
                AdjustToPdbFormat(
                    actualPdb: actualPortablePdb,
                    actualIsPortable: true,
                    expectedPdb: expectedPdb,
                    expectedIsPortable: format == DebugInformationFormat.PortablePdb);

                AssertXml.Equal(expectedPdb, actualPortablePdb, expectedValueSourcePath, expectedValueSourceLine, expectedIsXmlLiteral);
            }
        }
예제 #8
0
        public void Circle2DXml(string point, double radius, string xml)
        {
            var center = Point2D.Parse(point);
            var c      = new Circle2D(center, radius);
            var result = AssertXml.XmlSerializerRoundTrip(c, xml);

            Assert.AreEqual(c, result);
        }
예제 #9
0
        public void Vector3DXml()
        {
            var          v      = new Vector3D(1, -2, 3);
            const string Xml    = @"<Vector3D X=""1"" Y=""-2"" Z=""3"" />";
            var          result = AssertXml.XmlSerializerRoundTrip(v, Xml);

            Assert.AreEqual(v, result);
        }
예제 #10
0
        public void QuaternionXml()
        {
            var          q      = new Quaternion(1, 2, 3, 4);
            const string Xml    = @"<Quaternion W=""1"" X=""2"" Y=""3"" Z=""4"" />";
            var          result = AssertXml.XmlSerializerRoundTrip(q, Xml);

            Assert.AreEqual(q, result);
        }
예제 #11
0
        public void Point2DXml()
        {
            var          p      = new Point2D(1, 2);
            const string Xml    = @"<Point2D X=""1"" Y=""2"" />";
            var          result = AssertXml.XmlSerializerRoundTrip(p, Xml);

            Assert.AreEqual(p, result);
        }
예제 #12
0
        public void Ray3DXml(string ps, string vs, bool asElements, string xml)
        {
            var ray    = new Ray3D(Point3D.Parse(ps), UnitVector3D.Parse(vs));
            var result = AssertXml.XmlSerializerRoundTrip(ray, xml);

            Assert.AreEqual(ray, result);
            AssertGeometry.AreEqual(ray, result, Tolerance);
        }
예제 #13
0
        public void XmlTests(string p1s, string p2s, string xml)
        {
            Point3D p1 = Point3D.Parse(p1s);
            Point3D p2 = Point3D.Parse(p2s);
            var     l  = new Line3D(p1, p2);

            AssertXml.XmlRoundTrips(l, xml, (e, a) => AssertGeometry.AreEqual(e, a));
        }
예제 #14
0
        public void LineSegement2DXml(string p1s, string p2s, string xml)
        {
            Point2D p1     = Point2D.Parse(p1s);
            Point2D p2     = Point2D.Parse(p2s);
            var     l      = new LineSegment2D(p1, p2);
            var     result = AssertXml.XmlSerializerRoundTrip(l, xml);

            Assert.AreEqual(l, result);
        }
예제 #15
0
        public void EulerAnglesXml()
        {
            var          q           = new Quaternion(0, 0, 0, 0);
            var          eulerAngles = q.ToEulerAngles();
            const string Xml         = @"<EulerAngles><Alpha Value=""0""></Alpha><Beta Value=""0""></Beta><Gamma Value=""0""></Gamma></EulerAngles>";
            var          result      = AssertXml.XmlSerializerRoundTrip(eulerAngles, Xml);

            Assert.AreEqual(eulerAngles, result);
        }
예제 #16
0
        public void PolyLine3DXml()
        {
            var          points = "0, -1.5, 0; 0,1,0; 1,1,0";
            var          p      = new PolyLine3D(from x in points.Split(';') select Point3D.Parse(x));
            const string Xml    = @"<PolyLine3D><Points><Point X=""0.25"" Y=""0"" /><Point X=""0.5"" Y=""1"" /><Point X=""1"" Y=""-1"" /></Points></PolyLine3D>";
            var          result = AssertXml.XmlSerializerRoundTrip(p, Xml);

            Assert.AreEqual(p, result);
        }
        public void XmlRoundTrips(string vs, string xml)
        {
            var angle = Angle.Parse(vs);

            AssertXml.XmlRoundTrips(angle, xml, (e, a) =>
            {
                Assert.AreEqual(e.Radians, a.Radians, Tolerance);
            });
        }
예제 #18
0
        public void PolyLine2DXml()
        {
            var points = from x in new string[] { "0.25,0", "0.5,1", "1,-1" } select Point2D.Parse(x);

            var          p      = new PolyLine2D(points);
            const string Xml    = @"<PolyLine2D><Points><Point X=""0.25"" Y=""0"" /><Point X=""0.5"" Y=""1"" /><Point X=""1"" Y=""-1"" /></Points></PolyLine2D>";
            var          result = AssertXml.XmlSerializerRoundTrip(p, Xml);

            Assert.AreEqual(p, result);
        }
예제 #19
0
        public void VerifyPdb(
            IEnumerable <int> methodTokens,
            XElement expectedPdb,
            [CallerLineNumber] int expectedValueSourceLine  = 0,
            [CallerFilePath] string expectedValueSourcePath = null)
        {
            string actualPdb = PdbToXmlConverter.DeltaPdbToXml(PdbDelta, methodTokens);

            AssertXml.Equal(expectedPdb, XElement.Parse(actualPdb), expectedValueSourcePath, expectedValueSourceLine, expectedIsXmlLiteral: true);
        }
        public void WhenWriteWithOneSuperPerson_ThenWritesXml()
        {
            // Arrange
            List <SuperPerson> superPeople = new List <SuperPerson>()
            {
                new SuperPerson()
                {
                    Id         = 1,
                    Name       = "Superman",
                    Allegiance = TeamNames.SuperFriends,
                    Rank       = 1,
                    Health     = 1000,
                    Strength   = 10,
                    Resistance = 80,
                    Intellect  = 20,
                    Speed      = 60
                },
            };

            // Note: Example of using complex XML string with TestDataLoader for expected
            // Note: Would skip in favor of TestDataLoader

            string expected =
                "<SuperPeople>" +
                "<SuperPerson Id='1' Name='Superman' Allegiance='Super Friends' Rank='1' Health='1000' Strength='10' Speed='60' Resistance='80' Intellect='20'></SuperPerson>" +
                "</SuperPeople>";


            SuperXmlSerializer target = new SuperXmlSerializer();

            XmlWriterSettings writerSettings = new XmlWriterSettings();

            writerSettings.CloseOutput        = false;
            writerSettings.Encoding           = System.Text.Encoding.UTF8;
            writerSettings.Indent             = false;
            writerSettings.OmitXmlDeclaration = false;

            // Act
            string actual;

            using (StringWriter stringWriter = new StringWriter())
            {
                using (XmlWriter writer = XmlWriter.Create(stringWriter, writerSettings))
                {
                    target.Write(writer, superPeople);
                    writer.Flush();
                    stringWriter.Flush();

                    actual = stringWriter.ToString();
                }
            }

            // Assert
            AssertXml.AreEqual(expected, actual);
        }
예제 #21
0
        internal static void VerifyPdb(
            this Compilation compilation,
            string qualifiedMethodName,
            string expectedPdb,
            [CallerLineNumber] int expectedValueSourceLine  = 0,
            [CallerFilePath] string expectedValueSourcePath = null)
        {
            string actualPdb = GetPdbXml(compilation, qualifiedMethodName);

            AssertXml.Equal(ParseExpectedPdbXml(expectedPdb), XElement.Parse(actualPdb), expectedValueSourcePath, expectedValueSourceLine, expectedIsXmlLiteral: false);
        }
        public void XmlRoundTrips()
        {
            var          cs       = new CoordinateSystem(new Point3D(1, -2, 3), new Vector3D(0, 1, 0), new Vector3D(0, 0, 1), new Vector3D(1, 0, 0));
            const string expected = @"
<CoordinateSystem>
    <Origin X=""1"" Y=""-2"" Z=""3"" />
    <XAxis X=""0"" Y=""1"" Z=""0"" />
    <YAxis X=""0"" Y=""0"" Z=""1"" />
    <ZAxis X=""1"" Y=""0"" Z=""0"" />
</CoordinateSystem>";

            AssertXml.XmlRoundTrips(cs, expected, (e, a) => AssertGeometry.AreEqual(e, a));
        }
예제 #23
0
        public void CoordinateSystemXml()
        {
            var    cs     = new CoordinateSystem(new Point3D(1, -2, 3), new Vector3D(0, 1, 0), new Vector3D(0, 0, 1), new Vector3D(1, 0, 0));
            string xml    = @"
<CoordinateSystem>
    <Origin X=""1"" Y=""-2"" Z=""3"" />
    <XAxis X=""0"" Y=""1"" Z=""0"" />
    <YAxis X=""0"" Y=""0"" Z=""1"" />
    <ZAxis X=""1"" Y=""0"" Z=""0"" />
</CoordinateSystem>";
            var    result = AssertXml.XmlSerializerRoundTrip(cs, xml);

            AssertGeometry.AreEqual(cs, result);
        }
        public void WhenReadAndWrite_ThenRoundtripsXml()
        {
            // Arrange
            string inputXml = TestDataLoader.LoadText("TestData.SuperPeople.Valid.xml");
            string expected = inputXml;

            SuperXmlSerializer target = new SuperXmlSerializer();

            XmlReaderSettings settings = new XmlReaderSettings();

            settings.CloseInput       = false;
            settings.IgnoreWhitespace = true;
            settings.IgnoreComments   = true;

            XmlWriterSettings writerSettings = new XmlWriterSettings();

            writerSettings.CloseOutput        = false;
            writerSettings.Encoding           = System.Text.Encoding.UTF8;
            writerSettings.Indent             = false;
            writerSettings.OmitXmlDeclaration = false;

            // Act
            IEnumerable <SuperPerson> superPeople;

            using (StringReader stringReader = new StringReader(inputXml))
            {
                using (XmlReader reader = XmlReader.Create(stringReader, settings))
                {
                    superPeople = target.Read(reader);
                }
            }

            string actual;

            using (StringWriter stringWriter = new StringWriter())
            {
                using (XmlWriter writer = XmlWriter.Create(stringWriter, writerSettings))
                {
                    target.Write(writer, superPeople);
                    writer.Flush();
                    stringWriter.Flush();

                    actual = stringWriter.ToString();
                }
            }

            // Assert
            AssertXml.AreEqual(expected, actual);
        }
예제 #25
0
        public void Bug693206()
        {
            #region "Source"
            var text =
                @"
namespace X
{ 
	class DynamicMembers
	{
        enum HRESULT : int
        {
            S_OK = 0x0000,
            S_FALSE = 0x0001,
            S_PT_NO_CONFLICT = 0x40001,
            E_INVALID_DATA = unchecked((int)0x8007000D),
            E_INVALIDARG = unchecked((int)0x80070057),
            E_OUTOFMEMORY = unchecked((int)0x8007000E),
            ERROR_NOT_FOUND = unchecked((int)0x80070490)
        }
    }
}";
            #endregion

            string expected =
                @"<?xml version=""1.0"" encoding=""utf-16""?>
<token-map>
  <token-location token=""0x02xxxxxx"" file=""source.cs"" start-line=""4"" start-column=""8"" end-line=""4"" end-column=""22"" />
  <token-location token=""0x06xxxxxx"" file=""source.cs"" start-line=""4"" start-column=""8"" end-line=""4"" end-column=""22"" />
  <token-location token=""0x02xxxxxx"" file=""source.cs"" start-line=""6"" start-column=""14"" end-line=""6"" end-column=""21"" />
  <token-location token=""0x04xxxxxx"" file=""source.cs"" start-line=""8"" start-column=""13"" end-line=""8"" end-column=""17"" />
  <token-location token=""0x04xxxxxx"" file=""source.cs"" start-line=""9"" start-column=""13"" end-line=""9"" end-column=""20"" />
  <token-location token=""0x04xxxxxx"" file=""source.cs"" start-line=""10"" start-column=""13"" end-line=""10"" end-column=""29"" />
  <token-location token=""0x04xxxxxx"" file=""source.cs"" start-line=""11"" start-column=""13"" end-line=""11"" end-column=""27"" />
  <token-location token=""0x04xxxxxx"" file=""source.cs"" start-line=""12"" start-column=""13"" end-line=""12"" end-column=""25"" />
  <token-location token=""0x04xxxxxx"" file=""source.cs"" start-line=""13"" start-column=""13"" end-line=""13"" end-column=""26"" />
  <token-location token=""0x04xxxxxx"" file=""source.cs"" start-line=""14"" start-column=""13"" end-line=""14"" end-column=""28"" />
</token-map>";

            var compilation = CreateCompilationWithMscorlib45(
                text,
                options: TestOptions.ReleaseWinMD,
                sourceFileName: "source.cs"
                )
                              .VerifyDiagnostics();

            string actual = PdbTestUtilities.GetTokenToLocationMap(compilation, true);
            AssertXml.Equal(expected, actual);
        }
        public void XmlContainerRoundtrip()
        {
            var container = new AssertXml.Container <UnitVector3D>
            {
                Value1 = UnitVector3D.Create(0.2672612419124244, -0.53452248382484879, 0.80178372573727319),
                Value2 = UnitVector3D.Create(1, 0, 0)
            };
            var expected = "<ContainerOfUnitVector3D>\r\n" +
                           "  <Value1 X=\"0.2672612419124244\" Y=\"-0.53452248382484879\" Z=\"0.80178372573727319\"></Value1>\r\n" +
                           "  <Value2 X=\"1\" Y=\"0\" Z=\"0\"></Value2>\r\n" +
                           "</ContainerOfUnitVector3D>";
            var roundTrip = AssertXml.XmlSerializerRoundTrip(container, expected);

            AssertGeometry.AreEqual(container.Value1, roundTrip.Value1);
            AssertGeometry.AreEqual(container.Value2, roundTrip.Value2);
        }
        public void XmlContainerRoundtrip()
        {
            var container = new AssertXml.Container <Vector2D>
            {
                Value1 = new Vector2D(1, 2),
                Value2 = new Vector2D(3, 4)
            };
            var expected = "<ContainerOfVector2D>\r\n" +
                           "  <Value1 X=\"1\" Y=\"2\"></Value1>\r\n" +
                           "  <Value2 X=\"3\" Y=\"4\"></Value2>\r\n" +
                           "</ContainerOfVector2D>";
            var roundTrip = AssertXml.XmlSerializerRoundTrip(container, expected);

            AssertGeometry.AreEqual(container.Value1, roundTrip.Value1);
            AssertGeometry.AreEqual(container.Value2, roundTrip.Value2);
        }
예제 #28
0
        public void XmlContainerRoundtrip()
        {
            var container = new AssertXml.Container <Point3D>
            {
                Value1 = new Point3D(1, 2, 3),
                Value2 = new Point3D(4, 5, 6)
            };
            var expected = "<ContainerOfPoint3D>\r\n" +
                           "  <Value1 X=\"1\" Y=\"2\" Z=\"3\"></Value1>\r\n" +
                           "  <Value2 X=\"4\" Y=\"5\" Z=\"6\"></Value2>\r\n" +
                           "</ContainerOfPoint3D>";
            var roundTrip = AssertXml.XmlSerializerRoundTrip(container, expected);

            AssertGeometry.AreEqual(container.Value1, roundTrip.Value1);
            AssertGeometry.AreEqual(container.Value2, roundTrip.Value2);
        }
예제 #29
0
        public void XmlContainerRoundtrip()
        {
            var container = new AssertXml.Container <Angle>
            {
                Value1 = Angle.FromRadians(1),
                Value2 = Angle.FromRadians(2),
            };
            var expected = "<ContainerOfAngle>\r\n" +
                           "  <Value1 Value=\"1\"></Value1>\r\n" +
                           "  <Value2 Value=\"2\"></Value2>\r\n" +
                           "</ContainerOfAngle>";
            var roundTrip = AssertXml.XmlSerializerRoundTrip(container, expected);

            Assert.AreEqual(container.Value1, roundTrip.Value1);
            Assert.AreEqual(container.Value2, roundTrip.Value2);
        }
예제 #30
0
        public void XmlTest(string vs, string xml)
        {
            var angle = Angle.Parse(vs);

            AssertXml.XmlRoundTrips(angle, xml, (e, a) =>
            {
                Assert.AreEqual(e.Radians, a.Radians, Tolerance);
                Assert.IsInstanceOf <Angle>(a);
            });
            var serializer = new XmlSerializer(typeof(Angle));

            using (var reader = new StringReader(@"<Angle><Value>0.261799387799149</Value></Angle>"))
            {
                var fromElements = (Angle)serializer.Deserialize(reader);
                Assert.AreEqual(angle.Radians, fromElements.Radians, 1e-6);
            }
        }