PageRenderTime 61ms CodeModel.GetById 21ms app.highlight 7ms RepoModel.GetById 16ms app.codeStats 1ms

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

#
C# | 135 lines | 95 code | 40 blank | 0 comment | 0 complexity | af6f6f3953619aabd6eb719bf41fd5e7 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 TraceTests : RxxTraceTests
  9	{
 10		[TestMethod]
 11		public void RxTraceSource()
 12		{
 13			var source = CreateTraceSource();
 14
 15			var xs = Observable.Range(0, 5);
 16
 17			xs.Trace(source).Subscribe();
 18
 19			AssertEqual(Listener.Messages, Concat(
 20				Enumerable.Range(0, 5).Select(value => TraceDefaults.DefaultOnNext(value)),
 21				TraceDefaults.DefaultOnCompleted()));
 22		}
 23
 24		[TestMethod]
 25		public void RxTraceSourceOnNext()
 26		{
 27			var source = CreateTraceSource();
 28
 29			var xs = Observable.Range(0, 5);
 30
 31			xs.TraceOnNext(source).Subscribe();
 32
 33			AssertEqual(Listener.Messages, Enumerable.Range(0, 5).Select(value => TraceDefaults.DefaultOnNext(value)));
 34		}
 35
 36		[TestMethod]
 37		public void RxTraceSourceOnNextFormat()
 38		{
 39			var source = CreateTraceSource();
 40
 41			var xs = Observable.Range(0, 5);
 42
 43			xs.TraceOnNext(source, "OnNext: {0}").Subscribe();
 44
 45			AssertEqual(Listener.Messages, Enumerable.Range(0, 5).Select(value => "OnNext: " + value));
 46		}
 47
 48		[TestMethod]
 49		public void RxTraceSourceOnNextLazyMessage()
 50		{
 51			var source = CreateTraceSource();
 52
 53			var xs = Observable.Range(0, 5);
 54
 55			xs.TraceOnNext(source, value => "OnNext: " + value).Subscribe();
 56
 57			AssertEqual(Listener.Messages, Enumerable.Range(0, 5).Select(value => "OnNext: " + value));
 58		}
 59
 60		[TestMethod]
 61		public void RxTraceSourceOnError()
 62		{
 63			var source = CreateTraceSource();
 64
 65			var ex = new Exception("Error");
 66			var xs = Observable.Throw<int>(ex);
 67
 68			xs.TraceOnError(source).Subscribe(_ => { }, __ => { });
 69
 70			AssertEqual(Listener.Messages, TraceDefaults.DefaultOnError(ex));
 71		}
 72
 73		[TestMethod]
 74		public void RxTraceSourceOnErrorFormat()
 75		{
 76			var source = CreateTraceSource();
 77
 78			var ex = new Exception("Error");
 79			var xs = Observable.Throw<int>(ex);
 80
 81			xs.TraceOnError(source, "OnError: {0}").Subscribe(_ => { }, __ => { });
 82
 83			AssertEqual(Listener.Messages, "OnError: " + ex.ToString());
 84		}
 85
 86		[TestMethod]
 87		public void RxTraceSourceOnErrorLazyMessage()
 88		{
 89			var source = CreateTraceSource();
 90
 91			var ex = new Exception("Error");
 92			var xs = Observable.Throw<int>(ex);
 93
 94			xs.TraceOnError(source, error => "OnError: " + error.Message).Subscribe(_ => { }, __ => { });
 95
 96			AssertEqual(Listener.Messages, "OnError: " + ex.Message);
 97		}
 98
 99		[TestMethod]
100		public void RxTraceSourceOnCompleted()
101		{
102			var source = CreateTraceSource();
103
104			var xs = Observable.Range(0, 5);
105
106			xs.TraceOnCompleted(source).Subscribe();
107
108			AssertEqual(Listener.Messages, TraceDefaults.DefaultOnCompleted());
109		}
110
111		[TestMethod]
112		public void RxTraceSourceOnCompletedFormat()
113		{
114			var source = CreateTraceSource();
115
116			var xs = Observable.Range(0, 5);
117
118			xs.TraceOnCompleted(source, "OnCompleted").Subscribe();
119
120			AssertEqual(Listener.Messages, "OnCompleted");
121		}
122
123		[TestMethod]
124		public void RxTraceSourceOnCompletedLazyMessage()
125		{
126			var source = CreateTraceSource();
127
128			var xs = Observable.Range(0, 5);
129
130			xs.TraceOnCompleted(source, () => "OnCompleted").Subscribe();
131
132			AssertEqual(Listener.Messages, "OnCompleted");
133		}
134	}
135}