public void TestReportingFpMLSamplesLoadAllValid() { //string fileSpec = "rpt-ex20-matured-and-expired-trades.xml"; string fileSpec = "*.xml"; TimeSpan localTimeOffset = DateTimeOffset.Now.Offset; Assert.AreEqual(TimeSpan.FromHours(10), localTimeOffset);//11 var transformIncoming = new CustomXmlTransformer(FpMLViewHelpers.GetIncomingConversionMap(), OutputDateTimeKind.UnspecifiedOrLocal, null); var transformOutgoing = new CustomXmlTransformer(FpMLViewHelpers.GetOutgoingConversionMap(), OutputDateTimeKind.UnspecifiedOrCustom, TimeSpan.FromHours(-5)); var schemaSet = FpMLViewHelpers.GetSchemaSet(); var results = TestHelper.LoadFiles( FPMLViewName, schemaSet, FpMLViewHelpers.AutoDetectType, fileSpec, transformIncoming, transformOutgoing, false, false, false); Assert.AreEqual(178, results.FilesProcessed.Count); Assert.AreEqual(3, results.DeserialisationErrors.Count);//TODO should be 0 Assert.AreEqual(0, results.OrigValidationWarnings.Count); Assert.AreEqual(0, results.OrigValidationErrors.Count); Assert.AreEqual(0, results.IncomingTransformErrors.Count); }
private void BtnRunTestsClick(object sender, EventArgs e) { txtLog.Clear(); _Abort = false; LogInfo("Tests starting..."); var schemaSet = FpMLViewHelpers.GetSchemaSet(); // init paths string externalPath = txtWorkPath.Text + @"\External.xml"; string importedPath = txtWorkPath.Text + @"\Imported.xml"; string internalPath = txtWorkPath.Text + @"\Internal.xml"; string exportedPath = txtWorkPath.Text + @"\Exported.xml"; IXmlTransformer importTransformer = new CustomXmlTransformer(FpMLViewHelpers.GetIncomingConversionMap()); IXmlTransformer exportTransformer = new CustomXmlTransformer(FpMLViewHelpers.GetOutgoingConversionMap()); // test loop foreach (var item in clbTests.CheckedItems) { if (_Abort) { break; } string checkedTest = item.ToString(); int p1 = checkedTest.IndexOf('['); int p2 = checkedTest.IndexOf(']'); string testId = checkedTest.Substring(p1 + 1, (p2 - p1 - 1)); string testTitle = checkedTest.Substring(0, p1 - 1); LogInfo(testTitle + " ...", testId); var errorCounter = new Counter(); var warningCounter = new Counter(); try { switch (testId) { case "FMTEXT": TestHelper.FormatXml(this, testId, txtSourcePath.Text, externalPath, errorCounter); ShowXml(externalPath, txtExternalXml); break; case "VALEXT": TestHelper.ValidateXml(this, testId, externalPath, schemaSet, errorCounter, warningCounter); break; case "IMPORT": TestHelper.TransformXml(this, testId, importTransformer, externalPath, importedPath, errorCounter); ShowXml(importedPath, txtImportedXml); break; case "DESIMP": _FpMLObject = TestHelper.DeserialiseXml(this, testId, FpMLViewHelpers.AutoDetectType, importedPath, errorCounter); break; case "SERIAL": TestHelper.SerialiseXml(this, testId, _FpMLObject, internalPath, errorCounter); ShowXml(internalPath, txtInternalXml); break; case "CMPINT": TestHelper.CompareXml(this, testId, importedPath, internalPath, errorCounter); break; case "EXPORT": TestHelper.TransformXml(this, testId, exportTransformer, internalPath, exportedPath, errorCounter); ShowXml(exportedPath, txtExportedXml); break; case "VALEXP": TestHelper.ValidateXml(this, testId, exportedPath, schemaSet, errorCounter, warningCounter); break; case "CMPEXT": TestHelper.CompareXml(this, testId, txtSourcePath.Text, exportedPath, errorCounter); break; // internal case "FMTINT": TestHelper.FormatXml(this, testId, txtSourcePath.Text, importedPath, errorCounter); ShowXml(importedPath, txtImportedXml); break; case "CMPIIS": TestHelper.CompareXml(this, testId, txtSourcePath.Text, importedPath, errorCounter); break; default: throw new NotImplementedException("This test has not not implemented!"); } } catch (System.Exception excp) { errorCounter.Inc(); LogException(excp, testId, true); } if (errorCounter.Count > 0) { LogError(String.Format(" Test FAILED with {0} errors, {1} warnings.", errorCounter.Count, warningCounter.Count), testId, true); } else { LogInfo(String.Format(" Test PASSED with {0} warnings.", warningCounter.Count), testId); } } Log(_Abort ? "Tests aborted!" : "Tests completed."); }
private T Roundtrip_OutThenIn <T>(T input, bool compare, bool validate) { string originalPath = Path.GetFullPath(@"..\..\step0original.xml"); string internalPath = Path.GetFullPath(@"..\..\step1external.xml"); string externalPath = Path.GetFullPath(@"..\..\step2internal.xml"); IXmlTransformer transformIncoming = new CustomXmlTransformer(FpMLViewHelpers.GetIncomingConversionMap()); IXmlTransformer transformOutgoing = new CustomXmlTransformer(FpMLViewHelpers.GetOutgoingConversionMap()); // emit original internal var xs = new XmlSerializer(typeof(T)); using (var fs = new FileStream(originalPath, FileMode.Create, FileAccess.Write)) { xs.Serialize(fs, input); } // transform to external format transformOutgoing.Transform(originalPath, externalPath); // transform to internal format transformIncoming.Transform(externalPath, internalPath); if (compare) { // compare // load original into xml doc var docA = new XmlDocument(); using (var fs = new FileStream(originalPath, FileMode.Open, FileAccess.Read)) //using (var sr = new StreamReader(fs, Encoding.UTF8)) { docA.Load(fs); } // load emitted stream into xml doc var docB = new XmlDocument(); using (var fs = new FileStream(internalPath, FileMode.Open, FileAccess.Read)) { docB.Load(fs); } // compare XmlCompare.CompareXmlDocs(docA, docB); } // validate external if (validate) { const string schemaPath = @"..\..\..\..\..\Metadata\FpML.V5r3\FpML.V5r3\" + fpmlViewName + ".xsd"; string schemaFullPath = Path.GetFullPath(schemaPath); Assert.IsTrue(File.Exists(schemaFullPath)); // validate external xml int validationEvents = 0; var externalDoc = new XmlDocument(); externalDoc.Schemas.Add(null, "file://" + schemaFullPath); externalDoc.Load(externalPath); externalDoc.Validate((o, e) => { validationEvents++; System.Diagnostics.Debug.Print("Validation event: {0}", e.Message); }); Assert.AreEqual(0, validationEvents); } // deserialise using (TextReader tr = new StreamReader(internalPath)) { return((T)xs.Deserialize(tr)); } }
public void TestReportingRoundtripDateTimes() { const string schemaPath = @"..\..\..\..\..\Metadata\FpML.V5r10\FpML.V5r10.Reporting\MergedReportingSchemas\Reporting.xsd"; string schemaFullPath = Path.GetFullPath(schemaPath); Assert.IsTrue(File.Exists(schemaFullPath)); string originalFullPath = Path.GetFullPath(@"..\..\testOriginalFragment.xml"); string internalFullPath = Path.GetFullPath(@"..\..\testInternalFragment.xml"); string outgoingFullPath = Path.GetFullPath(@"..\..\testOutgoingFragment.xml"); string externalFullPath = Path.GetFullPath(@"..\..\testExternalFragment.xml"); IXmlTransformer transformIncoming = new CustomXmlTransformer(FpMLViewHelpers.GetIncomingConversionMap(), OutputDateTimeKind.UnspecifiedOrUniversal, null); IXmlTransformer transformOutgoing = new CustomXmlTransformer(FpMLViewHelpers.GetOutgoingConversionMap(), OutputDateTimeKind.UnspecifiedOrCustom, TimeSpan.FromHours(-5)); XmlSerializer xs = new XmlSerializer(typeof(ExposureReport)); // original FpML.org sample string originalFpMLText = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<exposureReport" + " xmlns=\"http://www.fpml.org/FpML-5/reporting\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + " fpmlVersion=\"5-10\" >" + " <asOfDate>2010-09-27</asOfDate>" + " <asOfTime>20:08:10-05:00</asOfTime>" + "</exposureReport>"; using (var sw = new StreamWriter(originalFullPath)) { sw.WriteLine(originalFpMLText); } DateTime expectedAsOfDate = new DateTime(2010, 9, 27, 0, 0, 0); DateTime expectedAsOfTime = new DateTime(1, 1, 1, 1, 8, 10);//11 became 12 { // original FpML.org sample // --- does not parse reliably due to variably local time zone offset of parser --- // asOfDate has an unspecified time zone // asOfTime has specific time zone (New York) ExposureReport orig; using (StringReader sr = new StringReader(originalFpMLText)) { orig = (ExposureReport)xs.Deserialize(sr); } Assert.AreEqual(DateTimeKind.Unspecified, orig.asOfDate.Value.Kind); Assert.IsTrue(orig.asOfTimeSpecified); Assert.AreEqual(DateTimeKind.Local, orig.asOfTime.Kind); // --- this test does not pass reliably due to variable local time zone offset of parser --- DateTime asOfDate = new DateTime(2010, 9, 27); Assert.AreEqual(asOfDate, orig.asOfDate.Value); DateTime asOfTime = new DateTime(1, 1, 2, 11, 8, 10);//TODO the time changed due to daylight saving??Why? Assert.AreEqual(asOfTime, orig.asOfTime); } { // modified FpML.org sample // --- this test does not pass reliably due to variable local time zone offset of parser --- // - asOfDate time zone modified to match asOfTime string externalXmlText = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<exposureReport" + " xmlns=\"http://www.fpml.org/FpML-5/reporting\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + " fpmlVersion=\"5-10\" >" + " <asOfDate>2010-09-27-5:00</asOfDate>" + " <asOfTime>20:08:10-05:00</asOfTime>" + "</exposureReport>"; ExposureReport orig; using (StringReader sr = new StringReader(externalXmlText)) { orig = (ExposureReport)xs.Deserialize(sr); } Assert.AreEqual(DateTimeKind.Local, orig.asOfDate.Value.Kind); Assert.IsTrue(orig.asOfTimeSpecified); Assert.AreEqual(DateTimeKind.Local, orig.asOfTime.Kind); // --- this test does not pass reliably due to variable local time zone offset of parser --- DateTime asOfDate = new DateTime(2010, 9, 27, 15, 0, 0); // Australia EST is +10:00 Assert.AreEqual(asOfDate, orig.asOfDate.Value); DateTime asOfTime = new DateTime(1, 1, 2, 11, 8, 10); //11 became 12 Assert.AreEqual(asOfTime, orig.asOfTime); } { // modified FpML.org sample // - asOfDate and asOfTime set to UTC string externalXmlText = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<exposureReport" + " xmlns=\"http://www.fpml.org/FpML-5/reporting\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + " fpmlVersion=\"5-10\" >" + " <asOfDate>2010-09-27Z</asOfDate>" + " <asOfTime>20:08:10Z</asOfTime>" + "</exposureReport>"; ExposureReport orig; using (StringReader sr = new StringReader(externalXmlText)) { orig = (ExposureReport)xs.Deserialize(sr); } Assert.AreEqual(DateTimeKind.Local, orig.asOfDate.Value.Kind); Assert.IsTrue(orig.asOfTimeSpecified); Assert.AreEqual(DateTimeKind.Utc, orig.asOfTime.Kind); //Local // --- this test does not pass reliably due to variable local time zone offset of parser --- DateTime asOfDate = new DateTime(2010, 9, 27, 10, 0, 0); // Australia EST is +10:00 Assert.AreEqual(asOfDate, orig.asOfDate.Value); DateTime asOfTime = new DateTime(1, 1, 1, 20, 8, 10); //6 became 7 Assert.AreEqual(asOfTime, orig.asOfTime); } { // modified FpML.org sample // --- passes reliably because local time zone offset of parser is ignored --- // - asOfDate and asOfTime set to unspecified time zone string externalXmlText = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<exposureReport" + " xmlns=\"http://www.fpml.org/FpML-5/reporting\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + " fpmlVersion=\"5-10\" >" + " <asOfDate>2010-09-27</asOfDate>" + " <asOfTime>20:08:10</asOfTime>" + "</exposureReport>"; ExposureReport orig; using (StringReader sr = new StringReader(externalXmlText)) { orig = (ExposureReport)xs.Deserialize(sr); } Assert.AreEqual(DateTimeKind.Unspecified, orig.asOfDate.Value.Kind); Assert.IsTrue(orig.asOfTimeSpecified); Assert.AreEqual(DateTimeKind.Unspecified, orig.asOfTime.Kind); Assert.AreEqual(new DateTime(2010, 9, 27, 0, 0, 0), orig.asOfDate.Value); Assert.AreEqual(new DateTime(1, 1, 1, 20, 8, 10), orig.asOfTime); } // now that we have a reliably formatted external fpml fragment we can test the roundtrip // transform to internal format transformIncoming.Transform(originalFullPath, internalFullPath); // deserialise ExposureReport fpml; using (var sr = new FileStream(internalFullPath, FileMode.Open, FileAccess.Read)) { fpml = (ExposureReport)xs.Deserialize(sr); } Assert.AreEqual(DateTimeKind.Unspecified, fpml.asOfDate.Value.Kind); Assert.IsTrue(fpml.asOfTimeSpecified); Assert.AreEqual(DateTimeKind.Utc, fpml.asOfTime.Kind);//Local Assert.AreEqual(expectedAsOfDate, fpml.asOfDate.Value); Assert.AreEqual(expectedAsOfTime, fpml.asOfTime); // emit test fragment using (var fs = new FileStream(outgoingFullPath, FileMode.Create, FileAccess.Write)) { xs.Serialize(fs, fpml); } // transform to external format transformOutgoing.Transform(outgoingFullPath, externalFullPath); // compare external xml using (var originalStream = new FileStream(originalFullPath, FileMode.Open, FileAccess.Read)) using (var externalStream = new FileStream(externalFullPath, FileMode.Open, FileAccess.Read)) { XmlDocument originalDoc = new XmlDocument(); originalDoc.Load(originalStream); XmlDocument emittedDoc = new XmlDocument(); emittedDoc.Load(externalStream); // compare XmlCompare.CompareXmlDocs(originalDoc, emittedDoc); } }