Commit 7bcc2e9f authored by Savorboard's avatar Savorboard

modify unit tests.

parent 12632529
...@@ -2,7 +2,6 @@ using System.Data.SqlClient; ...@@ -2,7 +2,6 @@ using System.Data.SqlClient;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Dapper; using Dapper;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace DotNetCore.CAP.SqlServer namespace DotNetCore.CAP.SqlServer
......
using System.Data; using System.Data;
using System.Data.SqlClient;
using System.Threading; using System.Threading;
using Dapper; using Dapper;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
...@@ -54,21 +55,20 @@ CREATE DATABASE [{databaseName}];"); ...@@ -54,21 +55,20 @@ CREATE DATABASE [{databaseName}];");
private void DeleteAllData() private void DeleteAllData()
{ {
using (CreateScope()) var conn = ConnectionUtil.GetConnectionString();
using (var connection = new SqlConnection(conn))
{ {
var context = GetService<TestDbContext>(); var commands = new[] {
var commands = new[]
{
"DISABLE TRIGGER ALL ON ?", "DISABLE TRIGGER ALL ON ?",
"ALTER TABLE ? NOCHECK CONSTRAINT ALL", "ALTER TABLE ? NOCHECK CONSTRAINT ALL",
"DELETE FROM ?", "DELETE FROM ?",
"ALTER TABLE ? CHECK CONSTRAINT ALL", "ALTER TABLE ? CHECK CONSTRAINT ALL",
"ENABLE TRIGGER ALL ON ?" "ENABLE TRIGGER ALL ON ?"
}; };
foreach (var command in commands) foreach (var command in commands)
{ {
context.Database.GetDbConnection().Execute( connection.Execute(
"sp_MSforeachtable", "sp_MSforeachtable",
new { command1 = command }, new { command1 = command },
commandType: CommandType.StoredProcedure); commandType: CommandType.StoredProcedure);
......
...@@ -27,8 +27,6 @@ ...@@ -27,8 +27,6 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.0.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.4.0" /> <PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>
using Microsoft.EntityFrameworkCore;
namespace DotNetCore.CAP.SqlServer.Test
{
public class TestDbContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
var connectionString = ConnectionUtil.GetConnectionString();
optionsBuilder.UseSqlServer(connectionString);
}
}
}
\ No newline at end of file
using System; using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
namespace DotNetCore.CAP.SqlServer.Test namespace DotNetCore.CAP.SqlServer.Test
...@@ -30,8 +29,7 @@ namespace DotNetCore.CAP.SqlServer.Test ...@@ -30,8 +29,7 @@ namespace DotNetCore.CAP.SqlServer.Test
_connectionString = ConnectionUtil.GetConnectionString(); _connectionString = ConnectionUtil.GetConnectionString();
services.AddSingleton(new SqlServerOptions { ConnectionString = _connectionString }); services.AddSingleton(new SqlServerOptions { ConnectionString = _connectionString });
services.AddSingleton<SqlServerStorage>(); services.AddSingleton<SqlServerStorage>();
services.AddDbContext<TestDbContext>(options => options.UseSqlServer(_connectionString));
_services = services; _services = services;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment