Skip to content

Commit

Permalink
Linting fixes and added Tests for code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
RikuVirtanen committed Dec 1, 2023
1 parent d815d2a commit cfcea27
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'."));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -21,7 +21,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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// <summary>
/// SQL transaction isolation levels.
/// </summary>
public enum SqlTransactionIsolationLevel
public enum SqlTransactionIsolationLevel
{
/// <summary>
/// A different isolation level than the one specified is being used, but the level cannot be determined.
Expand All @@ -28,8 +28,8 @@ public enum SqlTransactionIsolationLevel
/// <summary>
/// A dirty read is possible, meaning that no shared locks are issued and no exclusive locks are honored.
/// </summary>
ReadUncommitted = 256,
ReadUncommitted = 256,

/// <summary>
/// Locks are placed on all data that is used in a query, preventing other users from updating the data.
/// Prevents non-repeatable reads but phantom rows are still possible.
Expand All @@ -40,12 +40,12 @@ public enum SqlTransactionIsolationLevel
/// A range lock is placed on the System.Data.DataSet, preventing other users from updating or inserting rows into the dataset until the transaction is complete.
/// </summary>
Serializable = 1048576,

/// <summary>
/// Reduces blocking by storing a version of data that one application can read while another is modifying the same data.
/// Indicates that from one transaction you cannot see changes made in other transactions, even if you requery.
/// </summary>
Snapshot = 16777216
Snapshot = 16777216,
}

/// <summary>
Expand Down

0 comments on commit cfcea27

Please sign in to comment.