1
1
// Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
+ using Microsoft . EntityFrameworkCore . Internal ;
5
+
4
6
namespace Microsoft . EntityFrameworkCore . Design . Internal ;
5
7
6
8
public class DatabaseOperationsTest
@@ -10,16 +12,80 @@ public void Can_pass_null_args()
10
12
{
11
13
// Even though newer versions of the tools will pass an empty array
12
14
// older versions of the tools can pass null args.
15
+ CreateOperations ( null ) ;
16
+ }
17
+
18
+ [ ConditionalFact ]
19
+ public void ScaffoldContext_throws_exceptions_for_invalid_context_name ( )
20
+ {
21
+ ValidateContextNameInReverseEngineerGenerator ( "Invalid!CSharp*Class&Name" ) ;
22
+ ValidateContextNameInReverseEngineerGenerator ( "1CSharpClassNameCannotStartWithNumber" ) ;
23
+ ValidateContextNameInReverseEngineerGenerator ( "volatile" ) ;
24
+ }
25
+
26
+ private void ValidateContextNameInReverseEngineerGenerator ( string contextName )
27
+ {
28
+ var operations = CreateOperations ( [ ] ) ;
29
+
30
+ Assert . Equal (
31
+ DesignStrings . ContextClassNotValidCSharpIdentifier ( contextName ) ,
32
+ Assert . Throws < ArgumentException > (
33
+ ( ) => operations . ScaffoldContext (
34
+ "Microsoft.EntityFrameworkCore.SqlServer" ,
35
+ "connectionstring" ,
36
+ "" ,
37
+ "" ,
38
+ dbContextClassName : contextName ,
39
+ null ,
40
+ null ,
41
+ "FakeNamespace" ,
42
+ contextNamespace : null ,
43
+ useDataAnnotations : false ,
44
+ overwriteFiles : true ,
45
+ useDatabaseNames : false ,
46
+ suppressOnConfiguring : true ,
47
+ noPluralize : false ) )
48
+ . Message ) ;
49
+ }
50
+
51
+ [ ConditionalFact ]
52
+ [ SqlServerConfiguredCondition ]
53
+ public void ScaffoldContext_sets_environment ( )
54
+ {
55
+ var operations = CreateOperations ( [ ] ) ;
56
+ operations . ScaffoldContext (
57
+ "Microsoft.EntityFrameworkCore.SqlServer" ,
58
+ TestEnvironment . DefaultConnection ,
59
+ "" ,
60
+ "" ,
61
+ dbContextClassName : nameof ( TestContext ) ,
62
+ schemas : [ "Empty" ] ,
63
+ null ,
64
+ null ,
65
+ contextNamespace : null ,
66
+ useDataAnnotations : false ,
67
+ overwriteFiles : true ,
68
+ useDatabaseNames : false ,
69
+ suppressOnConfiguring : true ,
70
+ noPluralize : false ) ;
71
+
72
+ Assert . Equal ( "Development" , Environment . GetEnvironmentVariable ( "ASPNETCORE_ENVIRONMENT" ) ) ;
73
+ Assert . Equal ( "Development" , Environment . GetEnvironmentVariable ( "DOTNET_ENVIRONMENT" ) ) ;
74
+ }
75
+
76
+ private static DatabaseOperations CreateOperations ( string [ ] args )
77
+ {
13
78
var assembly = MockAssembly . Create ( typeof ( TestContext ) ) ;
14
- _ = new TestDatabaseOperations (
79
+ var operations = new DatabaseOperations (
15
80
new TestOperationReporter ( ) ,
16
81
assembly ,
17
82
assembly ,
18
83
"projectDir" ,
19
84
"RootNamespace" ,
20
85
"C#" ,
21
86
nullable : false ,
22
- args : null ) ;
87
+ args : args ) ;
88
+ return operations ;
23
89
}
24
90
25
91
public class TestContext : DbContext ;
0 commit comments