Added a test to verify behavior

This commit is contained in:
Koen
2023-08-30 01:22:21 +01:00
parent 59d4d63d58
commit 44b06e4959
2 changed files with 66 additions and 0 deletions

View File

@@ -72,6 +72,9 @@ namespace EntityFrameworkCore.Projectables.Generator
{
var diagnostic = Diagnostic.Create(Diagnostics.NullConditionalRewriteUnsupported, node.GetLocation(), node);
_context.ReportDiagnostic(diagnostic);
// Return the original node, do not attempt further rewrites
return node;
}
else if (_nullConditionalRewriteSupport is NullConditionalRewriteSupport.Ignore)

View File

@@ -644,6 +644,69 @@ namespace Foo {
Assert.Equal("EFP0002", diagnostic.Id);
}
[Fact]
public void NullableMemberBinding_UndefinedSupport_IsBeingReported()
{
var compilation = CreateCompilation(@"
using System;
using System.Linq;
using EntityFrameworkCore.Projectables;
namespace Foo {
static class C {
[Projectable]
public static int? GetLength(this string input) => input?.Length;
}
}
");
var result = RunGenerator(compilation);
var diagnostic = Assert.Single(result.Diagnostics);
Assert.Equal("EFP0002", diagnostic.Id);
}
[Fact]
public void MultiLevelNullableMemberBinding_UndefinedSupport_IsBeingReported()
{
var compilation = CreateCompilation(@"
using System;
using System.Linq;
using EntityFrameworkCore.Projectables;
namespace Foo {
public record Address
{
public int Id { get; set; }
public string? Country { get; set; }
}
public record Party
{
public int Id { get; set; }
public Address? Address { get; set; }
}
public record Entity
{
public int Id { get; set; }
public Party? Left { get; set; }
public Party? Right { get; set; }
[Projectable]
public bool IsSameCountry => Left?.Address?.Country == Right?.Address?.Country;
}
}
");
var result = RunGenerator(compilation);
Assert.All(result.Diagnostics, diagnostic => {
Assert.Equal("EFP0002", diagnostic.Id);
});
}
[Fact]
public Task NullableMemberBinding_WithIgnoreSupport_IsBeingRewritten()
{