-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathSingle.ts
91 lines (74 loc) · 3.05 KB
/
Single.ts
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { InvalidOperationException } from "linq-to-typescript"
import { asAsync, expectAsync, itAsync, itEnumerable, itParallel } from "../TestHelpers"
// tslint:disable:variable-name
describe("single", () => {
it("String", () => {
expect("a".single()).toBe("a")
})
itEnumerable("basic", (asEnumerable) => {
const vals = asEnumerable([1])
expect(vals.single()).toBe(1)
})
itAsync("basic", async () => {
const vals = asAsync([1])
expect(await vals.single()).toBe(1)
})
itParallel("basic", async (asParallel) => {
const vals = asParallel([1])
expect(await vals.single()).toBe(1)
})
itEnumerable("basic exception", (asEnumerable) => {
const vals = asEnumerable([1, 2, 3, 4])
expect(() => vals.single()).toThrowError(InvalidOperationException)
})
itAsync("basic exception", async () => {
const vals = asAsync([1, 2, 3, 4])
const expect = await expectAsync(vals.single())
expect.toThrowError(InvalidOperationException)
})
itParallel("basic exception", async (asParallel) => {
const vals = asParallel([1, 2, 3, 4])
const expect = await expectAsync(vals.single())
expect.toThrowError(InvalidOperationException)
})
itEnumerable("predicate", (asEnumerable) => {
const vals = asEnumerable([1])
expect(vals.single((_x) => true)).toBe(1)
})
itAsync("predicate", async () => {
const vals = asAsync([1])
expect(await vals.single((_x) => true)).toBe(1)
})
itParallel("predicate", async (asParallel) => {
const vals = asParallel([1])
expect(await vals.single((_x) => true)).toBe(1)
})
itEnumerable("predicate multiple expection", (asEnumerable) => {
const vals = asEnumerable([1, 2, 3, 4])
expect(() => vals.single((_x) => true)).toThrowError(InvalidOperationException)
})
itEnumerable("predicate no matches expection", (asEnumerable) => {
const vals = asEnumerable([1, 2, 3, 4])
expect(() => vals.single((_x) => false)).toThrowError(InvalidOperationException)
})
itAsync("predicate multiple expection", async () => {
const vals = asAsync([1, 2, 3, 4])
const expect = await expectAsync(vals.single((_x) => true))
expect.toThrowError(InvalidOperationException)
})
itAsync("predicate no matches expection", async () => {
const vals = asAsync([1, 2, 3, 4])
const expect = await expectAsync(vals.single((_x) => false))
expect.toThrowError(InvalidOperationException)
})
itParallel("predicate multiple expection", async (asParallel) => {
const vals = asParallel([1, 2, 3, 4])
const expect = await expectAsync(vals.single((_x) => true))
expect.toThrowError(InvalidOperationException)
})
itParallel("predicate no matches expection", async (asParallel) => {
const vals = asParallel([1, 2, 3, 4])
const expect = await expectAsync(vals.single((_x) => false))
expect.toThrowError(InvalidOperationException)
})
})