-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathExtensionMemberTests.cs
More file actions
79 lines (67 loc) · 2.88 KB
/
ExtensionMemberTests.cs
File metadata and controls
79 lines (67 loc) · 2.88 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
#if NET10_0_OR_GREATER
using System.Linq;
using System.Threading.Tasks;
using EntityFrameworkCore.Projectables.FunctionalTests.Helpers;
using Microsoft.EntityFrameworkCore;
using VerifyXunit;
using Xunit;
namespace EntityFrameworkCore.Projectables.FunctionalTests.ExtensionMembers
{
/// <summary>
/// Tests for C# 14 extension member support.
/// These tests only run on .NET 10+ where extension members are supported.
/// Note: Extension properties cannot currently be used directly in LINQ expression trees (CS9296),
/// so only extension methods are tested here.
/// </summary>
public class ExtensionMemberTests
{
[Fact]
public Task ExtensionMemberMethodOnEntity()
{
using var dbContext = new SampleDbContext<Entity>();
var query = dbContext.Set<Entity>()
.Select(x => x.TripleId());
return Verifier.Verify(query.ToQueryString());
}
[Fact]
public Task ExtensionMemberMethodWithParameterOnEntity()
{
using var dbContext = new SampleDbContext<Entity>();
var query = dbContext.Set<Entity>()
.Select(x => x.Multiply(5));
return Verifier.Verify(query.ToQueryString());
}
/// <summary>
/// Regression test: extension member on a <em>closed</em> generic receiver type
/// (e.g. <c>extension(GenericWrapper<Entity> w)</c>) previously threw
/// "Unable to resolve generated expression" because <c>global::</c> inside generic
/// type arguments caused a naming mismatch between the generator and the resolver.
/// </summary>
[Fact]
public Task ExtensionMemberMethodOnClosedGenericReceiverType()
{
using var dbContext = new SampleDbContext<Entity>();
var query = dbContext.Set<Entity>()
.Select(x => new GenericWrapper<Entity> { Id = x.Id })
.Select(x => x.DoubleId());
return Verifier.Verify(query.ToQueryString());
}
/// <summary>
/// Exercises support for extension members on an <em>open</em> generic receiver type
/// (e.g. <c>extension<T>(GenericWrapper<T> w)</c>).
/// The block-level type parameter <c>T</c> must be promoted to a method-level type
/// parameter on the generated <c>Expression<T>()</c> factory so the runtime
/// resolver can construct the correct closed-generic expression.
/// </summary>
[Fact]
public Task ExtensionMemberMethodOnOpenGenericReceiverType()
{
using var dbContext = new SampleDbContext<Entity>();
var query = dbContext.Set<Entity>()
.Select(x => new GenericWrapper<Entity> { Id = x.Id })
.Select(x => x.TripleId());
return Verifier.Verify(query.ToQueryString());
}
}
}
#endif