Skip to content

Commit 11e63d6

Browse files
authored
Add snapshot test: projectable constructor with NullConditionalRewriteSupport.Ignore and null-conditional operators
1 parent c5574ab commit 11e63d6

2 files changed

Lines changed: 84 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// <auto-generated/>
2+
#nullable disable
3+
using EntityFrameworkCore.Projectables;
4+
using Foo;
5+
6+
namespace EntityFrameworkCore.Projectables.Generated
7+
{
8+
/// <summary>
9+
/// <para>Generated from:</para>
10+
/// <code>
11+
/// [Projectable(NullConditionalRewriteSupport = NullConditionalRewriteSupport.Ignore)]
12+
/// public Projection(Source source)
13+
/// {
14+
/// Libelle = source.Libelle;
15+
/// NumeroDossier = source.Dossier?.Numero;
16+
/// TotalHt = source.TotalHt;
17+
/// TypeValue = source.Type?.ToString();
18+
/// IsForfaitDisplay = source.IsForfait ? "Yes" : "No";
19+
/// }
20+
/// </code>
21+
/// </summary>
22+
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
23+
static class Foo_Projection__ctor_P0_Foo_Source
24+
{
25+
static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.Source, global::Foo.Projection>> Expression()
26+
{
27+
return (global::Foo.Source source) => new global::Foo.Projection()
28+
{
29+
Libelle = source.Libelle,
30+
NumeroDossier = source.Dossier.Numero,
31+
TotalHt = source.TotalHt,
32+
TypeValue = source.Type.ToString(),
33+
IsForfaitDisplay = source.IsForfait ? "Yes" : "No"
34+
};
35+
}
36+
}
37+
}

tests/EntityFrameworkCore.Projectables.Generator.Tests/ConstructorTests.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,4 +1339,51 @@ public CustomerDto(Customer customer)
13391339

13401340
return Verifier.Verify(result.GeneratedTrees[0].ToString());
13411341
}
1342+
1343+
[Fact]
1344+
public Task ProjectableConstructor_WithNullConditionalIgnore()
1345+
{
1346+
var compilation = CreateCompilation(@"
1347+
using EntityFrameworkCore.Projectables;
1348+
1349+
namespace Foo {
1350+
class Dossier {
1351+
public string Numero { get; set; }
1352+
}
1353+
1354+
class Source {
1355+
public string Libelle { get; set; }
1356+
public Dossier Dossier { get; set; }
1357+
public decimal TotalHt { get; set; }
1358+
public bool IsForfait { get; set; }
1359+
public string Type { get; set; }
1360+
}
1361+
1362+
class Projection {
1363+
public string Libelle { get; set; }
1364+
public string NumeroDossier { get; set; }
1365+
public decimal TotalHt { get; set; }
1366+
public string TypeValue { get; set; }
1367+
public string IsForfaitDisplay { get; set; }
1368+
1369+
public Projection() { }
1370+
1371+
[Projectable(NullConditionalRewriteSupport = NullConditionalRewriteSupport.Ignore)]
1372+
public Projection(Source source) {
1373+
Libelle = source.Libelle;
1374+
NumeroDossier = source.Dossier?.Numero;
1375+
TotalHt = source.TotalHt;
1376+
TypeValue = source.Type?.ToString();
1377+
IsForfaitDisplay = source.IsForfait ? ""Yes"" : ""No"";
1378+
}
1379+
}
1380+
}
1381+
");
1382+
var result = RunGenerator(compilation);
1383+
1384+
Assert.Empty(result.Diagnostics);
1385+
Assert.Single(result.GeneratedTrees);
1386+
1387+
return Verifier.Verify(result.GeneratedTrees[0].ToString());
1388+
}
13421389
}

0 commit comments

Comments
 (0)