MockObserver.cs 1.3 KB

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