MockObserver.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 License.
  3. // See the LICENSE file in the project root for more information.
  4. using System.Collections.Generic;
  5. using System.Reactive;
  6. using System;
  7. namespace Microsoft.Reactive.Testing
  8. {
  9. class MockObserver<T> : ITestableObserver<T>
  10. {
  11. TestScheduler scheduler;
  12. List<Recorded<Notification<T>>> messages;
  13. public MockObserver(TestScheduler scheduler)
  14. {
  15. if (scheduler == null)
  16. throw new ArgumentNullException("scheduler");
  17. this.scheduler = scheduler;
  18. this.messages = new List<Recorded<Notification<T>>>();
  19. }
  20. public void OnNext(T value)
  21. {
  22. messages.Add(new Recorded<Notification<T>>(scheduler.Clock, Notification.CreateOnNext<T>(value)));
  23. }
  24. public void OnError(Exception exception)
  25. {
  26. messages.Add(new Recorded<Notification<T>>(scheduler.Clock, Notification.CreateOnError<T>(exception)));
  27. }
  28. public void OnCompleted()
  29. {
  30. messages.Add(new Recorded<Notification<T>>(scheduler.Clock, Notification.CreateOnCompleted<T>()));
  31. }
  32. public IList<Recorded<Notification<T>>> Messages
  33. {
  34. get { return messages; }
  35. }
  36. }
  37. }