-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathPartialClassWithPrivateMembersTests.cs
More file actions
59 lines (50 loc) · 1.94 KB
/
PartialClassWithPrivateMembersTests.cs
File metadata and controls
59 lines (50 loc) · 1.94 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
using System.Linq;
using System.Threading.Tasks;
using EntityFrameworkCore.Projectables.FunctionalTests.Helpers;
using Microsoft.EntityFrameworkCore;
using VerifyXunit;
using Xunit;
namespace EntityFrameworkCore.Projectables.FunctionalTests
{
/// <summary>
/// An entity that uses the partial class pattern to expose private projectable members.
/// Without the partial keyword, <see cref="PartialEntity.Total"/> could not call the private
/// <see cref="PartialEntity.DoubleId"/> because the generated companion class would be in a
/// separate namespace and lack access to private members.
/// </summary>
public partial record PartialEntity
{
public int Id { get; set; }
/// <summary>
/// Public projectable that delegates to a private projectable.
/// Requires the companion to be nested inside this type so it can call DoubleId.
/// </summary>
[Projectable]
public int Total => DoubleId + 1;
/// <summary>
/// Private projectable — only accessible from within this type.
/// The companion is generated as a nested class inside <see cref="PartialEntity"/> (partial).
/// </summary>
[Projectable]
private int DoubleId => Id * 2;
}
public class PartialClassWithPrivateMembersTests
{
[Fact]
public Task FilterOnPrivateProjectableProperty()
{
using var dbContext = new SampleDbContext<PartialEntity>();
var query = dbContext.Set<PartialEntity>()
.Where(x => x.Total > 5);
return Verifier.Verify(query.ToQueryString());
}
[Fact]
public Task SelectPrivateProjectableProperty()
{
using var dbContext = new SampleDbContext<PartialEntity>();
var query = dbContext.Set<PartialEntity>()
.Select(x => x.Total);
return Verifier.Verify(query.ToQueryString());
}
}
}