Support byte[] column type with new test for generic create command method (#8050)

This commit is contained in:
Mohammad Dameer
2018-05-11 22:08:52 +03:00
committed by Sébastien Ros
parent 91f0dac7dd
commit c1522d5b03
2 changed files with 22 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Data;
using System.IO;
using System.Linq;
using Autofac;
using NHibernate;
@@ -13,13 +14,11 @@ using Orchard.Environment.Configuration;
using Orchard.Environment.ShellBuilders.Models;
using Orchard.FileSystems.AppData;
using Orchard.Tests.ContentManagement;
using System.IO;
using Orchard.Tests.Environment;
using Orchard.Tests.FileSystems.AppData;
namespace Orchard.Tests.DataMigration
{
[TestFixture]
namespace Orchard.Tests.DataMigration {
[TestFixture]
public class SchemaBuilderTestsBase {
private IContainer _container;
private ISessionFactory _sessionFactory;
@@ -100,6 +99,21 @@ namespace Orchard.Tests.DataMigration
);
}
[Test]
public void GenericCreateCommandShouldBeHandled() {
_schemaBuilder
.CreateTable("User", table => table
.Column<int>("Id", column => column.PrimaryKey().Identity())
.Column<string>("Firstname", column => column.WithLength(255))
.Column<string>("Lastname", column => column.WithLength(100).NotNull())
.Column<string>("SN", column => column.WithLength(40).Unique())
.Column<decimal>("Salary", column => column.WithPrecision(9).WithScale(2))
.Column<decimal>("Gender", column => column.WithDefault(""))
.Column<Guid>("Identifier")
.Column<byte[]>("Photo", column => column.WithLength(2048))
);
}
[Test]
public void DropTableCommandShouldBeHandled() {
_schemaBuilder

View File

@@ -6,7 +6,7 @@ namespace Orchard.Data.Migration.Schema {
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1806:DoNotIgnoreMethodResults", MessageId = "System.Enum.TryParse<System.Data.DbType>(System.String,System.Boolean,System.Data.DbType@)")]
public static DbType ToDbType(Type type) {
DbType dbType;
switch ( Type.GetTypeCode(type) ) {
switch (Type.GetTypeCode(type)) {
case TypeCode.String:
dbType = DbType.String;
break;
@@ -20,8 +20,10 @@ namespace Orchard.Data.Migration.Schema {
dbType = DbType.Boolean;
break;
default:
if(type == typeof(Guid))
if (type == typeof(Guid))
dbType = DbType.Guid;
else if (type == typeof(byte[]))
dbType = DbType.Binary;
else
Enum.TryParse(Type.GetTypeCode(type).ToString(), true, out dbType);
break;