PageRenderTime 83ms CodeModel.GetById 41ms app.highlight 11ms RepoModel.GetById 29ms app.codeStats 0ms

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

#
C# | 226 lines | 156 code | 70 blank | 0 comment | 10 complexity | ebcd7203707299dc0dbc717c5067d83d 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 TraceIdentityTests : RxxTraceTests
 10	{
 11		[TestMethod]
 12		public void RxTraceIdentity()
 13		{
 14			AddTraceListener();
 15
 16			var xs = Observable.Range(0, 5);
 17
 18			for (int i = 0; i < 3; i++)
 19			{
 20				xs.TraceIdentity().Subscribe();
 21
 22				string id = GetCurrentId();
 23
 24				AssertEqual(Listener.Messages, Concat(
 25					Enumerable.Range(0, 5).Select(value => TraceDefaults.DefaultOnNext(id, value)),
 26					TraceDefaults.DefaultOnCompleted(id)));
 27
 28				Listener.Clear();
 29			}
 30
 31			RemoveTraceListener();
 32		}
 33
 34		[TestMethod]
 35		public void RxTraceIdentityOnNext()
 36		{
 37			AddTraceListener();
 38
 39			var xs = Observable.Range(0, 5);
 40
 41			for (int i = 0; i < 3; i++)
 42			{
 43				xs.TraceIdentityOnNext().Subscribe();
 44
 45				string id = GetCurrentId();
 46
 47				AssertEqual(Listener.Messages, Enumerable.Range(0, 5).Select(value => TraceDefaults.DefaultOnNext(id, value)));
 48
 49				Listener.Clear();
 50			}
 51
 52			RemoveTraceListener();
 53		}
 54
 55		[TestMethod]
 56		public void RxTraceIdentityOnNextFormat()
 57		{
 58			AddTraceListener();
 59
 60			var xs = Observable.Range(0, 5);
 61
 62			for (int i = 0; i < 3; i++)
 63			{
 64				xs.TraceIdentityOnNext("OnNext: {0}={1}").Subscribe();
 65
 66				string id = GetCurrentId();
 67
 68				AssertEqual(Listener.Messages, Enumerable.Range(0, 5).Select(value => "OnNext: " + id + "=" + value));
 69
 70				Listener.Clear();
 71			}
 72
 73			RemoveTraceListener();
 74		}
 75
 76		[TestMethod]
 77		public void RxTraceIdentityOnNextLazyMessage()
 78		{
 79			AddTraceListener();
 80
 81			var xs = Observable.Range(0, 5);
 82
 83			for (int i = 0; i < 3; i++)
 84			{
 85				xs.TraceIdentityOnNext((oId, value) => "OnNext: " + oId + "=" + value).Subscribe();
 86
 87				string id = GetCurrentId();
 88
 89				AssertEqual(Listener.Messages, Enumerable.Range(0, 5).Select(value => "OnNext: " + id + "=" + value));
 90
 91				Listener.Clear();
 92			}
 93
 94			RemoveTraceListener();
 95		}
 96
 97		[TestMethod]
 98		public void RxTraceIdentityOnError()
 99		{
100			AddTraceListener();
101
102			var ex = new Exception("Error");
103			var xs = Observable.Throw<int>(ex);
104
105			for (int i = 0; i < 3; i++)
106			{
107				xs.TraceIdentityOnError().Subscribe(_ => { }, __ => { });
108
109				string id = GetCurrentId();
110
111				AssertEqual(Listener.Messages, TraceDefaults.DefaultOnError(id, ex));
112
113				Listener.Clear();
114			}
115
116			RemoveTraceListener();
117		}
118
119		[TestMethod]
120		public void RxTraceIdentityOnErrorFormat()
121		{
122			AddTraceListener();
123
124			var ex = new Exception("Error");
125			var xs = Observable.Throw<int>(ex);
126
127			for (int i = 0; i < 3; i++)
128			{
129				xs.TraceIdentityOnError("OnError: {0}={1}").Subscribe(_ => { }, __ => { });
130
131				string id = GetCurrentId();
132
133				AssertEqual(Listener.Messages, "OnError: " + id + "=" + ex.ToString());
134
135				Listener.Clear();
136			}
137
138			RemoveTraceListener();
139		}
140
141		[TestMethod]
142		public void RxTraceIdentityOnErrorLazyMessage()
143		{
144			AddTraceListener();
145
146			var ex = new Exception("Error");
147			var xs = Observable.Throw<int>(ex);
148
149			for (int i = 0; i < 3; i++)
150			{
151				xs.TraceIdentityOnError((oId, error) => "OnError: " + oId + "=" + error.Message).Subscribe(_ => { }, __ => { });
152
153				string id = GetCurrentId();
154
155				AssertEqual(Listener.Messages, "OnError: " + id + "=" + ex.Message);
156
157				Listener.Clear();
158			}
159
160			RemoveTraceListener();
161		}
162
163		[TestMethod]
164		public void RxTraceIdentityOnCompleted()
165		{
166			AddTraceListener();
167
168			var xs = Observable.Range(0, 5);
169
170			for (int i = 0; i < 3; i++)
171			{
172				xs.TraceIdentityOnCompleted().Subscribe();
173
174				string id = GetCurrentId();
175
176				AssertEqual(Listener.Messages, TraceDefaults.DefaultOnCompleted(id));
177
178				Listener.Clear();
179			}
180
181			RemoveTraceListener();
182		}
183
184		[TestMethod]
185		public void RxTraceIdentityOnCompletedFormat()
186		{
187			AddTraceListener();
188
189			var xs = Observable.Range(0, 5);
190
191			for (int i = 0; i < 3; i++)
192			{
193				xs.TraceIdentityOnCompleted("OnCompleted: {0}").Subscribe();
194
195				string id = GetCurrentId();
196
197				AssertEqual(Listener.Messages, "OnCompleted: " + id);
198
199				Listener.Clear();
200			}
201
202			RemoveTraceListener();
203		}
204
205		[TestMethod]
206		public void RxTraceIdentityOnCompletedLazyMessage()
207		{
208			AddTraceListener();
209
210			var xs = Observable.Range(0, 5);
211
212			for (int i = 0; i < 3; i++)
213			{
214				xs.TraceIdentityOnCompleted(oId => "OnCompleted: " + oId).Subscribe();
215
216				string id = GetCurrentId();
217
218				AssertEqual(Listener.Messages, "OnCompleted: " + id);
219
220				Listener.Clear();
221			}
222
223			RemoveTraceListener();
224		}
225	}
226}