Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete removal of the System.Data.SqlClient. #931

Merged
merged 1 commit into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 6 additions & 130 deletions RepoDb.SqlServer/RepoDb.SqlServer.IntegrationTests/AttributeTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.Data.SqlClient;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RepoDb.Attributes;
using RepoDb.Attributes.Parameter.SqlServer;
using RepoDb.Extensions;
using RepoDb.SqlServer.IntegrationTests.Setup;
using System;
Expand Down Expand Up @@ -35,40 +35,19 @@ public class MdsAttributeTable
{
public int Id { get; set; }

[MicrosoftSqlServerTypeMap(SqlDbType.UniqueIdentifier)]
[SqlDbType(SqlDbType.UniqueIdentifier)]
public Guid SessionId { get; set; }

[MicrosoftSqlServerTypeMap(SqlDbType.Binary)]
[SqlDbType(SqlDbType.Binary)]
public byte[] ColumnBinary { get; set; }

[MicrosoftSqlServerTypeMap(SqlDbType.BigInt)]
[SqlDbType(SqlDbType.BigInt)]
public long ColumnBigInt { get; set; }

[MicrosoftSqlServerTypeMap(SqlDbType.DateTime2)]
[SqlDbType(SqlDbType.DateTime2)]
public DateTime ColumnDateTime2 { get; set; }

[MicrosoftSqlServerTypeMap(SqlDbType.Text)]
public string ColumnNVarChar { get; set; }
}

[Table("CompleteTable")]
public class SdsAttributeTable
{
public int Id { get; set; }

[SystemSqlServerTypeMap(SqlDbType.UniqueIdentifier)]
public Guid SessionId { get; set; }

[SystemSqlServerTypeMap(SqlDbType.Binary)]
public byte[] ColumnBinary { get; set; }

[SystemSqlServerTypeMap(SqlDbType.BigInt)]
public long ColumnBigInt { get; set; }

[SystemSqlServerTypeMap(SqlDbType.DateTime2)]
public DateTime ColumnDateTime2 { get; set; }

[SystemSqlServerTypeMap(SqlDbType.Text)]
[SqlDbType(SqlDbType.Text)]
public string ColumnNVarChar { get; set; }
}

Expand All @@ -93,23 +72,6 @@ private IEnumerable<MdsAttributeTable> CreateMdsAttributeTables(int count = 10)
}
}

private IEnumerable<SdsAttributeTable> CreateSdsAttributeTables(int count = 10)
{
var random = new Random();
for (var i = 0; i < count; i++)
{
yield return new SdsAttributeTable
{
Id = i,
ColumnBigInt = Convert.ToInt64(random.Next(int.MaxValue)),
ColumnBinary = Encoding.UTF8.GetBytes(Guid.NewGuid().ToString()),
ColumnDateTime2 = DateTime.UtcNow.AddDays(-random.Next(100)),
ColumnNVarChar = $"ColumnNVarChar-{i}-{Guid.NewGuid()}",
SessionId = Guid.NewGuid()
};
}
}

#endregion

#region MDS
Expand Down Expand Up @@ -197,91 +159,5 @@ public void TestSqlConnectionForQueryAllForMicrosoftSqlServerTypeMapAttribute()
}

#endregion

#region SDS

[TestMethod]
public void TestSqlConnectionForInsertForSystemSqlServerTypeMapAttribute()
{
// Setup
var table = CreateSdsAttributeTables(1).First();

using (var connection = new System.Data.SqlClient.SqlConnection(Database.ConnectionString))
{
// Act
connection.Insert<SdsAttributeTable>(table);

// Assert
Assert.AreEqual(1, connection.CountAll<SdsAttributeTable>());

// Query
var queryResult = connection.QueryAll<SdsAttributeTable>().First();

// Assert
Helper.AssertPropertiesEquality(table, queryResult);
}
}

[TestMethod]
public void TestSqlConnectionForInsertAllForSystemSqlServerTypeMapAttribute()
{
// Setup
var tables = CreateSdsAttributeTables(10).AsList();

using (var connection = new System.Data.SqlClient.SqlConnection(Database.ConnectionString))
{
// Act
connection.InsertAll<SdsAttributeTable>(tables);

// Assert
Assert.AreEqual(tables.Count, connection.CountAll<SdsAttributeTable>());

// Query
var queryResult = connection.QueryAll<SdsAttributeTable>();

// Assert
tables.ForEach(table => Helper.AssertPropertiesEquality(table, queryResult.First(e => e.Id == table.Id)));
}
}

[TestMethod]
public void TestSqlConnectionForQueryForSystemSqlServerTypeMapAttribute()
{
// Setup
var table = CreateSdsAttributeTables(1).First();

using (var connection = new System.Data.SqlClient.SqlConnection(Database.ConnectionString))
{
// Act
var id = connection.Insert<SdsAttributeTable>(table);

// Query
var queryResult = connection.Query<SdsAttributeTable>(id).First();

// Assert
Helper.AssertPropertiesEquality(table, queryResult);
}
}

[TestMethod]
public void TestSqlConnectionForQueryAllForSystemSqlServerTypeMapAttribute()
{
// Setup
var tables = CreateSdsAttributeTables(10).AsList();

using (var connection = new System.Data.SqlClient.SqlConnection(Database.ConnectionString))
{
// Act
connection.InsertAll<SdsAttributeTable>(tables);

// Query
var queryResult = connection.QueryAll<SdsAttributeTable>();

// Assert
Assert.AreEqual(tables.Count, queryResult.Count());
}
}

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Data.SqlClient;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RepoDb.Attributes;
using RepoDb.Extensions;
using RepoDb.SqlServer.IntegrationTests.Setup;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

Expand Down

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion RepoDb.SqlServer/RepoDb.SqlServer/RepoDb.SqlServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" Version="3.0.0" />
<PackageReference Include="RepoDb" Version="1.12.8" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
</ItemGroup>

<ItemGroup>
Expand Down
16 changes: 7 additions & 9 deletions RepoDb.SqlServer/RepoDb.SqlServer/SqlServerBootstrap.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using RepoDb.DbHelpers;
using Microsoft.Data.SqlClient;
using RepoDb.DbHelpers;
using RepoDb.DbSettings;
using RepoDb.StatementBuilders;

namespace RepoDb
{
/// <summary>
/// A class that is used to initialize the necessary settings for both the <see cref="Microsoft.Data.SqlClient.SqlConnection"/> and <see cref="System.Data.SqlClient.SqlConnection"/> objects.
/// A class that is being used to initialize the necessary settings for the <see cref="SqlConnection"/> object.
/// </summary>
public static class SqlServerBootstrap
{
Expand All @@ -21,7 +22,7 @@ public static class SqlServerBootstrap
#region Methods

/// <summary>
/// Initializes all necessary settings for SqlServer.
/// Initializes all the necessary settings for SQL Server.
/// </summary>
public static void Initialize()
{
Expand All @@ -33,18 +34,15 @@ public static void Initialize()

// Map the DbSetting
var dbSetting = new SqlServerDbSetting();
DbSettingMapper.Add<Microsoft.Data.SqlClient.SqlConnection>(dbSetting, true);
DbSettingMapper.Add<System.Data.SqlClient.SqlConnection>(dbSetting, true);
DbSettingMapper.Add<SqlConnection>(dbSetting, true);

// Map the DbHelper
var dbHelper = new SqlServerDbHelper();
DbHelperMapper.Add<Microsoft.Data.SqlClient.SqlConnection>(dbHelper, true);
DbHelperMapper.Add<System.Data.SqlClient.SqlConnection>(dbHelper, true);
DbHelperMapper.Add<SqlConnection>(dbHelper, true);

// Map the Statement Builder
var statementBuilder = new SqlServerStatementBuilder(dbSetting);
StatementBuilderMapper.Add<Microsoft.Data.SqlClient.SqlConnection>(statementBuilder, true);
StatementBuilderMapper.Add<System.Data.SqlClient.SqlConnection>(statementBuilder, true);
StatementBuilderMapper.Add<SqlConnection>(statementBuilder, true);

// Set the flag
IsInitialized = true;
Expand Down