2 // DelimitedListTraceListenerTest.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2007 Novell, Inc.
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using NUnit.Framework;
36 using System.Diagnostics;
37 using System.Threading;
39 namespace MonoTests.System.Diagnostics
42 public class DelimitedListTraceListenerTest
44 string sample1 = "sample\n";
46 string sample2 = ";Error;4;;;;;;;;\n";
48 string sample3 = "\"bulldog\";Error;5;;;;;;;;\n\"bulldog\";Error;3;\"test event arg:arg1\";;;;;;;\n";
50 string sample4 = ";Error;2;;;;;;;;\n;Error;3;;;;;;;;\n";
52 string sample5 = ";Error;7;;\"XYZ\";;;;;;\n;Error;7;;\"ABC\",\"DEF\",\"123\";;;;;;\n";
54 string sample6 = "\"my name is \"\"tricky\"\"\";Transfer;0;\"hoge;hoge, relatedActivityId=00000000-0000-0000-0000-000000000000\";;;;;;;\n";
56 string sample7 = "Fail: error summary error details\n";
59 public void WriteLine1 ()
61 StringWriter sw = new StringWriter ();
62 DelimitedListTraceListener x = new DelimitedListTraceListener (sw);
63 x.WriteLine ("sample");
65 Assert.AreEqual (sample1, sw.ToString ().Replace ("\r\n", "\n"));
69 public void TraceEvent1 ()
71 StringWriter sw = new StringWriter ();
72 DelimitedListTraceListener x = new DelimitedListTraceListener (sw);
73 x.TraceEvent (null, null, TraceEventType.Error, 4, null);
75 Assert.AreEqual (sample2, sw.ToString ().Replace ("\r\n", "\n"));
79 public void TraceEvent2 ()
81 StringWriter sw = new StringWriter ();
82 DelimitedListTraceListener x = new DelimitedListTraceListener (sw);
83 x.TraceEvent (null, "bulldog", TraceEventType.Error, 5);
84 x.TraceEvent (null, "bulldog", TraceEventType.Error, 3, "test event arg:{0}", "arg1");
86 Assert.AreEqual (sample3, sw.ToString ().Replace ("\r\n", "\n"));
90 public void TraceDataWithCache1 ()
92 StringWriter sw = new StringWriter ();
93 DelimitedListTraceListener x = new DelimitedListTraceListener (sw);
94 Trace.CorrelationManager.StartLogicalOperation ("op1"); // ... irrelevant?
95 TraceEventCache cc = new TraceEventCache ();
96 x.TraceData (cc, null, TraceEventType.Error, 2);
97 x.TraceData (cc, null, TraceEventType.Error, 3);
98 Trace.CorrelationManager.StopLogicalOperation ();
100 Assert.AreEqual (sample4, sw.ToString ().Replace ("\r\n", "\n"));
104 public void TraceDataWithCache2 ()
106 StringWriter sw = new StringWriter ();
107 DelimitedListTraceListener x = new DelimitedListTraceListener (sw);
108 TraceEventCache cc = new TraceEventCache ();
109 x.TraceData (cc, null, TraceEventType.Error, 7, "XYZ");
110 x.TraceData (cc, null, TraceEventType.Error, 7, "ABC", "DEF", 123);
112 Assert.AreEqual (sample5, sw.ToString ().Replace ("\r\n", "\n"));
116 public void TraceTransfer1 ()
118 StringWriter sw = new StringWriter ();
119 DelimitedListTraceListener x = new DelimitedListTraceListener (sw);
120 x.TraceTransfer (null, "my name is \"tricky\"", 0, "hoge;hoge", Guid.Empty);
122 Assert.AreEqual (sample6, sw.ToString ().Replace ("\r\n", "\n"));
126 [Category ("NotWorking")]
129 StringWriter sw = new StringWriter ();
130 DelimitedListTraceListener x = new DelimitedListTraceListener (sw);
131 TraceEventCache cc = new TraceEventCache ();
132 x.Fail ("error summary", "error details");
134 Assert.AreEqual (sample7, sw.ToString ().Replace ("\r\n", "\n"));