Skip to content

Commit

Permalink
Merge pull request #22 from FrendsPlatform/issue-20
Browse files Browse the repository at this point in the history
ExecuteQuery - Changed data type of QueryParameter.Value
  • Loading branch information
Svenskapojkarna authored Dec 4, 2023
2 parents 7ec6beb + d0cb9f8 commit 093a177
Show file tree
Hide file tree
Showing 12 changed files with 288 additions and 212 deletions.
4 changes: 4 additions & 0 deletions Frends.MicrosoftSQL.ExecuteQuery/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [1.2.0] - 2023-11-30
### Changed
- [Breaking] QueryParameter.Value type to object so that binary data can be used.

## [1.1.0] - 2023-01-27
### Changed
- Naming: Result.QueryResult to Result.Data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Frends.MicrosoftSQL.ExecuteQuery.Tests;
public class AutoUnitTests
{
/*
docker-compose up
docker-compose up -d
How to use via terminal:
docker exec -it sql1 "bash"
Expand All @@ -20,7 +20,7 @@ docker exec -it sql1 "bash"

private static readonly string _connString = "Server=127.0.0.1,1433;Database=Master;User Id=SA;Password=Salakala123!";
private static readonly string _tableName = "TestTable";

[TestInitialize]
public void Init()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ docker exec -it sql1 "bash"

private static readonly string _connString = "Server=127.0.0.1,1433;Database=Master;User Id=SA;Password=Salakala123!";
private static readonly string _tableName = "TestTable";

[TestInitialize]
public void Init()
{
Expand Down Expand Up @@ -83,4 +83,47 @@ public async Task TestExecuteQuery_Invalid_Creds_ReturnErrorMessage()
Assert.IsTrue(result.ErrorMessage.Contains("Login failed for user 'SA'."));
Assert.AreEqual(0, result.RecordsAffected);
}

[TestMethod]
public void TestExecuteQuery_ExceptionIsThrownWhenQueryFails()
{
var input = new Input()
{
Query = $"INSERT INTO {_tableName} VALUES (1, Unit, Tests, 456)",
ExecuteType = ExecuteTypes.NonQuery,
ConnectionString = _connString,
};

var options = new Options()
{
SqlTransactionIsolationLevel = SqlTransactionIsolationLevel.ReadCommitted,
CommandTimeoutSeconds = 2,
ThrowErrorOnFailure = true
};

var ex = Assert.ThrowsExceptionAsync<Exception>(async () => await MicrosoftSQL.ExecuteQuery(input, options, default));
Assert.IsTrue(ex.Result.Message.Contains("System.Data.SqlClient.SqlException (0x80131904): Invalid column name 'Unit'."));
}

[TestMethod]
public async Task TestExecuteQuery_ErrorMessageWhenQueryFails()
{
var input = new Input()
{
Query = $"INSERT INTO {_tableName} VALUES (1, Unit, Tests, 456)",
ExecuteType = ExecuteTypes.NonQuery,
ConnectionString = _connString,
};

var options = new Options()
{
SqlTransactionIsolationLevel = SqlTransactionIsolationLevel.ReadCommitted,
CommandTimeoutSeconds = 2,
ThrowErrorOnFailure = false
};

var result = await MicrosoftSQL.ExecuteQuery(input, options, default);
Assert.IsFalse(result.Success);
Assert.IsTrue(result.ErrorMessage.Contains("System.Data.SqlClient.SqlException (0x80131904): Invalid column name 'Unit'."));
}
}
Loading

0 comments on commit 093a177

Please sign in to comment.