mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Improved a data migration test to ensure the default values are written in the db
- Provides an example to check the db using a SQL query --HG-- branch : dev extra : transplant_source : %24%2B%3A%0D%E0%7F%D5%D1Wl%1Bx%13%017%ED%9A%D8%A6%D0
This commit is contained in:
@@ -26,6 +26,7 @@ namespace Orchard.Tests.DataMigration {
|
|||||||
private string _tempFolder;
|
private string _tempFolder;
|
||||||
private SchemaBuilder _schemaBuilder;
|
private SchemaBuilder _schemaBuilder;
|
||||||
private DefaultDataMigrationInterpreter _interpreter;
|
private DefaultDataMigrationInterpreter _interpreter;
|
||||||
|
private ISession _session;
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup() {
|
public void Setup() {
|
||||||
@@ -38,7 +39,7 @@ namespace Orchard.Tests.DataMigration {
|
|||||||
|
|
||||||
var builder = new ContainerBuilder();
|
var builder = new ContainerBuilder();
|
||||||
|
|
||||||
var session = _sessionFactory.OpenSession();
|
_session = _sessionFactory.OpenSession();
|
||||||
builder.RegisterInstance(appDataFolder).As<IAppDataFolder>();
|
builder.RegisterInstance(appDataFolder).As<IAppDataFolder>();
|
||||||
builder.RegisterType<SqlCeDataServicesProvider>().As<IDataServicesProvider>();
|
builder.RegisterType<SqlCeDataServicesProvider>().As<IDataServicesProvider>();
|
||||||
builder.RegisterType<DataServicesProviderFactory>().As<IDataServicesProviderFactory>();
|
builder.RegisterType<DataServicesProviderFactory>().As<IDataServicesProviderFactory>();
|
||||||
@@ -46,7 +47,7 @@ namespace Orchard.Tests.DataMigration {
|
|||||||
builder.RegisterType<DefaultDataMigrationInterpreter>().As<IDataMigrationInterpreter>();
|
builder.RegisterType<DefaultDataMigrationInterpreter>().As<IDataMigrationInterpreter>();
|
||||||
builder.RegisterType<SessionConfigurationCache>().As<ISessionConfigurationCache>();
|
builder.RegisterType<SessionConfigurationCache>().As<ISessionConfigurationCache>();
|
||||||
builder.RegisterType<SessionFactoryHolder>().As<ISessionFactoryHolder>();
|
builder.RegisterType<SessionFactoryHolder>().As<ISessionFactoryHolder>();
|
||||||
builder.RegisterInstance(new DefaultContentManagerTests.TestSessionLocator(session)).As<ISessionLocator>();
|
builder.RegisterInstance(new DefaultContentManagerTests.TestSessionLocator(_session)).As<ISessionLocator>();
|
||||||
builder.RegisterInstance(new ShellBlueprint { Records = Enumerable.Empty<RecordBlueprint>() }).As<ShellBlueprint>();
|
builder.RegisterInstance(new ShellBlueprint { Records = Enumerable.Empty<RecordBlueprint>() }).As<ShellBlueprint>();
|
||||||
builder.RegisterInstance(new ShellSettings { Name = "temp", DataProvider = "SqlCe", DataTablePrefix = "TEST" }).As<ShellSettings>();
|
builder.RegisterInstance(new ShellSettings { Name = "temp", DataProvider = "SqlCe", DataTablePrefix = "TEST" }).As<ShellSettings>();
|
||||||
builder.RegisterModule(new DataModule());
|
builder.RegisterModule(new DataModule());
|
||||||
@@ -133,10 +134,24 @@ namespace Orchard.Tests.DataMigration {
|
|||||||
.AlterTable("User", table => table
|
.AlterTable("User", table => table
|
||||||
.AddColumn("Age", DbType.Int32))
|
.AddColumn("Age", DbType.Int32))
|
||||||
.AlterTable("User", table => table
|
.AlterTable("User", table => table
|
||||||
.AlterColumn("Lastname", column => column.WithDefault("John")))
|
.AlterColumn("Lastname", column => column.WithDefault("Doe")))
|
||||||
.AlterTable("User", table => table
|
.AlterTable("User", table => table
|
||||||
.DropColumn("Firstname")
|
.DropColumn("Firstname")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// creating a new row should assign a default value to Firstname and Age
|
||||||
|
_schemaBuilder
|
||||||
|
.ExecuteSql("insert into TEST_User VALUES (DEFAULT, DEFAULT)");
|
||||||
|
|
||||||
|
// ensure wehave one record woth the default value
|
||||||
|
var command = _session.Connection.CreateCommand();
|
||||||
|
command.CommandText = "SELECT count(*) FROM TEST_User WHERE Lastname = 'Doe'";
|
||||||
|
Assert.That(command.ExecuteScalar(), Is.EqualTo(1));
|
||||||
|
|
||||||
|
// ensure this is not a false positive
|
||||||
|
command = _session.Connection.CreateCommand();
|
||||||
|
command.CommandText = "SELECT count(*) FROM TEST_User WHERE Lastname = 'Foo'";
|
||||||
|
Assert.That(command.ExecuteScalar(), Is.EqualTo(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
Reference in New Issue
Block a user