-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ignore comments in SQL composability check
And rewrite without regex Fixes #18412
- Loading branch information
Showing
2 changed files
with
105 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
test/EFCore.Relational.Tests/Query/Internal/QuerySqlGeneratorTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using JetBrains.Annotations; | ||
using Microsoft.EntityFrameworkCore.Diagnostics; | ||
using Microsoft.EntityFrameworkCore.Storage; | ||
using Microsoft.EntityFrameworkCore.TestUtilities; | ||
using Xunit; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query.Internal | ||
{ | ||
public class QuerySqlGeneratorTest | ||
{ | ||
[Theory] | ||
[InlineData("INSERT something")] | ||
[InlineData("SELECTANDSOMEOTHERSTUFF")] | ||
[InlineData("SELECT")] | ||
[InlineData("SELEC")] | ||
[InlineData("- bad comment\nSELECT something")] | ||
[InlineData("SELECT-\n1")] | ||
[InlineData("")] | ||
public void CheckComposableSql_throws(string sql) | ||
=> Assert.Equal( | ||
RelationalStrings.FromSqlNonComposable, | ||
Assert.Throws<InvalidOperationException>( | ||
() => CreateDummyQuerySqlGenerator().CheckComposableSql(sql)).Message); | ||
|
||
[Theory] | ||
[InlineData("SELECT something")] | ||
[InlineData(" SELECT something")] | ||
[InlineData("-- comment\n SELECT something")] | ||
[InlineData("-- comment1\r\n --\t\rcomment2\r\nSELECT something")] | ||
[InlineData("SELECT--\n1")] | ||
public void CheckComposableSql_does_not_throw(string sql) | ||
=> CreateDummyQuerySqlGenerator().CheckComposableSql(sql); | ||
|
||
private DummyQuerySqlGenerator CreateDummyQuerySqlGenerator() | ||
=> new DummyQuerySqlGenerator( | ||
new QuerySqlGeneratorDependencies( | ||
new RelationalCommandBuilderFactory( | ||
new RelationalCommandBuilderDependencies( | ||
new TestRelationalTypeMappingSource( | ||
TestServiceFactory.Instance.Create<TypeMappingSourceDependencies>(), | ||
TestServiceFactory.Instance.Create<RelationalTypeMappingSourceDependencies>()))), | ||
new RelationalSqlGenerationHelper( | ||
new RelationalSqlGenerationHelperDependencies()))); | ||
|
||
class DummyQuerySqlGenerator : QuerySqlGenerator | ||
{ | ||
public DummyQuerySqlGenerator([NotNull] QuerySqlGeneratorDependencies dependencies) | ||
: base(dependencies) | ||
{ | ||
} | ||
|
||
public new void CheckComposableSql(string sql) | ||
=> base.CheckComposableSql(sql); | ||
} | ||
} | ||
} |