This repository has been archived by the owner on Dec 24, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
22652f5
commit 86bbacb
Showing
3 changed files
with
247 additions
and
0 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
src/ServiceStack.OrmLite.DDLTest/ServiceStack.OrmLite.DDLTest.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProductVersion>12.0.0</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{E106F587-2DFF-4550-BA49-9A81A2EC344F}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<RootNamespace>ServiceStack.OrmLite.DDLTest</RootNamespace> | ||
<AssemblyName>ServiceStack.OrmLite.DDLTest</AssemblyName> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>True</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>False</Optimize> | ||
<OutputPath>bin\Debug</OutputPath> | ||
<DefineConstants>DEBUG;</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<ConsolePause>False</ConsolePause> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>none</DebugType> | ||
<Optimize>True</Optimize> | ||
<OutputPath>bin\Release</OutputPath> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<ConsolePause>False</ConsolePause> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="nunit.framework"> | ||
<HintPath>..\..\lib\tests\nunit.framework.dll</HintPath> | ||
</Reference> | ||
<Reference Include="FirebirdSql.Data.FirebirdClient"> | ||
<HintPath>..\..\lib\FirebirdSql.Data.FirebirdClient.dll</HintPath> | ||
</Reference> | ||
<Reference Include="MySql.Data"> | ||
<HintPath>..\..\lib\MySql.Data.dll</HintPath> | ||
</Reference> | ||
<Reference Include="ServiceStack.Common"> | ||
<HintPath>..\..\lib\ServiceStack.Common.dll</HintPath> | ||
</Reference> | ||
<Reference Include="ServiceStack.Interfaces"> | ||
<HintPath>..\..\lib\ServiceStack.Interfaces.dll</HintPath> | ||
</Reference> | ||
<Reference Include="ServiceStack.Text"> | ||
<HintPath>..\..\lib\ServiceStack.Text.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.ComponentModel.DataAnnotations" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Test.cs" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> | ||
<ItemGroup> | ||
<ProjectReference Include="..\ServiceStack.OrmLite\ServiceStack.OrmLite.csproj"> | ||
<Project>{96179AC6-F6F1-40C3-9FDD-4F6582F54C5C}</Project> | ||
<Name>ServiceStack.OrmLite</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\ServiceStack.OrmLite.Firebird\ServiceStack.OrmLite.Firebird.csproj"> | ||
<Project>{317B64BA-D7A6-4A15-8719-821B38147C63}</Project> | ||
<Name>ServiceStack.OrmLite.Firebird</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\ServiceStack.OrmLite.MySql\ServiceStack.OrmLite.MySql.csproj"> | ||
<Project>{FD20F088-ACC0-4979-AC0C-8C541C2E7DE5}</Project> | ||
<Name>ServiceStack.OrmLite.MySql</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
using System; | ||
using NUnit.Framework; | ||
using ServiceStack.OrmLite; | ||
using ServiceStack.OrmLite.Firebird; | ||
using ServiceStack.OrmLite.MySql; | ||
using System.Collections.Generic; | ||
using ServiceStack.Logging; | ||
using ServiceStack.Logging.Support.Logging; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace ServiceStack.OrmLite.DDLTest | ||
{ | ||
|
||
|
||
[TestFixture()] | ||
public class Test | ||
{ | ||
List<Dialect> dialects = new List<Dialect>(); | ||
|
||
[TestFixtureSetUp] | ||
public void TestFixtureSetup() | ||
{ | ||
dialects.Add ( new Dialect{ | ||
Provider= FirebirdOrmLiteDialectProvider.Instance, | ||
AddColumnString="ALTER TABLE Model ADD Column1 VARCHAR(128) ;", | ||
AlterColumnString="ALTER TABLE Model ALTER Column2 VARCHAR(50) ;", | ||
ChangeColumnNameString="ALTER TABLE Model ALTER OldColumn3 TO Column3 ;", | ||
AddFKString="ALTER TABLE Child ADD CONSTRAINT JustOneFK FOREIGN KEY (IdModel) REFERENCES Model (Id) ON UPDATE NO ACTION ON DELETE CASCADE;", | ||
CreateIndexString="CREATE UNIQUE INDEX JustIndexOnColumn3 ON Model(Column3);" | ||
|
||
}); | ||
dialects.Add ( new Dialect{ | ||
Provider= MySqlDialectProvider.Instance, | ||
AddColumnString="ALTER TABLE `Model` ADD COLUMN `Column1` VARCHAR(255) NULL;", | ||
AlterColumnString="ALTER TABLE `Model` MODIFY COLUMN `Column2` VARCHAR(50) NULL;", | ||
ChangeColumnNameString="ALTER TABLE `Model` CHANGE COLUMN `OldColumn3` `Column3` VARCHAR(255) NULL;", | ||
AddFKString="ALTER TABLE `Child` ADD CONSTRAINT `JustOneFK` FOREIGN KEY (`IdModel`) REFERENCES `Model` (`Id`) ON UPDATE NO ACTION ON DELETE CASCADE;", | ||
CreateIndexString="CREATE UNIQUE INDEX `JustIndexOnColumn3` ON `Model`(`Column3`);" | ||
}); | ||
|
||
LogManager.LogFactory = new ConsoleLogFactory(); | ||
} | ||
|
||
[Test()] | ||
public void CanAddColumn () | ||
{ | ||
var model = typeof(Model); | ||
|
||
foreach (var d in dialects) | ||
{ | ||
OrmLiteConfig.DialectProvider=d.Provider; | ||
var fielDef = ModelDefinition<Model>.Definition.GetFieldDefinition<Model> (f => f.Column1); | ||
Assert.AreEqual(d.AddColumnString, (d.Provider.ToAddColumnStatement(model, fielDef))); | ||
} | ||
} | ||
|
||
[Test()] | ||
public void CanAAlterColumn () | ||
{ | ||
var model = typeof(Model); | ||
|
||
foreach (var d in dialects) | ||
{ | ||
OrmLiteConfig.DialectProvider=d.Provider; | ||
var fielDef = ModelDefinition<Model>.Definition.GetFieldDefinition<Model> (f => f.Column2); | ||
Assert.AreEqual(d.AlterColumnString, (d.Provider.ToAlterColumnStatement(model, fielDef))); | ||
} | ||
|
||
} | ||
|
||
|
||
[Test()] | ||
public void CanChangeColumnName () | ||
{ | ||
var model = typeof(Model); | ||
|
||
foreach (var d in dialects) | ||
{ | ||
OrmLiteConfig.DialectProvider=d.Provider; | ||
var fielDef = ModelDefinition<Model>.Definition.GetFieldDefinition<Model> (f => f.Column3); | ||
Assert.AreEqual(d.ChangeColumnNameString,(d.Provider.ToChangeColumnNameStatement(model, fielDef,"OldColumn3"))); | ||
|
||
} | ||
|
||
} | ||
|
||
[Test()] | ||
public void CanAddForeignKey () | ||
{ | ||
|
||
foreach (var d in dialects) | ||
{ | ||
OrmLiteConfig.DialectProvider=d.Provider; | ||
Assert.AreEqual(d.AddFKString,d.Provider.ToAddForeignKeyStatement<Child,Model>(f=>f.IdModel, fk=>fk.Id,OnFkOption.NoAction,OnFkOption.Cascade, "JustOneFK")); | ||
} | ||
} | ||
|
||
|
||
[Test()] | ||
public void CanCreateIndex () | ||
{ | ||
|
||
foreach (var d in dialects) | ||
{ | ||
OrmLiteConfig.DialectProvider=d.Provider; | ||
Assert.AreEqual(d.CreateIndexString, d.Provider.ToCreateIndexStatement<Model>(f=>f.Column3, "JustIndexOnColumn3", true) ); | ||
|
||
} | ||
|
||
} | ||
|
||
|
||
} | ||
|
||
public class Model | ||
{ | ||
public Model() | ||
{ | ||
} | ||
public int Id { get; set; } | ||
public string Column1{ get; set; } | ||
[StringLength(50)] | ||
public string Column2{ get; set; } | ||
public string Column3{ get; set; } | ||
|
||
} | ||
|
||
public class Child | ||
{ | ||
public Child(){} | ||
public int Id{ get; set;} | ||
public int IdModel{ get; set;} | ||
|
||
} | ||
|
||
public class Dialect | ||
{ | ||
public IOrmLiteDialectProvider Provider { get; set; } | ||
public string AddColumnString { get; set; } | ||
public string AlterColumnString { get; set; } | ||
public string ChangeColumnNameString { get; set; } | ||
public string AddFKString { get; set; } | ||
public string CreateIndexString { get; set; } | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters