forked from dotnet/corefx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWhereTests.cs
More file actions
72 lines (62 loc) · 2.34 KB
/
WhereTests.cs
File metadata and controls
72 lines (62 loc) · 2.34 KB
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
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Linq.Expressions;
using Xunit;
namespace System.Linq.Tests
{
public class WhereTests : EnumerableBasedTests
{
[Fact]
public void Where_SourceIsNull_ArgumentNullExceptionThrown()
{
IQueryable<int> source = null;
Assert.Throws<ArgumentNullException>("source", () => source.Where(i => true));
Assert.Throws<ArgumentNullException>("source", () => source.Where((v, i) => true));
}
[Fact]
public void Where_PredicateIsNull_ArgumentNullExceptionThrown()
{
IQueryable<int> source = Enumerable.Range(1, 10).AsQueryable();
Expression<Func<int, bool>> simplePredicate = null;
Expression<Func<int, int, bool>> complexPredicate = null;
Assert.Throws<ArgumentNullException>("predicate", () => source.Where(simplePredicate));
Assert.Throws<ArgumentNullException>("predicate", () => source.Where(complexPredicate));
}
[Fact]
public void ReturnsExpectedValues_True()
{
int[] source = new[] { 1, 2, 3, 4, 5 };
Assert.Equal(source, source.AsQueryable().Where(i => true));
}
[Fact]
public void ReturnsExpectedValues_False()
{
int[] source = new[] { 1, 2, 3, 4, 5 };
Assert.Empty(source.AsQueryable().Where(i => false));
}
[Fact]
public void ReturnsExpectedValuesIndexed_True()
{
int[] source = new[] { 1, 2, 3, 4, 5 };
Assert.Equal(source, source.AsQueryable().Where((e, i) => true));
}
[Fact]
public void ReturnsExpectedValuesIndexed_False()
{
int[] source = new[] { 1, 2, 3, 4, 5 };
Assert.Empty(source.AsQueryable().Where((e, i) => false));
}
[Fact]
public void Where1()
{
var count = (new int[] { 0, 1, 2 }).AsQueryable().Where(n => n > 1).Count();
Assert.Equal(1, count);
}
[Fact]
public void Where2()
{
var count = (new int[] { 0, 1, 2 }).AsQueryable().Where((n, i) => n > 1 || i == 0).Count();
Assert.Equal(2, count);
}
}
}