Debian Codegraph @

external/rx/Rx/NET/Source/Tests.System.Reactive/Tests/Concurrency/ScheduledItemTest.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.Collections.Generic;
5 using System.Reactive.Concurrency;
6 using System.Reactive.Disposables;
7 using Microsoft.Reactive.Testing;
8 #if NUNIT
9 using NUnit.Framework;
10 using TestClassAttribute = NUnit.Framework.TestFixtureAttribute;
11 using TestMethodAttribute = NUnit.Framework.TestAttribute;
12 using TestInitializeAttribute = NUnit.Framework.SetUpAttribute;
13 #else
14 using Microsoft.VisualStudio.TestTools.UnitTesting;
15 #endif
16
17 namespace ReactiveTests
18 {
19 [TestClass]
20 public class ScheduledItemTest : ReactiveTest
21 {
22 [TestMethod]
23 public void ArgumentChecking()
24 {
25 ReactiveAssert.Throws<ArgumentNullException>(() => new ScheduledItem<DateTimeOffset, int>(default(IScheduler), 42, (x, y) => Disposable.Empty, DateTimeOffset.Now));
26 ReactiveAssert.Throws<ArgumentNullException>(() => new ScheduledItem<DateTimeOffset, int>(Scheduler.Default, 42, default(Func<IScheduler, int, IDisposable>), DateTimeOffset.Now));
27
28 ReactiveAssert.Throws<ArgumentNullException>(() => new ScheduledItem<DateTimeOffset, int>(default(IScheduler), 42, (x, y) => Disposable.Empty, DateTimeOffset.Now, Comparer<DateTimeOffset>.Default));
29 ReactiveAssert.Throws<ArgumentNullException>(() => new ScheduledItem<DateTimeOffset, int>(Scheduler.Default, 42, default(Func<IScheduler, int, IDisposable>), DateTimeOffset.Now, Comparer<DateTimeOffset>.Default));
30 ReactiveAssert.Throws<ArgumentNullException>(() => new ScheduledItem<DateTimeOffset, int>(Scheduler.Default, 42, (x, y) => Disposable.Empty, DateTimeOffset.Now, default(IComparer<DateTimeOffset>)));
31 }
32
33 [TestMethod]
34 public void Inequalities()
35 {
36 var si1 = new SI(42);
37 var si2 = new SI(43);
38 var si3 = new SI(42);
39
40 Assert.IsTrue(si1 < si2);
41 Assert.IsFalse(si1 < si3);
42 Assert.IsTrue(si1 <= si2);
43 Assert.IsTrue(si1 <= si3);
44 Assert.IsTrue(si2 > si1);
45 Assert.IsFalse(si3 > si1);
46 Assert.IsTrue(si2 >= si1);
47 Assert.IsTrue(si3 >= si1);
48
49 Assert.IsTrue(si1.CompareTo(si2) < 0);
50 Assert.IsTrue(si2.CompareTo(si1) > 0);
51 Assert.IsTrue(si1.CompareTo(si1) == 0);
52 Assert.IsTrue(si1.CompareTo(si3) == 0);
53
54 Assert.IsTrue(si2 > null);
55 Assert.IsTrue(si2 >= null);
56 Assert.IsFalse(si2 < null);
57 Assert.IsFalse(si2 <= null);
58 Assert.IsTrue(null < si1);
59 Assert.IsTrue(null <= si1);
60 Assert.IsFalse(null > si1);
61 Assert.IsFalse(null >= si1);
62
63 Assert.IsTrue(si1.CompareTo(null) > 0);
64
65 var si4 = new SI2(43, -1);
66 var si5 = new SI2(44, -1);
67
68 Assert.IsTrue(si4 > si1);
69 Assert.IsTrue(si4 >= si1);
70 Assert.IsTrue(si1 < si4);
71 Assert.IsTrue(si1 <= si4);
72 Assert.IsFalse(si4 > si2);
73 Assert.IsTrue(si4 >= si2);
74 Assert.IsFalse(si2 < si4);
75 Assert.IsTrue(si2 <= si4);
76
77 Assert.IsTrue(si5 > si4);
78 Assert.IsTrue(si5 >= si4);
79 Assert.IsFalse(si4 > si5);
80 Assert.IsFalse(si4 >= si5);
81 Assert.IsTrue(si4 < si5);
82 Assert.IsTrue(si4 <= si5);
83 Assert.IsFalse(si5 < si4);
84 Assert.IsFalse(si5 <= si4);
85 }
86
87 [TestMethod]
88 public void Equalities()
89 {
90 var si1 = new SI2(42, 123);
91 var si2 = new SI2(42, 123);
92 var si3 = new SI2(42, 321);
93 var si4 = new SI2(43, 123);
94
95 #pragma warning disable 1718
96 Assert.IsFalse(si1 != si1);
97 Assert.IsTrue(si1 == si1);
98 #pragma warning restore 1718
99 Assert.IsTrue(si1.Equals(si1));
100
101 Assert.IsTrue(si1 != si2);
102 Assert.IsFalse(si1 == si2);
103 Assert.IsFalse(si1.Equals(si2));
104
105 Assert.IsTrue(si1 != null);
106 Assert.IsTrue(null != si1);
107 Assert.IsFalse(si1 == null);
108 Assert.IsFalse(null == si1);
109
110 Assert.AreEqual(si1.GetHashCode(), si1.GetHashCode());
111 Assert.AreNotEqual(si1.GetHashCode(), si2.GetHashCode());
112 Assert.AreNotEqual(si1.GetHashCode(), si3.GetHashCode());
113 }
114
115 class SI : ScheduledItem<int>
116 {
117 public SI(int dueTime)
118 : base(dueTime, Comparer<int>.Default)
119 {
120 }
121
122 protected override IDisposable InvokeCore()
123 {
124 throw new NotImplementedException();
125 }
126 }
127
128 class SI2 : ScheduledItem<int>
129 {
130 private readonly int _value;
131
132 public SI2(int dueTime, int value)
133 : base(dueTime, Comparer<int>.Default)
134 {
135 _value = value;
136 }
137
138 protected override IDisposable InvokeCore()
139 {
140 throw new NotImplementedException();
141 }
142 }
143 }
144 }