Debian Codegraph @

external/rx/Ix/NET/Tests/AsyncTests.cs

raw
1 // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
2 #if !NO_TPL
3
4 using System;
5 using System.Collections.Generic;
6 using System.Linq;
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 Tests
17 {
18 [TestClass]
19 public partial class AsyncTests
20 {
21 public void AssertThrows<E>(Action a)
22 where E : Exception
23 {
24 try
25 {
26 a();
27 Assert.Fail();
28 }
29 catch (E)
30 {
31 }
32 }
33
34 public void AssertThrows<E>(Action a, Func<E, bool> assert)
35 where E : Exception
36 {
37 try
38 {
39 a();
40 Assert.Fail();
41 }
42 catch (E e)
43 {
44 Assert.IsTrue(assert(e));
45 }
46 }
47
48 public void NoNext<T>(IAsyncEnumerator<T> e)
49 {
50 Assert.IsFalse(e.MoveNext().Result);
51 }
52
53 public void HasNext<T>(IAsyncEnumerator<T> e, T value)
54 {
55 Assert.IsTrue(e.MoveNext().Result);
56 Assert.AreEqual(value, e.Current);
57 }
58 }
59 }
60
61 #endif