Skip to content

Commit

Permalink
Integration tests for the #836
Browse files Browse the repository at this point in the history
  • Loading branch information
mikependon committed Aug 28, 2021
1 parent b7b30ab commit 35a80b5
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,34 @@ public void TestSqlConnectionExecuteNonQueryByExecutingAStoredProcedureWithMulti
}
}

[TestMethod]
public void TestSqlConnectionExecuteNonQueryByExecutingAStoredProcedureWithMultipleOutputParameters()
{
using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
{
// Setup
var userId = new DirectionalQueryField("UserId", typeof(int), ParameterDirection.Output);
var serverName = new DirectionalQueryField("ServerName", typeof(string), 256, ParameterDirection.Output);
var dateTimeUtc = new DirectionalQueryField("DateTimeUtc", typeof(DateTime), ParameterDirection.Output);
var param = new[]
{
userId,
serverName,
dateTimeUtc
};

// Act
var result = connection.ExecuteNonQuery("[dbo].[sp_get_server_info_with_output]",
param: param,
commandType: CommandType.StoredProcedure);

// Assert
Assert.AreEqual(1000, userId.GetValue<int>());
Assert.AreEqual("ServerName", serverName.GetValue<string>());
Assert.AreEqual(DateTime.Parse("1970-01-01 23:59:59.999"), dateTimeUtc.GetValue<DateTime>());
}
}

[TestMethod, ExpectedException(typeof(SqlException))]
public void ThrowExceptionOnTestSqlConnectionExecuteNonQueryIfTheParametersAreNotDefined()
{
Expand Down
31 changes: 31 additions & 0 deletions RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Setup/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ private static void CreateStoredProcedures()
CreateGetIdentityTableByIdStoredProcedure();
CreateMultiplyStoredProcedure();
CreateMultiplyWithOutputStoredProcedure();
CreateGetServerInfoWithOutputStoredProcedure();
CreateGetDatabaseDateTimeStoredProcedure();
CreateIdentityTableTypeStoredProcedure();
}
Expand Down Expand Up @@ -510,6 +511,36 @@ @Output INT OUTPUT
}
}

/// <summary>
/// Create a stored procedure that is used for multiplication.
/// </summary>
private static void CreateGetServerInfoWithOutputStoredProcedure()
{
using (var connection = new SqlConnection(ConnectionStringForRepoDb).EnsureOpen())
{
var exists = connection.ExecuteScalar("SELECT 1 FROM [sys].[objects] WHERE type = 'P' AND name = 'sp_get_server_info_with_output';");
if (exists == null)
{
var commandText = @"CREATE PROCEDURE [dbo].[sp_get_server_info_with_output]
(
@UserId INT OUTPUT,
@ServerName NVARCHAR(256) OUTPUT,
@DateTimeUtc DATETIME2(7) OUTPUT
)
AS
BEGIN
SET @UserId = 1000;
SET @ServerName = 'ServerName';
SET @DateTimeUtc = '1970-01-01 23:59:59.999';
SELECT @UserId AS [UserID]
, @ServerName AS [ServerName]
, @DateTimeUtc AS [DateTimeUtc];
END";
connection.ExecuteNonQuery(commandText);
}
}
}

/// <summary>
/// Creates the 'IdentityTableType' type.
/// </summary>
Expand Down

0 comments on commit 35a80b5

Please sign in to comment.