Welcome to mirror list, hosted at ThFree Co, Russian Federation.

EventPatternSourceBaseTest.cs « Tests « Tests.System.Reactive « Rx.NET - github.com/mono/rx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 21add27dec9ca1705ac0ef51ae3f5ddbdc4bdb80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.

using System;
using System.Reactive;
using System.Reactive.Linq;
using Microsoft.Reactive.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace ReactiveTests.Tests
{
    [TestClass]
    public class EventPatternSourceBaseTest
    {
        [TestMethod]
        public void ArgumentChecking()
        {
            var xs = Observable.Empty<EventPattern<object, EventArgs>>();

            ReactiveAssert.Throws<ArgumentNullException>(() => new MyEventPatternSource(null, (a, x) => { }));
            ReactiveAssert.Throws<ArgumentNullException>(() => new MyEventPatternSource(xs, null));

            var e = new MyEventPatternSource(xs, (a, x) => { });
            e.GetInvoke = h => (_, __) => { };

            ReactiveAssert.Throws<ArgumentNullException>(() => e.OnNext += null);

            e.GetInvoke = h => null;
            ReactiveAssert.Throws<ArgumentNullException>(() => e.OnNext += (_, __) => { });
            e.GetInvoke = null;

            ReactiveAssert.Throws<ArgumentNullException>(() => e.OnNext -= null);
        }
    }

    class MyEventPatternSource : EventPatternSourceBase<object, EventArgs>
    {
        public MyEventPatternSource(IObservable<EventPattern<object, EventArgs>> source, Action<Action<object, EventArgs>, EventPattern<object, EventArgs>> invokeHandler)
            : base(source, invokeHandler)
        {
        }

        public Func<EventHandler<EventArgs>, Action<object, EventArgs>> GetInvoke;

        public event EventHandler<EventArgs> OnNext
        {
            add
            {
                base.Add(value, GetInvoke(value));
            }

            remove
            {
                Remove(value);
            }
        }
    }
}