// // XmlWriterTraceListenerTest.cs // // Author: // Atsushi Enomoto // // Copyright (C) 2007 Novell, Inc. // // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // #if !MOBILE using NUnit.Framework; using System; using System.IO; using System.Diagnostics; using System.Threading; using System.Xml; namespace MonoTests.System.Diagnostics { [TestFixture] public class XmlWriterTraceListenerTest { string sample1 = @"0308PCsample"; string sample2 = @"4302PC"; string sample3 = @"5302PC"; string sample4 = @"2302PC3302PC"; string sample5 = @"7302PCXYZ7302PCABCDEF"; string sample6 = "030255PChoge"; string sample7 = "0302PCerror summary error details"; [Test] [Ignore ("the test should be rewritten to not compare instance-specific items.")] public void WriteLine1 () { StringWriter sw = new StringWriter (); XmlWriterTraceListener x = new XmlWriterTraceListener (sw); x.WriteLine ("sample"); x.Close (); Assert.AreEqual (sample1.Replace ('\'', '"'), sw.ToString ()); } [Test] [Ignore ("the test should be rewritten to not compare instance-specific items.")] public void TraceEvent1 () { StringWriter sw = new StringWriter (); XmlWriterTraceListener x = new XmlWriterTraceListener (sw); x.TraceEvent (null, null, TraceEventType.Error, 4, null); x.Close (); Assert.AreEqual (sample2.Replace ('\'', '"'), sw.ToString ()); } [Test] [Ignore ("the test should be rewritten to not compare instance-specific items.")] public void TraceEvent2 () { StringWriter sw = new StringWriter (); XmlWriterTraceListener x = new XmlWriterTraceListener (sw); x.TraceEvent (null, "bulldog", TraceEventType.Error, 5); x.Close (); Assert.AreEqual (sample3.Replace ('\'', '"'), sw.ToString ()); } [Test] [Ignore ("the test should be rewritten to not compare instance-specific items.")] public void TraceDataWithCache1 () { StringWriter sw = new StringWriter (); XmlWriterTraceListener x = new XmlWriterTraceListener (sw); TraceEventCache cc = new TraceEventCache (); x.TraceData (cc, null, TraceEventType.Error, 2); x.TraceData (cc, null, TraceEventType.Error, 3); x.Close (); Assert.AreEqual (sample4.Replace ('\'', '"'), sw.ToString ()); } [Test] [Ignore ("the test should be rewritten to not compare instance-specific items.")] public void TraceDataWithCache2 () { StringWriter sw = new StringWriter (); XmlWriterTraceListener x = new XmlWriterTraceListener (sw); TraceEventCache cc = new TraceEventCache (); x.TraceData (cc, null, TraceEventType.Error, 7, "XYZ"); x.TraceData (cc, null, TraceEventType.Error, 7, "ABC", "DEF"); x.Close (); Assert.AreEqual (sample5.Replace ('\'', '"'), sw.ToString ()); } [Test] [Ignore ("the test should be rewritten to not compare instance-specific items.")] public void TraceTransfer1 () { StringWriter sw = new StringWriter (); XmlWriterTraceListener x = new XmlWriterTraceListener (sw); x.TraceTransfer (null, "bulldog", 0, "hoge", Guid.Empty); x.Close (); Assert.AreEqual (sample6.Replace ('\'', '"'), sw.ToString ()); } [Test] [Ignore ("the test should be rewritten to not compare instance-specific items.")] public void Fail1 () { StringWriter sw = new StringWriter (); XmlWriterTraceListener x = new XmlWriterTraceListener (sw); TraceEventCache cc = new TraceEventCache (); x.Fail ("error summary", "error details"); x.Close (); Assert.AreEqual (sample7.Replace ('\'', '"'), sw.ToString ()); } [Test] public void XPathNavigatorAsData () { // While XmlReader, XmlDocument and XDocument are not supported as direct xml content (i.e. to not get escaped), XPathNavigator is. var sw = new StringWriter (); var xl = new XmlWriterTraceListener (sw); var doc = new XmlDocument (); string xml = "text"; doc.LoadXml (xml); xl.TraceData (null, "my source", TraceEventType.Information, 1, doc.CreateNavigator (), doc.CreateNavigator ()); // Note that it does not result in "...". // See XmlWriterTraceListener.TraceCore() for details. Assert.IsTrue (sw.ToString ().IndexOf (xml) > 0, "#1"); Assert.IsTrue (sw.ToString ().IndexOf ("") > 0, "#2"); } } } #endif