-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
SqlServerCodeGeneratorTest.cs
80 lines (64 loc) · 3.07 KB
/
SqlServerCodeGeneratorTest.cs
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
80
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.EntityFrameworkCore.SqlServer.Scaffolding.Internal;
// ReSharper disable InconsistentNaming
namespace Microsoft.EntityFrameworkCore.Scaffolding;
public class SqlServerCodeGeneratorTest
{
[ConditionalFact]
public virtual void Use_provider_method_is_generated_correctly()
{
var codeGenerator = new SqlServerCodeGenerator(
new ProviderCodeGeneratorDependencies(
Enumerable.Empty<IProviderCodeGeneratorPlugin>()));
var result = codeGenerator.GenerateUseProvider("Data Source=Test", providerOptions: null);
Assert.Equal("UseSqlServer", result.Method);
Assert.Collection(
result.Arguments,
a => Assert.Equal("Data Source=Test", a));
Assert.Null(result.ChainedCall);
}
[ConditionalFact]
public virtual void Use_provider_method_is_generated_correctly_with_options()
{
var codeGenerator = new SqlServerCodeGenerator(
new ProviderCodeGeneratorDependencies(
Enumerable.Empty<IProviderCodeGeneratorPlugin>()));
var providerOptions = new MethodCallCodeFragment(_setProviderOptionMethodInfo);
var result = codeGenerator.GenerateUseProvider("Data Source=Test", providerOptions);
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.Same(providerOptions, nestedClosure.MethodCalls[0]);
});
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), [typeof(DbContextOptionsBuilder)]);
public static SqlServerDbContextOptionsBuilder SetProviderOption(DbContextOptionsBuilder optionsBuilder)
=> throw new NotSupportedException();
}