forked from zzzprojects/System.Linq.Dynamic.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntitiesTests.FormattableString.cs
More file actions
127 lines (103 loc) · 3.49 KB
/
EntitiesTests.FormattableString.cs
File metadata and controls
127 lines (103 loc) · 3.49 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#if EFCORE
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.DynamicLinq;
#else
using System.Data.Entity;
using EntityFramework.DynamicLinq;
#endif
using System.Threading.Tasks;
using Xunit;
using System.Linq.Dynamic.Core.Tests.Helpers.Entities;
using System.Linq.Expressions;
namespace System.Linq.Dynamic.Core.Tests;
#if EFCORE || (NET46_OR_GREATER || NET5_0_OR_GREATER || NETCOREAPP2_1_OR_GREATER || NETSTANDARD1_3_OR_GREATER || UAP10_0)
public partial class EntitiesTests
{
[Fact]
public void Entities_All_FS()
{
//Arrange
int value = 2000;
var expected = _context.Blogs.All(b => b.BlogId > value);
//Act
var actual = _context.Blogs.AllInterpolated($"BlogId > {value}");
//Assert
Assert.Equal(expected, actual);
}
[Fact]
public async Task Entities_AllAsync_FS()
{
//Arrange
int value = 2000;
var expected = await _context.Blogs.AllAsync(b => b.BlogId > value);
//Act
var actual = await _context.Blogs.AllInterpolatedAsync($"BlogId > {value}");
//Assert
Assert.Equal(expected, actual);
}
[Fact]
public void Entities_Count_Predicate_FS()
{
// Arrange
const string search = "a";
// Act
int expected = _context.Blogs.Count(b => b.Name.Contains(search));
int result = _context.Blogs.CountInterpolated($"Name.Contains({search})");
// Assert
Assert.Equal(expected, result);
}
[Fact]
public async Task Entities_CountAsync_Predicate_Args_FS()
{
// Arrange
const string search = "a";
Expression<Func<Blog, bool>> predicate = b => b.Name.Contains(search);
#if EFCORE
var expected = await EntityFrameworkQueryableExtensions.CountAsync(_context.Blogs, predicate);
#else
var expected = await QueryableExtensions.CountAsync(_context.Blogs, predicate);
#endif
// Act
int result = await (_context.Blogs as IQueryable).CountInterpolatedAsync($"Name.Contains({search})");
// Assert
Assert.Equal(expected, result);
}
[Fact]
public void Entities_LongCount_Predicate_FS()
{
// Arrange
const string search = "a";
// Act
long expected = _context.Blogs.LongCount(b => b.Name.Contains(search));
long result = _context.Blogs.LongCountInterpolated($"Name.Contains({search})");
// Assert
Assert.Equal(expected, result);
}
[Fact]
public async Task Entities_LongCountAsync_Predicate_Args_FS()
{
// Arrange
const string search = "a";
Expression<Func<Blog, bool>> predicate = b => b.Name.Contains(search);
#if EFCORE
var expected = await EntityFrameworkQueryableExtensions.LongCountAsync(_context.Blogs, predicate);
#else
var expected = await QueryableExtensions.LongCountAsync(_context.Blogs, predicate);
#endif
//Act
long result = (_context.Blogs as IQueryable).LongCountInterpolated($"Name.Contains({search})");
//Assert
Assert.Equal(expected, result);
}
[Fact(Skip = "not supported")]
public void Entities_TakeWhile_FS()
{
// Act
int value = 5;
var expected = _context.Blogs.OrderBy(b => b.BlogId).TakeWhile(b => b.BlogId > value).ToArray();
var result = _context.Blogs.OrderByInterpolated($"BlogId").TakeWhileInterpolated($"b.BlogId > {value}").ToDynamicArray<Blog>();
// Assert
Assert.Equal(expected, result);
}
}
#endif