--HG--
branch : theming
This commit is contained in:
Louis DeJardin
2010-09-14 12:31:53 -07:00
5 changed files with 79 additions and 8 deletions

View File

@@ -1,4 +1,5 @@
using System.Data;
using System;
using System.Data;
using System.Linq;
using Autofac;
using NHibernate;
@@ -37,8 +38,6 @@ namespace Orchard.Tests.DataMigration {
var builder = new ContainerBuilder();
builder.RegisterInstance(new ShellSettings { DataTablePrefix = "TEST_", DataProvider = "SqlCe" });
var session = _sessionFactory.OpenSession();
builder.RegisterInstance(appDataFolder).As<IAppDataFolder>();
builder.RegisterType<SqlCeDataServicesProvider>().As<IDataServicesProvider>();
@@ -49,7 +48,7 @@ namespace Orchard.Tests.DataMigration {
builder.RegisterType<SessionFactoryHolder>().As<ISessionFactoryHolder>();
builder.RegisterInstance(new DefaultContentManagerTests.TestSessionLocator(session)).As<ISessionLocator>();
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());
_container = builder.Build();
@@ -154,6 +153,61 @@ namespace Orchard.Tests.DataMigration {
.Column("UserId", DbType.Int32, column => column.NotNull()))
.CreateForeignKey("FK_User", "Address", new[] { "UserId" }, "User", new[] { "Id" })
.DropForeignKey("Address", "FK_User");
}
[Test, ExpectedException]
public void BiggerDataShouldNotFit() {
_schemaBuilder
.CreateTable("ContentItemRecord", table => table
.Column("Id", DbType.Int32, column => column.PrimaryKey().Identity())
.Column("Data", DbType.String, column => column.WithLength(255)));
// should write successfully less than 255 chars
_schemaBuilder
.ExecuteSql("insert into TEST_ContentItemRecord (Data) values('Hello World')");
// should throw an exception if trying to write more data
_schemaBuilder
.ExecuteSql(String.Format("insert into TEST_ContentItemRecord (Data) values('{0}')", new String('x', 256)));
_schemaBuilder
.AlterTable("ContentItemRecord", table => table
.AlterColumn("Data", column => column.WithType(DbType.String).WithLength(257)));
_schemaBuilder
.ExecuteSql(String.Format("insert into TEST_ContentItemRecord (Data) values('{0}')", new String('x', 256)));
}
[Test]
public void ShouldAllowFieldSizeAlteration() {
_schemaBuilder
.CreateTable("ContentItemRecord", table => table
.Column("Id", DbType.Int32, column => column.PrimaryKey().Identity())
.Column("Data", DbType.String, column => column.WithLength(255)));
// should write successfully less than 255 chars
_schemaBuilder
.ExecuteSql("insert into TEST_ContentItemRecord (Data) values('Hello World')");
_schemaBuilder
.AlterTable("ContentItemRecord", table => table
.AlterColumn("Data", column => column.WithType(DbType.String).WithLength(2048)));
// should write successfully a bigger value now
_schemaBuilder
.ExecuteSql(String.Format("insert into TEST_ContentItemRecord (Data) values('{0}')", new String('x', 2048)));
}
[Test, ExpectedException(typeof(OrchardException))]
public void ChangingSizeWithoutTypeShouldNotBeAllowed() {
_schemaBuilder
.CreateTable("ContentItemRecord", table => table
.Column("Id", DbType.Int32, column => column.PrimaryKey().Identity())
.Column("Data", DbType.String, column => column.WithLength(255)));
_schemaBuilder
.AlterTable("ContentItemRecord", table => table
.AlterColumn("Data", column => column.WithLength(2048)));
}
}

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using Orchard.ContentManagement;
@@ -46,6 +47,9 @@ namespace Orchard.Tags.Handlers {
}
});
OnIndexing<TagsPart>((context, tagsPart) => context.DocumentIndex
.Add("tags", String.Join(", ", tagsPart.CurrentTags.Select(t => t.TagName))).Analyze());
}
}
}

View File

@@ -8,7 +8,6 @@
\Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration>
<configSections>
<sectionGroup name="system.razor.web" type="System.Razor.Web.Configuration.SystemRazorWebSectionGroup, System.Razor.Web">
<section name="host" type="System.Razor.Web.Configuration.HostSection, System.Razor.Web" requirePermission="false" />

View File

@@ -1,4 +1,5 @@
using Orchard.Data.Migration;
using System.Data;
using Orchard.Data.Migration;
namespace Orchard.ContentManagement.DataMigrations {
public class FrameworkDataMigration : DataMigrationImpl {
@@ -35,5 +36,13 @@ namespace Orchard.ContentManagement.DataMigrations {
return 1;
}
public int UpdateFrom1() {
SchemaBuilder
.AlterTable("ContentItemRecord", table => table
.AlterColumn("Data", column => column.WithType(DbType.String).Unlimited()));
return 2;
}
}
}

View File

@@ -39,7 +39,7 @@ namespace Orchard.Data.Migration.Interpreters {
_reportsCoordinator = reportsCoordinator;
Logger = NullLogger.Instance;
T = NullLocalizer.Instance;
var configuration = _sessionFactoryHolder.GetConfiguration();
_dialect = Dialect.GetDialect(configuration.Properties);
}
@@ -192,6 +192,11 @@ namespace Orchard.Data.Migration.Interpreters {
if (command.DbType != DbType.Object) {
builder.Append(GetTypeName(command.DbType, command.Length, command.Precision, command.Scale));
}
else {
if(command.Length > 0 || command.Precision > 0 || command.Scale > 0) {
throw new OrchardException(T("Error while executing data migration: you need to specify the field's type in order to change it's properies"));
}
}
// [default value]
if (!string.IsNullOrEmpty(command.Default)) {