forked from zzzprojects/System.Linq.Dynamic.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntitiesTests.AnyAsync.cs
More file actions
62 lines (52 loc) · 2.12 KB
/
EntitiesTests.AnyAsync.cs
File metadata and controls
62 lines (52 loc) · 2.12 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
#if EFCORE
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.DynamicLinq;
#else
using System.Data.Entity;
using EntityFramework.DynamicLinq;
#endif
using System.Threading.Tasks;
using Xunit;
namespace System.Linq.Dynamic.Core.Tests
{
public partial class EntitiesTests
{
[Fact]
public async Task Entities_AnyAsync()
{
//Arrange
PopulateTestData(1, 0);
var expectedQueryable1 = _context.Blogs.Where(b => b.BlogId > 0);
bool expectedAny1 = await expectedQueryable1.AnyAsync();
var expectedQueryable2 = _context.Blogs.Where(b => b.BlogId > 9999);
bool expectedAny2 = await expectedQueryable2.AnyAsync();
//Act
IQueryable queryable1 = _context.Blogs.Where("BlogId > 0");
bool any1 = await queryable1.AnyAsync();
IQueryable queryable2 = _context.Blogs.Where("BlogId > 9999");
bool any2 = await queryable2.AnyAsync();
//Assert
Assert.Equal(expectedAny1, any1);
Assert.Equal(expectedAny2, any2);
}
[Fact]
public async Task Entities_AnyAsync_Predicate()
{
//Arrange
PopulateTestData(1, 0);
#if EFCORE
bool expectedAny1 = await Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.AnyAsync(_context.Blogs, b => b.BlogId > 0);
bool expectedAny2 = await Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.AnyAsync(_context.Blogs, b => b.BlogId > 9999);
#else
bool expectedAny1 = await System.Data.Entity.QueryableExtensions.AnyAsync(_context.Blogs, b => b.BlogId > 0);
bool expectedAny2 = await System.Data.Entity.QueryableExtensions.AnyAsync(_context.Blogs, b => b.BlogId > 9999);
#endif
//Act
bool any1 = await _context.Blogs.AsQueryable().AnyAsync("it.BlogId > 0");
bool any2 = await _context.Blogs.AsQueryable().AnyAsync("it.BlogId > 9999");
//Assert
Assert.Equal(expectedAny1, any1);
Assert.Equal(expectedAny2, any2);
}
}
}