PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 8ms RepoModel.GetById 32ms app.codeStats 0ms

/Main/Testing/Rxx.UnitTests/Reactive/TraceTests - System.Diagnostics.Trace.cs

#
C# | 156 lines | 106 code | 50 blank | 0 comment | 0 complexity | 9a2185bf614ef78b02d76c541adeb1cb MD5 | raw file
  1using System;
  2using System.Linq;
  3using System.Reactive.Linq;
  4using Microsoft.VisualStudio.TestTools.UnitTesting;
  5
  6namespace Rxx.UnitTests.Reactive
  7{
  8	[TestClass]
  9	public partial class TraceTests : RxxTraceTests
 10	{
 11		[TestMethod]
 12		public void RxTrace()
 13		{
 14			AddTraceListener();
 15
 16			var xs = Observable.Range(0, 5);
 17
 18			xs.Trace().Subscribe();
 19
 20			AssertEqual(Listener.Messages, Concat(
 21				Enumerable.Range(0, 5).Select(value => TraceDefaults.DefaultOnNext(value)),
 22				TraceDefaults.DefaultOnCompleted()));
 23
 24			RemoveTraceListener();
 25		}
 26
 27		[TestMethod]
 28		public void RxTraceOnNext()
 29		{
 30			AddTraceListener();
 31
 32			var xs = Observable.Range(0, 5);
 33
 34			xs.TraceOnNext().Subscribe();
 35
 36			AssertEqual(Listener.Messages, Enumerable.Range(0, 5).Select(value => TraceDefaults.DefaultOnNext(value)));
 37
 38			RemoveTraceListener();
 39		}
 40
 41		[TestMethod]
 42		public void RxTraceOnNextFormat()
 43		{
 44			AddTraceListener();
 45
 46			var xs = Observable.Range(0, 5);
 47
 48			xs.TraceOnNext("OnNext: {0}").Subscribe();
 49
 50			AssertEqual(Listener.Messages, Enumerable.Range(0, 5).Select(value => "OnNext: " + value));
 51
 52			RemoveTraceListener();
 53		}
 54
 55		[TestMethod]
 56		public void RxTraceOnNextLazyMessage()
 57		{
 58			AddTraceListener();
 59
 60			var xs = Observable.Range(0, 5);
 61
 62			xs.TraceOnNext(value => "OnNext: " + value).Subscribe();
 63
 64			AssertEqual(Listener.Messages, Enumerable.Range(0, 5).Select(value => "OnNext: " + value));
 65
 66			RemoveTraceListener();
 67		}
 68
 69		[TestMethod]
 70		public void RxTraceOnError()
 71		{
 72			AddTraceListener();
 73
 74			var ex = new Exception("Error");
 75			var xs = Observable.Throw<int>(ex);
 76
 77			xs.TraceOnError().Subscribe(_ => { }, __ => { });
 78
 79			AssertEqual(Listener.Messages, TraceDefaults.DefaultOnError(ex));
 80
 81			RemoveTraceListener();
 82		}
 83
 84		[TestMethod]
 85		public void RxTraceOnErrorFormat()
 86		{
 87			AddTraceListener();
 88
 89			var ex = new Exception("Error");
 90			var xs = Observable.Throw<int>(ex);
 91
 92			xs.TraceOnError("OnError: {0}").Subscribe(_ => { }, __ => { });
 93
 94			AssertEqual(Listener.Messages, "OnError: " + ex.ToString());
 95
 96			RemoveTraceListener();
 97		}
 98
 99		[TestMethod]
100		public void RxTraceOnErrorLazyMessage()
101		{
102			AddTraceListener();
103
104			var ex = new Exception("Error");
105			var xs = Observable.Throw<int>(ex);
106
107			xs.TraceOnError(error => "OnError: " + error.Message).Subscribe(_ => { }, __ => { });
108
109			AssertEqual(Listener.Messages, "OnError: " + ex.Message);
110
111			RemoveTraceListener();
112		}
113
114		[TestMethod]
115		public void RxTraceOnCompleted()
116		{
117			AddTraceListener();
118
119			var xs = Observable.Range(0, 5);
120
121			xs.TraceOnCompleted().Subscribe();
122
123			AssertEqual(Listener.Messages, TraceDefaults.DefaultOnCompleted());
124
125			RemoveTraceListener();
126		}
127
128		[TestMethod]
129		public void RxTraceOnCompletedFormat()
130		{
131			AddTraceListener();
132
133			var xs = Observable.Range(0, 5);
134
135			xs.TraceOnCompleted("OnCompleted").Subscribe();
136
137			AssertEqual(Listener.Messages, "OnCompleted");
138
139			RemoveTraceListener();
140		}
141
142		[TestMethod]
143		public void RxTraceOnCompletedLazyMessage()
144		{
145			AddTraceListener();
146
147			var xs = Observable.Range(0, 5);
148
149			xs.TraceOnCompleted(() => "OnCompleted").Subscribe();
150
151			AssertEqual(Listener.Messages, "OnCompleted");
152
153			RemoveTraceListener();
154		}
155	}
156}