EventPatternSourceBaseTest.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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;
  5. using System.Reactive;
  6. using System.Reactive.Linq;
  7. using Microsoft.Reactive.Testing;
  8. using Xunit;
  9. namespace ReactiveTests.Tests
  10. {
  11. public class EventPatternSourceBaseTest
  12. {
  13. [Fact]
  14. public void ArgumentChecking()
  15. {
  16. var xs = Observable.Empty<EventPattern<object, EventArgs>>();
  17. ReactiveAssert.Throws<ArgumentNullException>(() => new MyEventPatternSource(null, (a, x) => { }));
  18. ReactiveAssert.Throws<ArgumentNullException>(() => new MyEventPatternSource(xs, null));
  19. var e = new MyEventPatternSource(xs, (a, x) => { })
  20. {
  21. GetInvoke = h => (_, __) => { }
  22. };
  23. ReactiveAssert.Throws<ArgumentNullException>(() => e.OnNext += null);
  24. e.GetInvoke = h => null;
  25. ReactiveAssert.Throws<ArgumentNullException>(() => e.OnNext += (_, __) => { });
  26. e.GetInvoke = null;
  27. ReactiveAssert.Throws<ArgumentNullException>(() => e.OnNext -= null);
  28. }
  29. }
  30. internal class MyEventPatternSource : EventPatternSourceBase<object, EventArgs>
  31. {
  32. public MyEventPatternSource(IObservable<EventPattern<object, EventArgs>> source, Action<Action<object, EventArgs>, EventPattern<object, EventArgs>> invokeHandler)
  33. : base(source, invokeHandler)
  34. {
  35. }
  36. public Func<EventHandler<EventArgs>, Action<object, EventArgs>> GetInvoke;
  37. public event EventHandler<EventArgs> OnNext
  38. {
  39. add
  40. {
  41. Add(value, GetInvoke(value));
  42. }
  43. remove
  44. {
  45. Remove(value);
  46. }
  47. }
  48. }
  49. }