Commit 14a3d4a5 authored by Savorboard's avatar Savorboard

temporarily remove

parent 8294a586
......@@ -5,58 +5,58 @@ using Microsoft.EntityFrameworkCore;
namespace DotNetCore.CAP.EntityFrameworkCore.Test
{
public abstract class DatabaseTestHost : TestHost
{
private static bool _sqlObjectInstalled;
//public abstract class DatabaseTestHost : TestHost
//{
// private static bool _sqlObjectInstalled;
protected override void PostBuildServices()
{
base.PostBuildServices();
InitializeDatabase();
}
// protected override void PostBuildServices()
// {
// base.PostBuildServices();
// InitializeDatabase();
// }
public override void Dispose()
{
DeleteAllData();
base.Dispose();
}
// public override void Dispose()
// {
// DeleteAllData();
// base.Dispose();
// }
private void InitializeDatabase()
{
if (!_sqlObjectInstalled)
{
using (CreateScope())
{
var context = GetService<TestDbContext>();
context.Database.EnsureDeleted();
context.Database.Migrate();
_sqlObjectInstalled = true;
}
}
}
// private void InitializeDatabase()
// {
// if (!_sqlObjectInstalled)
// {
// using (CreateScope())
// {
// var context = GetService<TestDbContext>();
// context.Database.EnsureDeleted();
// context.Database.Migrate();
// _sqlObjectInstalled = true;
// }
// }
// }
private void DeleteAllData()
{
using (CreateScope())
{
var context = GetService<TestDbContext>();
// private void DeleteAllData()
// {
// using (CreateScope())
// {
// var context = GetService<TestDbContext>();
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(
"sp_MSforeachtable",
new {command1 = command},
commandType: CommandType.StoredProcedure);
}
}
}
}
// 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(
// "sp_MSforeachtable",
// new {command1 = command},
// commandType: CommandType.StoredProcedure);
// }
// }
// }
//}
}
\ No newline at end of file
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using DotNetCore.CAP.EntityFrameworkCore.Test;
namespace DotNetCore.CAP.EntityFrameworkCore.Test.Migrations
{
[DbContext(typeof(TestDbContext))]
[Migration("20170708050416_InitDB")]
partial class InitDB
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
modelBuilder
.HasAnnotation("ProductVersion", "1.1.2")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("DotNetCore.CAP.Infrastructure.CapReceivedMessage", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd();
b.Property<DateTime>("Added");
b.Property<string>("Content");
b.Property<string>("Group");
b.Property<string>("KeyName");
b.Property<DateTime>("LastRun");
b.Property<int>("Retries");
b.Property<string>("StatusName")
.HasMaxLength(50);
b.HasKey("Id");
b.ToTable("CapReceivedMessages");
});
modelBuilder.Entity("DotNetCore.CAP.Infrastructure.CapSentMessage", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd();
b.Property<DateTime>("Added");
b.Property<string>("Content");
b.Property<string>("KeyName");
b.Property<DateTime>("LastRun");
b.Property<int>("Retries");
b.Property<string>("StatusName")
.HasMaxLength(50);
b.HasKey("Id");
b.ToTable("CapSentMessages");
});
}
}
}
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Migrations;
namespace DotNetCore.CAP.EntityFrameworkCore.Test.Migrations
{
public partial class InitDB : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "CapReceivedMessages",
columns: table => new
{
Id = table.Column<string>(nullable: false),
Added = table.Column<DateTime>(nullable: false),
Content = table.Column<string>(nullable: true),
Group = table.Column<string>(nullable: true),
KeyName = table.Column<string>(nullable: true),
LastRun = table.Column<DateTime>(nullable: false),
Retries = table.Column<int>(nullable: false),
StatusName = table.Column<string>(maxLength: 50, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_CapReceivedMessages", x => x.Id);
});
migrationBuilder.CreateTable(
name: "CapSentMessages",
columns: table => new
{
Id = table.Column<string>(nullable: false),
Added = table.Column<DateTime>(nullable: false),
Content = table.Column<string>(nullable: true),
KeyName = table.Column<string>(nullable: true),
LastRun = table.Column<DateTime>(nullable: false),
Retries = table.Column<int>(nullable: false),
StatusName = table.Column<string>(maxLength: 50, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_CapSentMessages", x => x.Id);
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "CapReceivedMessages");
migrationBuilder.DropTable(
name: "CapSentMessages");
}
}
}
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using DotNetCore.CAP.EntityFrameworkCore.Test;
namespace DotNetCore.CAP.EntityFrameworkCore.Test.Migrations
{
[DbContext(typeof(TestDbContext))]
partial class TestDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
modelBuilder
.HasAnnotation("ProductVersion", "1.1.2")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("DotNetCore.CAP.Infrastructure.CapReceivedMessage", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd();
b.Property<DateTime>("Added");
b.Property<string>("Content");
b.Property<string>("Group");
b.Property<string>("KeyName");
b.Property<DateTime>("LastRun");
b.Property<int>("Retries");
b.Property<string>("StatusName")
.HasMaxLength(50);
b.HasKey("Id");
b.ToTable("CapReceivedMessages");
});
modelBuilder.Entity("DotNetCore.CAP.Infrastructure.CapSentMessage", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd();
b.Property<DateTime>("Added");
b.Property<string>("Content");
b.Property<string>("KeyName");
b.Property<DateTime>("LastRun");
b.Property<int>("Retries");
b.Property<string>("StatusName")
.HasMaxLength(50);
b.HasKey("Id");
b.ToTable("CapSentMessages");
});
}
}
}
using Microsoft.EntityFrameworkCore;
namespace DotNetCore.CAP.EntityFrameworkCore.Test
{
public class TestDbContext : CapDbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
var connectionString = ConnectionUtil.GetConnectionString();
optionsBuilder.UseSqlServer(connectionString);
}
}
}
\ No newline at end of file
......@@ -29,7 +29,7 @@ namespace DotNetCore.CAP.EntityFrameworkCore.Test
var connectionString = ConnectionUtil.GetConnectionString();
//services.AddSingleton(new SqlServerOptions { ConnectionString = connectionString });
services.AddDbContext<TestDbContext>(options => options.UseSqlServer(connectionString));
//services.AddDbContext<TestDbContext>(options => options.UseSqlServer(connectionString));
_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