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,79 @@ 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
+ public void ScaffoldContext_sets_environment ( )
53
+ {
54
+ var operations = CreateOperations ( [ ] ) ;
55
+ operations . ScaffoldContext (
56
+ "Microsoft.EntityFrameworkCore.SqlServer" ,
57
+ TestEnvironment . DefaultConnection ,
58
+ "" ,
59
+ "" ,
60
+ dbContextClassName : nameof ( TestContext ) ,
61
+ schemas : [ "Empty" ] ,
62
+ null ,
63
+ null ,
64
+ contextNamespace : null ,
65
+ useDataAnnotations : false ,
66
+ overwriteFiles : true ,
67
+ useDatabaseNames : false ,
68
+ suppressOnConfiguring : true ,
69
+ noPluralize : false ) ;
70
+
71
+ Assert . Equal ( "Development" , Environment . GetEnvironmentVariable ( "ASPNETCORE_ENVIRONMENT" ) ) ;
72
+ Assert . Equal ( "Development" , Environment . GetEnvironmentVariable ( "DOTNET_ENVIRONMENT" ) ) ;
73
+ }
74
+
75
+ private static DatabaseOperations CreateOperations ( string [ ] args )
76
+ {
13
77
var assembly = MockAssembly . Create ( typeof ( TestContext ) ) ;
14
- _ = new TestDatabaseOperations (
78
+ var operations = new DatabaseOperations (
15
79
new TestOperationReporter ( ) ,
16
80
assembly ,
17
81
assembly ,
18
82
"projectDir" ,
19
83
"RootNamespace" ,
20
84
"C#" ,
21
85
nullable : false ,
22
- args : null ) ;
86
+ args : args ) ;
87
+ return operations ;
23
88
}
24
89
25
90
public class TestContext : DbContext ;
0 commit comments