Browse Source

modify unit tests.

master
Savorboard 7 years ago
parent
commit
7bcc2e9f1d
5 changed files with 7 additions and 25 deletions
  1. +0
    -1
      src/DotNetCore.CAP.SqlServer/SqlServerStorage.cs
  2. +6
    -6
      test/DotNetCore.CAP.SqlServer.Test/DatabaseTestHost.cs
  3. +0
    -2
      test/DotNetCore.CAP.SqlServer.Test/DotNetCore.CAP.SqlServer.Test.csproj
  4. +0
    -13
      test/DotNetCore.CAP.SqlServer.Test/TestDbContext.cs
  5. +1
    -3
      test/DotNetCore.CAP.SqlServer.Test/TestHost.cs

+ 0
- 1
src/DotNetCore.CAP.SqlServer/SqlServerStorage.cs View File

@@ -2,7 +2,6 @@ using System.Data.SqlClient;
using System.Threading;
using System.Threading.Tasks;
using Dapper;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;

namespace DotNetCore.CAP.SqlServer


+ 6
- 6
test/DotNetCore.CAP.SqlServer.Test/DatabaseTestHost.cs View File

@@ -1,4 +1,5 @@
using System.Data;
using System.Data.SqlClient;
using System.Threading;
using Dapper;
using Microsoft.EntityFrameworkCore;
@@ -54,21 +55,20 @@ CREATE DATABASE [{databaseName}];");

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 ?",
"ALTER TABLE ? NOCHECK CONSTRAINT ALL",
"DELETE FROM ?",
"ALTER TABLE ? CHECK CONSTRAINT ALL",
"ENABLE TRIGGER ALL ON ?"
};

foreach (var command in commands)
{
context.Database.GetDbConnection().Execute(
connection.Execute(
"sp_MSforeachtable",
new { command1 = command },
commandType: CommandType.StoredProcedure);


+ 0
- 2
test/DotNetCore.CAP.SqlServer.Test/DotNetCore.CAP.SqlServer.Test.csproj View File

@@ -27,8 +27,6 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Json" 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="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.0" />
</ItemGroup>

</Project>

+ 0
- 13
test/DotNetCore.CAP.SqlServer.Test/TestDbContext.cs View File

@@ -1,13 +0,0 @@
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);
}
}
}

+ 1
- 3
test/DotNetCore.CAP.SqlServer.Test/TestHost.cs View File

@@ -1,5 +1,4 @@
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;

namespace DotNetCore.CAP.SqlServer.Test
@@ -30,8 +29,7 @@ namespace DotNetCore.CAP.SqlServer.Test

_connectionString = ConnectionUtil.GetConnectionString();
services.AddSingleton(new SqlServerOptions { ConnectionString = _connectionString });
services.AddSingleton<SqlServerStorage>();
services.AddDbContext<TestDbContext>(options => options.UseSqlServer(_connectionString));
services.AddSingleton<SqlServerStorage>();

_services = services;
}


Loading…
Cancel
Save