Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.0] Fix SQL Server NTS scaffolding code generation #26160

Merged
merged 1 commit into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class SqlServerNetTopologySuiteCodeGeneratorPlugin : ProviderCodeGenerato
private static readonly MethodInfo _useNetTopologySuiteMethodInfo
= typeof(SqlServerNetTopologySuiteDbContextOptionsBuilderExtensions).GetRequiredRuntimeMethod(
nameof(SqlServerNetTopologySuiteDbContextOptionsBuilderExtensions.UseNetTopologySuite),
typeof(Action<SqlServerDbContextOptionsBuilder>));
typeof(SqlServerDbContextOptionsBuilder));

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,29 @@ public virtual void Use_provider_method_is_generated_correctly_with_options()
Assert.Null(result.ChainedCall);
}

[ConditionalFact]
public virtual void Use_provider_method_is_generated_correctly_with_NetTopologySuite()
{
var codeGenerator = new SqlServerCodeGenerator(
new ProviderCodeGeneratorDependencies(
new[] { new SqlServerNetTopologySuiteCodeGeneratorPlugin() }));

var result = ((IProviderConfigurationCodeGenerator)codeGenerator).GenerateUseProvider("Data Source=Test");

Assert.Equal("UseSqlServer", result.Method);
Assert.Collection(
result.Arguments,
a => Assert.Equal("Data Source=Test", a),
a =>
{
var nestedClosure = Assert.IsType<NestedClosureCodeFragment>(a);

Assert.Equal("x", nestedClosure.Parameter);
Assert.Equal("UseNetTopologySuite", nestedClosure.MethodCalls[0].Method);
});
Assert.Null(result.ChainedCall);
}

private static readonly MethodInfo _setProviderOptionMethodInfo
= typeof(SqlServerCodeGeneratorTest).GetRuntimeMethod(nameof(SetProviderOption), new[] { typeof(DbContextOptionsBuilder) });

Expand Down
23 changes: 23 additions & 0 deletions test/EFCore.Sqlite.Tests/Scaffolding/SqliteCodeGeneratorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,29 @@ public virtual void Use_provider_method_is_generated_correctly_with_options()
Assert.Null(result.ChainedCall);
}

[ConditionalFact]
public virtual void Use_provider_method_is_generated_correctly_with_NetTopologySuite()
{
var codeGenerator = new SqliteCodeGenerator(
new ProviderCodeGeneratorDependencies(
new[] { new SqliteNetTopologySuiteCodeGeneratorPlugin() }));

var result = ((IProviderConfigurationCodeGenerator)codeGenerator).GenerateUseProvider("Data Source=Test");

Assert.Equal("UseSqlite", result.Method);
Assert.Collection(
result.Arguments,
a => Assert.Equal("Data Source=Test", a),
a =>
{
var nestedClosure = Assert.IsType<NestedClosureCodeFragment>(a);

Assert.Equal("x", nestedClosure.Parameter);
Assert.Equal("UseNetTopologySuite", nestedClosure.MethodCalls[0].Method);
});
Assert.Null(result.ChainedCall);
}

private static readonly MethodInfo _setProviderOptionMethodInfo
= typeof(SqliteCodeGeneratorTest).GetRuntimeMethod(nameof(SetProviderOption), new[] { typeof(DbContextOptionsBuilder) });

Expand Down