PageRenderTime 62ms CodeModel.GetById 24ms app.highlight 11ms RepoModel.GetById 24ms app.codeStats 1ms

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

#
C# | 205 lines | 145 code | 60 blank | 0 comment | 10 complexity | ec0d228322deb1b86e7174ebf8ec96e3 MD5 | raw file
  1using System;
  2using System.Linq;
  3using System.Reactive.Linq;
  4using Microsoft.VisualStudio.TestTools.UnitTesting;
  5
  6namespace Rxx.UnitTests.Reactive
  7{
  8	public partial class TraceIdentityTests : RxxTraceTests
  9	{
 10		[TestMethod]
 11		public void RxTraceSourceIdentity()
 12		{
 13			var source = CreateTraceSource();
 14
 15			var xs = Observable.Range(0, 5);
 16
 17			for (int i = 0; i < 3; i++)
 18			{
 19				xs.TraceIdentity(source).Subscribe();
 20
 21				string id = GetCurrentId();
 22
 23				AssertEqual(Listener.Messages, Concat(
 24					Enumerable.Range(0, 5).Select(value => TraceDefaults.DefaultOnNext(id, value)),
 25					TraceDefaults.DefaultOnCompleted(id)));
 26
 27				Listener.Clear();
 28			}
 29		}
 30
 31		[TestMethod]
 32		public void RxTraceSourceIdentityOnNext()
 33		{
 34			var source = CreateTraceSource();
 35
 36			var xs = Observable.Range(0, 5);
 37
 38			for (int i = 0; i < 3; i++)
 39			{
 40				xs.TraceIdentityOnNext(source).Subscribe();
 41
 42				string id = GetCurrentId();
 43
 44				AssertEqual(Listener.Messages, Enumerable.Range(0, 5).Select(value => TraceDefaults.DefaultOnNext(id, value)));
 45
 46				Listener.Clear();
 47			}
 48		}
 49
 50		[TestMethod]
 51		public void RxTraceSourceIdentityOnNextFormat()
 52		{
 53			var source = CreateTraceSource();
 54
 55			var xs = Observable.Range(0, 5);
 56
 57			for (int i = 0; i < 3; i++)
 58			{
 59				xs.TraceIdentityOnNext(source, "OnNext: {0}={1}").Subscribe();
 60
 61				string id = GetCurrentId();
 62
 63				AssertEqual(Listener.Messages, Enumerable.Range(0, 5).Select(value => "OnNext: " + id + "=" + value));
 64
 65				Listener.Clear();
 66			}
 67		}
 68
 69		[TestMethod]
 70		public void RxTraceSourceIdentityOnNextLazyMessage()
 71		{
 72			var source = CreateTraceSource();
 73
 74			var xs = Observable.Range(0, 5);
 75
 76			for (int i = 0; i < 3; i++)
 77			{
 78				xs.TraceIdentityOnNext(source, (oId, value) => "OnNext: " + oId + "=" + value).Subscribe();
 79
 80				string id = GetCurrentId();
 81
 82				AssertEqual(Listener.Messages, Enumerable.Range(0, 5).Select(value => "OnNext: " + id + "=" + value));
 83
 84				Listener.Clear();
 85			}
 86		}
 87
 88		[TestMethod]
 89		public void RxTraceSourceIdentityOnError()
 90		{
 91			var source = CreateTraceSource();
 92
 93			var ex = new Exception("Error");
 94			var xs = Observable.Throw<int>(ex);
 95
 96			for (int i = 0; i < 3; i++)
 97			{
 98				xs.TraceIdentityOnError(source).Subscribe(_ => { }, __ => { });
 99
100				string id = GetCurrentId();
101
102				AssertEqual(Listener.Messages, TraceDefaults.DefaultOnError(id, ex));
103
104				Listener.Clear();
105			}
106		}
107
108		[TestMethod]
109		public void RxTraceSourceIdentityOnErrorFormat()
110		{
111			var source = CreateTraceSource();
112
113			var ex = new Exception("Error");
114			var xs = Observable.Throw<int>(ex);
115
116			for (int i = 0; i < 3; i++)
117			{
118				xs.TraceIdentityOnError(source, "OnError: {0}={1}").Subscribe(_ => { }, __ => { });
119
120				string id = GetCurrentId();
121
122				AssertEqual(Listener.Messages, "OnError: " + id + "=" + ex.ToString());
123
124				Listener.Clear();
125			}
126		}
127
128		[TestMethod]
129		public void RxTraceSourceIdentityOnErrorLazyMessage()
130		{
131			var source = CreateTraceSource();
132
133			var ex = new Exception("Error");
134			var xs = Observable.Throw<int>(ex);
135
136			for (int i = 0; i < 3; i++)
137			{
138				xs.TraceIdentityOnError(source, (oId, error) => "OnError: " + oId + "=" + error.Message).Subscribe(_ => { }, __ => { });
139
140				string id = GetCurrentId();
141
142				AssertEqual(Listener.Messages, "OnError: " + id + "=" + ex.Message);
143
144				Listener.Clear();
145			}
146		}
147
148		[TestMethod]
149		public void RxTraceSourceIdentityOnCompleted()
150		{
151			var source = CreateTraceSource();
152
153			var xs = Observable.Range(0, 5);
154
155			for (int i = 0; i < 3; i++)
156			{
157				xs.TraceIdentityOnCompleted(source).Subscribe();
158
159				string id = GetCurrentId();
160
161				AssertEqual(Listener.Messages, TraceDefaults.DefaultOnCompleted(id));
162
163				Listener.Clear();
164			}
165		}
166
167		[TestMethod]
168		public void RxTraceSourceIdentityOnCompletedFormat()
169		{
170			var source = CreateTraceSource();
171
172			var xs = Observable.Range(0, 5);
173
174			for (int i = 0; i < 3; i++)
175			{
176				xs.TraceIdentityOnCompleted(source, "OnCompleted: {0}").Subscribe();
177
178				string id = GetCurrentId();
179
180				AssertEqual(Listener.Messages, "OnCompleted: " + id);
181
182				Listener.Clear();
183			}
184		}
185
186		[TestMethod]
187		public void RxTraceSourceIdentityOnCompletedLazyMessage()
188		{
189			var source = CreateTraceSource();
190
191			var xs = Observable.Range(0, 5);
192
193			for (int i = 0; i < 3; i++)
194			{
195				xs.TraceIdentityOnCompleted(source, oId => "OnCompleted: " + oId).Subscribe();
196
197				string id = GetCurrentId();
198
199				AssertEqual(Listener.Messages, "OnCompleted: " + id);
200
201				Listener.Clear();
202			}
203		}
204	}
205}