| 1 |
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. |
| 2 |
|
| 3 |
using System; |
| 4 |
using System.Collections.Generic; |
| 5 |
using System.Reactive.Disposables; |
| 6 |
using System.Reactive.Subjects; |
| 7 |
|
| 8 |
namespace ReactiveTests.Tests |
| 9 |
{ |
| 10 |
class MySubject : ISubject<int> |
| 11 |
{ |
| 12 |
private Dictionary<int, IDisposable> _disposeOn = new Dictionary<int, IDisposable>(); |
| 13 |
|
| 14 |
public void DisposeOn(int value, IDisposable disposable) |
| 15 |
{ |
| 16 |
_disposeOn[value] = disposable; |
| 17 |
} |
| 18 |
|
| 19 |
private IObserver<int> _observer; |
| 20 |
|
| 21 |
public void OnNext(int value) |
| 22 |
{ |
| 23 |
_observer.OnNext(value); |
| 24 |
|
| 25 |
IDisposable disconnect; |
| 26 |
if (_disposeOn.TryGetValue(value, out disconnect)) |
| 27 |
disconnect.Dispose(); |
| 28 |
} |
| 29 |
|
| 30 |
public void OnError(Exception exception) |
| 31 |
{ |
| 32 |
_observer.OnError(exception); |
| 33 |
} |
| 34 |
|
| 35 |
public void OnCompleted() |
| 36 |
{ |
| 37 |
_observer.OnCompleted(); |
| 38 |
} |
| 39 |
|
| 40 |
public IDisposable Subscribe(IObserver<int> observer) |
| 41 |
{ |
| 42 |
_subscribeCount++; |
| 43 |
_observer = observer; |
| 44 |
return Disposable.Create(() => { _disposed = true; }); |
| 45 |
} |
| 46 |
|
| 47 |
private int _subscribeCount; |
| 48 |
private bool _disposed; |
| 49 |
|
| 50 |
public int SubscribeCount { get { return _subscribeCount; } } |
| 51 |
public bool Disposed { get { return _disposed; } } |
| 52 |
} |
| 53 |
} |