EventPatternSourceBaseTest.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
  2. using System;
  3. using System.Reactive;
  4. using System.Reactive.Linq;
  5. using Microsoft.Reactive.Testing;
  6. using Xunit;
  7. namespace ReactiveTests.Tests
  8. {
  9. public class EventPatternSourceBaseTest
  10. {
  11. [Fact]
  12. public void ArgumentChecking()
  13. {
  14. var xs = Observable.Empty<EventPattern<object, EventArgs>>();
  15. ReactiveAssert.Throws<ArgumentNullException>(() => new MyEventPatternSource(null, (a, x) => { }));
  16. ReactiveAssert.Throws<ArgumentNullException>(() => new MyEventPatternSource(xs, null));
  17. var e = new MyEventPatternSource(xs, (a, x) => { });
  18. e.GetInvoke = h => (_, __) => { };
  19. ReactiveAssert.Throws<ArgumentNullException>(() => e.OnNext += null);
  20. e.GetInvoke = h => null;
  21. ReactiveAssert.Throws<ArgumentNullException>(() => e.OnNext += (_, __) => { });
  22. e.GetInvoke = null;
  23. ReactiveAssert.Throws<ArgumentNullException>(() => e.OnNext -= null);
  24. }
  25. }
  26. class MyEventPatternSource : EventPatternSourceBase<object, EventArgs>
  27. {
  28. public MyEventPatternSource(IObservable<EventPattern<object, EventArgs>> source, Action<Action<object, EventArgs>, EventPattern<object, EventArgs>> invokeHandler)
  29. : base(source, invokeHandler)
  30. {
  31. }
  32. public Func<EventHandler<EventArgs>, Action<object, EventArgs>> GetInvoke;
  33. public event EventHandler<EventArgs> OnNext
  34. {
  35. add
  36. {
  37. base.Add(value, GetInvoke(value));
  38. }
  39. remove
  40. {
  41. Remove(value);
  42. }
  43. }
  44. }
  45. }