1
- using System . Diagnostics ;
1
+ using System ;
2
+ using System . Data . Odbc ;
2
3
using System . IO ;
3
4
using Microsoft . VisualStudio . TestTools . UnitTesting ;
4
5
@@ -25,31 +26,67 @@ public void TearDown()
25
26
public void CreateAndDropDatabaseFromConnection ( )
26
27
{
27
28
using var connection = new JetConnection ( StoreName , Helpers . DataAccessProviderFactory ) ;
29
+
28
30
connection . CreateDatabase ( ) ;
29
-
30
31
Assert . IsTrue ( File . Exists ( StoreName ) ) ;
31
-
32
- using var command = connection . CreateCommand ( ) ;
33
- command . CommandText = "DROP DATABASE " + StoreName ;
34
- command . ExecuteNonQuery ( ) ;
35
-
32
+
33
+ connection . DropDatabase ( ) ;
36
34
Assert . IsFalse ( File . Exists ( StoreName ) ) ;
37
35
}
38
36
39
37
[ TestMethod ]
40
38
public void CreateAndDropDatabaseWithUnsetConnection ( )
41
39
{
42
- using var connection = new JetConnection ( ) ;
40
+ using var connection = new JetConnection ( Helpers . DataAccessProviderFactory ) ;
43
41
44
42
var command = connection . CreateCommand ( ) ;
45
- command . CommandText = "CREATE DATABASE " + StoreName ;
43
+ command . CommandText = $ "CREATE DATABASE ' { StoreName } '" ;
46
44
command . ExecuteNonQuery ( ) ;
47
-
48
45
Assert . IsTrue ( File . Exists ( StoreName ) ) ;
49
46
50
- command . CommandText = "DROP DATABASE " + StoreName ;
47
+ command . CommandText = $ "DROP DATABASE ' { StoreName } '" ;
51
48
command . ExecuteNonQuery ( ) ;
49
+ Assert . IsFalse ( File . Exists ( StoreName ) ) ;
50
+ }
51
+
52
+ [ TestMethod ]
53
+ public void CreateAndDropDatabaseWithUnsetConnectionWithoutDataAccessProviderFactoryThrows ( )
54
+ {
55
+ using var connection = new JetConnection ( ) ;
56
+
57
+ Assert . ThrowsException < InvalidOperationException > (
58
+ ( ) => { using var command = connection . CreateCommand ( ) ; } ) ;
59
+ }
60
+
61
+ [ TestMethod ]
62
+ public void CreateAndDropDatabaseWithSingleQuotedConnectionString ( )
63
+ {
64
+ var connectionString = Helpers . DataAccessProviderFactory is OdbcFactory
65
+ ? $ "DBQ='{ StoreName } '"
66
+ : $ "Data Source='{ StoreName } '";
67
+
68
+ using var connection = new JetConnection ( connectionString , Helpers . DataAccessProviderFactory ) ;
69
+
70
+ connection . CreateDatabase ( ) ;
71
+ Assert . IsTrue ( File . Exists ( StoreName ) ) ;
72
+
73
+ connection . DropDatabase ( ) ;
74
+ Assert . IsFalse ( File . Exists ( StoreName ) ) ;
75
+ }
76
+
77
+ [ TestMethod ]
78
+ public void CreateAndDropDatabaseWithDoubleQuotedConnectionString ( )
79
+ {
80
+ var connectionString = Helpers . DataAccessProviderFactory is OdbcFactory
81
+ ? $ "DBQ=\" { StoreName } \" "
82
+ : $ "Data Source=\" { StoreName } \" ";
52
83
84
+ using var connection = new JetConnection ( connectionString , Helpers . DataAccessProviderFactory ) ;
85
+
86
+ connection . CreateDatabase ( ) ;
87
+ Assert . IsTrue ( File . Exists ( StoreName ) ) ;
88
+
89
+ connection . DropDatabase ( ) ;
53
90
Assert . IsFalse ( File . Exists ( StoreName ) ) ;
54
91
}
55
92
}
0 commit comments