Debian Codegraph @

external/rx/Rx/NET/Source/Tests.System.Reactive/Tests/EventPatternSourceBaseTest.cs

raw
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.Reactive;
5 using System.Reactive.Linq;
6 using Microsoft.Reactive.Testing;
7 #if NUNIT
8 using NUnit.Framework;
9 using TestClassAttribute = NUnit.Framework.TestFixtureAttribute;
10 using TestMethodAttribute = NUnit.Framework.TestAttribute;
11 using TestInitializeAttribute = NUnit.Framework.SetUpAttribute;
12 #else
13 using Microsoft.VisualStudio.TestTools.UnitTesting;
14 #endif
15
16 namespace ReactiveTests.Tests
17 {
18 [TestClass]
19 public class EventPatternSourceBaseTest
20 {
21 [TestMethod]
22 public void ArgumentChecking()
23 {
24 var xs = Observable.Empty<EventPattern<object, EventArgs>>();
25
26 ReactiveAssert.Throws<ArgumentNullException>(() => new MyEventPatternSource(null, (a, x) => { }));
27 ReactiveAssert.Throws<ArgumentNullException>(() => new MyEventPatternSource(xs, null));
28
29 var e = new MyEventPatternSource(xs, (a, x) => { });
30 e.GetInvoke = h => (_, __) => { };
31
32 ReactiveAssert.Throws<ArgumentNullException>(() => e.OnNext += null);
33
34 e.GetInvoke = h => null;
35 ReactiveAssert.Throws<ArgumentNullException>(() => e.OnNext += (_, __) => { });
36 e.GetInvoke = null;
37
38 ReactiveAssert.Throws<ArgumentNullException>(() => e.OnNext -= null);
39 }
40 }
41
42 class MyEventPatternSource : EventPatternSourceBase<object, EventArgs>
43 {
44 public MyEventPatternSource(IObservable<EventPattern<object, EventArgs>> source, Action<Action<object, EventArgs>, EventPattern<object, EventArgs>> invokeHandler)
45 : base(source, invokeHandler)
46 {
47 }
48
49 public Func<EventHandler<EventArgs>, Action<object, EventArgs>> GetInvoke;
50
51 public event EventHandler<EventArgs> OnNext
52 {
53 add
54 {
55 base.Add(value, GetInvoke(value));
56 }
57
58 remove
59 {
60 Remove(value);
61 }
62 }
63 }
64 }