Ver código fonte

temporarily remove

master
Savorboard 7 anos atrás
pai
commit
14a3d4a57c
7 arquivos alterados com 216 adições e 429 exclusões
  1. +49
    -49
      test/DotNetCore.CAP.EntityFrameworkCore.Test/DatabaseTestHost.cs
  2. +166
    -173
      test/DotNetCore.CAP.EntityFrameworkCore.Test/EFMessageStoreTest.cs
  3. +0
    -69
      test/DotNetCore.CAP.EntityFrameworkCore.Test/Migrations/20170708050416_InitDB.Designer.cs
  4. +0
    -56
      test/DotNetCore.CAP.EntityFrameworkCore.Test/Migrations/20170708050416_InitDB.cs
  5. +0
    -68
      test/DotNetCore.CAP.EntityFrameworkCore.Test/Migrations/TestDbContextModelSnapshot.cs
  6. +0
    -13
      test/DotNetCore.CAP.EntityFrameworkCore.Test/TestDbContext.cs
  7. +1
    -1
      test/DotNetCore.CAP.EntityFrameworkCore.Test/TestHost.cs

+ 49
- 49
test/DotNetCore.CAP.EntityFrameworkCore.Test/DatabaseTestHost.cs Ver arquivo

@@ -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);
// }
// }
// }
//}
}

+ 166
- 173
test/DotNetCore.CAP.EntityFrameworkCore.Test/EFMessageStoreTest.cs Ver arquivo

@@ -1,175 +1,168 @@
using System;
using System.Linq;
using DotNetCore.CAP.Infrastructure;
using DotNetCore.CAP.Models;
using Microsoft.Extensions.DependencyInjection;
using Xunit;

namespace DotNetCore.CAP.EntityFrameworkCore.Test
namespace DotNetCore.CAP.EntityFrameworkCore.Test
{
public class EFMessageStoreTest : DatabaseTestHost
{
[Fact]
public void CanCreateSentMessageUsingEF()
{
using (var db = CreateContext())
{
var guid = Guid.NewGuid().ToString();
var message = new CapSentMessage
{
Id = guid,
Content = "this is message body",
StatusName = StatusName.Enqueued
};
db.Attach(message).State = Microsoft.EntityFrameworkCore.EntityState.Added;
db.SaveChanges();
Assert.True(db.CapSentMessages.Any(u => u.Id == guid));
Assert.NotNull(db.CapSentMessages.FirstOrDefault(u => u.StatusName == StatusName.Enqueued));
}
}
[Fact]
public void CanUpdateSentMessageUsingEF()
{
using (var db = CreateContext())
{
var guid = Guid.NewGuid().ToString();
var message = new CapSentMessage
{
Id = guid,
Content = "this is message body",
StatusName = StatusName.Enqueued
};
db.Attach(message).State = Microsoft.EntityFrameworkCore.EntityState.Added;
db.SaveChanges();
var selectedMessage = db.CapSentMessages.FirstOrDefault(u => u.StatusName == StatusName.Enqueued);
Assert.NotNull(selectedMessage);
selectedMessage.StatusName = StatusName.Succeeded;
selectedMessage.Content = "Test";
db.SaveChanges();
selectedMessage = db.CapSentMessages.FirstOrDefault(u => u.StatusName == StatusName.Succeeded);
Assert.NotNull(selectedMessage);
Assert.True(selectedMessage.Content == "Test");
}
}
[Fact]
public void CanRemoveSentMessageUsingEF()
{
using (var db = CreateContext())
{
var guid = Guid.NewGuid().ToString();
var message = new CapSentMessage
{
Id = guid,
Content = "this is message body",
StatusName = StatusName.Enqueued
};
db.Attach(message).State = Microsoft.EntityFrameworkCore.EntityState.Added;
db.SaveChanges();
var selectedMessage = db.CapSentMessages.FirstOrDefault(u => u.StatusName == StatusName.Enqueued);
Assert.NotNull(selectedMessage);
db.CapSentMessages.Remove(selectedMessage);
db.SaveChanges();
selectedMessage = db.CapSentMessages.FirstOrDefault(u => u.StatusName == StatusName.Enqueued);
Assert.Null(selectedMessage);
}
}
[Fact]
public void CanCreateReceivedMessageUsingEF()
{
using (var db = CreateContext())
{
var guid = Guid.NewGuid().ToString();
var message = new CapReceivedMessage
{
Id = guid,
Content = "this is message body",
StatusName = StatusName.Enqueued
};
db.Attach(message).State = Microsoft.EntityFrameworkCore.EntityState.Added;
db.SaveChanges();
Assert.True(db.CapReceivedMessages.Any(u => u.Id == guid));
Assert.NotNull(db.CapReceivedMessages.FirstOrDefault(u => u.StatusName == StatusName.Enqueued));
}
}
[Fact]
public void CanUpdateReceivedMessageUsingEF()
{
using (var db = CreateContext())
{
var guid = Guid.NewGuid().ToString();
var message = new CapReceivedMessage
{
Id = guid,
Content = "this is message body",
StatusName = StatusName.Enqueued
};
db.Attach(message).State = Microsoft.EntityFrameworkCore.EntityState.Added;
db.SaveChanges();
var selectedMessage = db.CapReceivedMessages.FirstOrDefault(u => u.StatusName == StatusName.Enqueued);
Assert.NotNull(selectedMessage);
selectedMessage.StatusName = StatusName.Succeeded;
selectedMessage.Content = "Test";
db.SaveChanges();
selectedMessage = db.CapReceivedMessages.FirstOrDefault(u => u.StatusName == StatusName.Succeeded);
Assert.NotNull(selectedMessage);
Assert.True(selectedMessage.Content == "Test");
}
}
[Fact]
public void CanRemoveReceivedMessageUsingEF()
{
using (var db = CreateContext())
{
var guid = Guid.NewGuid().ToString();
var message = new CapReceivedMessage
{
Id = guid,
Content = "this is message body",
StatusName = StatusName.Enqueued
};
db.Attach(message).State = Microsoft.EntityFrameworkCore.EntityState.Added;
db.SaveChanges();
var selectedMessage = db.CapReceivedMessages.FirstOrDefault(u => u.StatusName == StatusName.Enqueued);
Assert.NotNull(selectedMessage);
db.CapReceivedMessages.Remove(selectedMessage);
db.SaveChanges();
selectedMessage = db.CapReceivedMessages.FirstOrDefault(u => u.StatusName == StatusName.Enqueued);
Assert.Null(selectedMessage);
}
}
public TestDbContext CreateContext(bool delete = false)
{
var db = Provider.GetRequiredService<TestDbContext>();
if (delete)
{
db.Database.EnsureDeleted();
}
db.Database.EnsureCreated();
return db;
}
}
//public class EFMessageStoreTest : DatabaseTestHost
//{
// [Fact]
// public void CanCreateSentMessageUsingEF()
// {
// using (var db = CreateContext())
// {
// var guid = Guid.NewGuid().ToString();
// var message = new CapPublishedMessage
// {
// Id = guid,
// Content = "this is message body",
// StatusName = StatusName.Enqueued
// };
// db.Attach(message).State = Microsoft.EntityFrameworkCore.EntityState.Added;
// db.SaveChanges();
// Assert.True(db.CapSentMessages.Any(u => u.Id == guid));
// Assert.NotNull(db.CapSentMessages.FirstOrDefault(u => u.StatusName == StatusName.Enqueued));
// }
// }
// [Fact]
// public void CanUpdateSentMessageUsingEF()
// {
// using (var db = CreateContext())
// {
// var guid = Guid.NewGuid().ToString();
// var message = new CapPublishedMessage
// {
// Id = guid,
// Content = "this is message body",
// StatusName = StatusName.Enqueued
// };
// db.Attach(message).State = Microsoft.EntityFrameworkCore.EntityState.Added;
// db.SaveChanges();
// var selectedMessage = db.CapSentMessages.FirstOrDefault(u => u.StatusName == StatusName.Enqueued);
// Assert.NotNull(selectedMessage);
// selectedMessage.StatusName = StatusName.Succeeded;
// selectedMessage.Content = "Test";
// db.SaveChanges();
// selectedMessage = db.CapSentMessages.FirstOrDefault(u => u.StatusName == StatusName.Succeeded);
// Assert.NotNull(selectedMessage);
// Assert.True(selectedMessage.Content == "Test");
// }
// }
// [Fact]
// public void CanRemoveSentMessageUsingEF()
// {
// using (var db = CreateContext())
// {
// var guid = Guid.NewGuid().ToString();
// var message = new CapPublishedMessage
// {
// Id = guid,
// Content = "this is message body",
// StatusName = StatusName.Enqueued
// };
// db.Attach(message).State = Microsoft.EntityFrameworkCore.EntityState.Added;
// db.SaveChanges();
// var selectedMessage = db.CapSentMessages.FirstOrDefault(u => u.StatusName == StatusName.Enqueued);
// Assert.NotNull(selectedMessage);
// db.CapSentMessages.Remove(selectedMessage);
// db.SaveChanges();
// selectedMessage = db.CapSentMessages.FirstOrDefault(u => u.StatusName == StatusName.Enqueued);
// Assert.Null(selectedMessage);
// }
// }
// [Fact]
// public void CanCreateReceivedMessageUsingEF()
// {
// using (var db = CreateContext())
// {
// var guid = Guid.NewGuid().ToString();
// var message = new CapReceivedMessage
// {
// Id = guid,
// Content = "this is message body",
// StatusName = StatusName.Enqueued
// };
// db.Attach(message).State = Microsoft.EntityFrameworkCore.EntityState.Added;
// db.SaveChanges();
// Assert.True(db.CapReceivedMessages.Any(u => u.Id == guid));
// Assert.NotNull(db.CapReceivedMessages.FirstOrDefault(u => u.StatusName == StatusName.Enqueued));
// }
// }
// [Fact]
// public void CanUpdateReceivedMessageUsingEF()
// {
// using (var db = CreateContext())
// {
// var guid = Guid.NewGuid().ToString();
// var message = new CapReceivedMessage
// {
// Id = guid,
// Content = "this is message body",
// StatusName = StatusName.Enqueued
// };
// db.Attach(message).State = Microsoft.EntityFrameworkCore.EntityState.Added;
// db.SaveChanges();
// var selectedMessage = db.CapReceivedMessages.FirstOrDefault(u => u.StatusName == StatusName.Enqueued);
// Assert.NotNull(selectedMessage);
// selectedMessage.StatusName = StatusName.Succeeded;
// selectedMessage.Content = "Test";
// db.SaveChanges();
// selectedMessage = db.CapReceivedMessages.FirstOrDefault(u => u.StatusName == StatusName.Succeeded);
// Assert.NotNull(selectedMessage);
// Assert.True(selectedMessage.Content == "Test");
// }
// }
// [Fact]
// public void CanRemoveReceivedMessageUsingEF()
// {
// using (var db = CreateContext())
// {
// var guid = Guid.NewGuid().ToString();
// var message = new CapReceivedMessage
// {
// Id = guid,
// Content = "this is message body",
// StatusName = StatusName.Enqueued
// };
// db.Attach(message).State = Microsoft.EntityFrameworkCore.EntityState.Added;
// db.SaveChanges();
// var selectedMessage = db.CapReceivedMessages.FirstOrDefault(u => u.StatusName == StatusName.Enqueued);
// Assert.NotNull(selectedMessage);
// db.CapReceivedMessages.Remove(selectedMessage);
// db.SaveChanges();
// selectedMessage = db.CapReceivedMessages.FirstOrDefault(u => u.StatusName == StatusName.Enqueued);
// Assert.Null(selectedMessage);
// }
// }
// public TestDbContext CreateContext(bool delete = false)
// {
// var db = Provider.GetRequiredService<TestDbContext>();
// if (delete)
// {
// db.Database.EnsureDeleted();
// }
// db.Database.EnsureCreated();
// return db;
// }
//}
}

+ 0
- 69
test/DotNetCore.CAP.EntityFrameworkCore.Test/Migrations/20170708050416_InitDB.Designer.cs Ver arquivo

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

+ 0
- 56
test/DotNetCore.CAP.EntityFrameworkCore.Test/Migrations/20170708050416_InitDB.cs Ver arquivo

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

+ 0
- 68
test/DotNetCore.CAP.EntityFrameworkCore.Test/Migrations/TestDbContextModelSnapshot.cs Ver arquivo

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

+ 0
- 13
test/DotNetCore.CAP.EntityFrameworkCore.Test/TestDbContext.cs Ver arquivo

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

+ 1
- 1
test/DotNetCore.CAP.EntityFrameworkCore.Test/TestHost.cs Ver arquivo

@@ -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;
}


Carregando…
Cancelar
Salvar