@@ -19,7 +19,7 @@ docker exec -it sql1 "bash"
1919
2020 private static readonly string _connString = "Server=127.0.0.1,1433;Database=Master;User Id=SA;Password=Salakala123!" ;
2121 private static readonly string _tableName = "TestTable" ;
22-
22+
2323 [ TestInitialize ]
2424 public void Init ( )
2525 {
@@ -83,4 +83,47 @@ public async Task TestExecuteQuery_Invalid_Creds_ReturnErrorMessage()
8383 Assert . IsTrue ( result . ErrorMessage . Contains ( "Login failed for user 'SA'." ) ) ;
8484 Assert . AreEqual ( 0 , result . RecordsAffected ) ;
8585 }
86+
87+ [ TestMethod ]
88+ public void TestExecuteQuery_ExceptionIsThrownWhenQueryFails ( )
89+ {
90+ var input = new Input ( )
91+ {
92+ Query = $ "INSERT INTO { _tableName } VALUES (1, Unit, Tests, 456)",
93+ ExecuteType = ExecuteTypes . NonQuery ,
94+ ConnectionString = _connString ,
95+ } ;
96+
97+ var options = new Options ( )
98+ {
99+ SqlTransactionIsolationLevel = SqlTransactionIsolationLevel . ReadCommitted ,
100+ CommandTimeoutSeconds = 2 ,
101+ ThrowErrorOnFailure = true
102+ } ;
103+
104+ var ex = Assert . ThrowsExceptionAsync < Exception > ( async ( ) => await MicrosoftSQL . ExecuteQuery ( input , options , default ) ) ;
105+ Assert . IsTrue ( ex . Result . Message . Contains ( "System.Data.SqlClient.SqlException (0x80131904): Invalid column name 'Unit'." ) ) ;
106+ }
107+
108+ [ TestMethod ]
109+ public async Task TestExecuteQuery_ErrorMessageWhenQueryFails ( )
110+ {
111+ var input = new Input ( )
112+ {
113+ Query = $ "INSERT INTO { _tableName } VALUES (1, Unit, Tests, 456)",
114+ ExecuteType = ExecuteTypes . NonQuery ,
115+ ConnectionString = _connString ,
116+ } ;
117+
118+ var options = new Options ( )
119+ {
120+ SqlTransactionIsolationLevel = SqlTransactionIsolationLevel . ReadCommitted ,
121+ CommandTimeoutSeconds = 2 ,
122+ ThrowErrorOnFailure = false
123+ } ;
124+
125+ var result = await MicrosoftSQL . ExecuteQuery ( input , options , default ) ;
126+ Assert . IsFalse ( result . Success ) ;
127+ Assert . IsTrue ( result . ErrorMessage . Contains ( "System.Data.SqlClient.SqlException (0x80131904): Invalid column name 'Unit'." ) ) ;
128+ }
86129}
0 commit comments