Skip to content

Commit 093a177

Browse files
Merge pull request #22 from FrendsPlatform/issue-20
ExecuteQuery - Changed data type of QueryParameter.Value
2 parents 7ec6beb + d0cb9f8 commit 093a177

File tree

12 files changed

+288
-212
lines changed

12 files changed

+288
-212
lines changed

Frends.MicrosoftSQL.ExecuteQuery/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [1.2.0] - 2023-11-30
4+
### Changed
5+
- [Breaking] QueryParameter.Value type to object so that binary data can be used.
6+
37
## [1.1.0] - 2023-01-27
48
### Changed
59
- Naming: Result.QueryResult to Result.Data.

Frends.MicrosoftSQL.ExecuteQuery/Frends.MicrosoftSQL.ExecuteQuery.Tests/AutoUnitTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Frends.MicrosoftSQL.ExecuteQuery.Tests;
99
public class AutoUnitTests
1010
{
1111
/*
12-
docker-compose up
12+
docker-compose up -d
1313
1414
How to use via terminal:
1515
docker exec -it sql1 "bash"
@@ -20,7 +20,7 @@ docker exec -it sql1 "bash"
2020

2121
private static readonly string _connString = "Server=127.0.0.1,1433;Database=Master;User Id=SA;Password=Salakala123!";
2222
private static readonly string _tableName = "TestTable";
23-
23+
2424
[TestInitialize]
2525
public void Init()
2626
{

Frends.MicrosoftSQL.ExecuteQuery/Frends.MicrosoftSQL.ExecuteQuery.Tests/ExceptionUnitTests.cs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)