| 1 |
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. |
| 2 |
|
| 3 |
using System.Collections.Generic; |
| 4 |
using System.Reactive; |
| 5 |
using System; |
| 6 |
|
| 7 |
namespace Microsoft.Reactive.Testing |
| 8 |
{ |
| 9 |
class MockObserver<T> : ITestableObserver<T> |
| 10 |
{ |
| 11 |
TestScheduler scheduler; |
| 12 |
List<Recorded<Notification<T>>> messages; |
| 13 |
|
| 14 |
public MockObserver(TestScheduler scheduler) |
| 15 |
{ |
| 16 |
if (scheduler == null) |
| 17 |
throw new ArgumentNullException("scheduler"); |
| 18 |
|
| 19 |
this.scheduler = scheduler; |
| 20 |
this.messages = new List<Recorded<Notification<T>>>(); |
| 21 |
} |
| 22 |
|
| 23 |
public void OnNext(T value) |
| 24 |
{ |
| 25 |
messages.Add(new Recorded<Notification<T>>(scheduler.Clock, Notification.CreateOnNext<T>(value))); |
| 26 |
} |
| 27 |
|
| 28 |
public void OnError(Exception exception) |
| 29 |
{ |
| 30 |
messages.Add(new Recorded<Notification<T>>(scheduler.Clock, Notification.CreateOnError<T>(exception))); |
| 31 |
} |
| 32 |
|
| 33 |
public void OnCompleted() |
| 34 |
{ |
| 35 |
messages.Add(new Recorded<Notification<T>>(scheduler.Clock, Notification.CreateOnCompleted<T>())); |
| 36 |
} |
| 37 |
|
| 38 |
public IList<Recorded<Notification<T>>> Messages |
| 39 |
{ |
| 40 |
get { return messages; } |
| 41 |
} |
| 42 |
} |
| 43 |
} |