Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding repository version and upgrade/downgrade. All unit tested.
- Loading branch information
Alfred Hall
committed
Mar 10, 2011
1 parent
cf741ac
commit 90d806c
Showing
7 changed files
with
222 additions
and
59 deletions.
There are no files selected for viewing
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
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,66 @@ | ||
using System; | ||
using NUnit.Framework; | ||
|
||
namespace Sector.Tests | ||
{ | ||
[TestFixture()] | ||
public class RepositoryTest | ||
{ | ||
[Test()] | ||
public void GetVersion() | ||
{ | ||
var repository = TestUtils.MakeRepository(); | ||
Assert.AreEqual(2, repository.GetVersion()); | ||
} | ||
|
||
[Test()] | ||
[ExpectedException(typeof(Exception))] | ||
public void GetUpgradeSql_Invalid() | ||
{ | ||
var repository = TestUtils.MakeRepository(); | ||
repository.GetUpgradeSql(232323); | ||
} | ||
|
||
[Test()] | ||
public void GetUpgradeSql() | ||
{ | ||
var repository = TestUtils.MakeRepository(); | ||
|
||
string version1 = @"CREATE TABLE testie( | ||
id serial PRIMARY KEY NOT NULL, | ||
age integer NOT NULL UNIQUE, | ||
description varchar(255) | ||
); | ||
"; | ||
Assert.AreEqual(version1, repository.GetUpgradeSql(1)); | ||
|
||
string version2 = @"CREATE TABLE moon( | ||
id serial PRIMARY KEY NOT NULL, | ||
age2 integer NOT NULL UNIQUE, | ||
description2 varchar(255) | ||
); | ||
"; | ||
Assert.AreEqual(version2, repository.GetUpgradeSql(2)); | ||
} | ||
|
||
[Test()] | ||
[ExpectedException(typeof(Exception))] | ||
public void GetDowngradeSql_Invalid() | ||
{ | ||
var repository = TestUtils.MakeRepository(); | ||
repository.GetDowngradeSql(232323); | ||
} | ||
|
||
[Test()] | ||
public void GetDowngradeSql() | ||
{ | ||
var repository = TestUtils.MakeRepository(); | ||
|
||
string version1 = @"DROP TABLE testie;" + Environment.NewLine; | ||
Assert.AreEqual(version1, repository.GetDowngradeSql(1)); | ||
|
||
string version2 = @"DROP TABLE moon;" + Environment.NewLine; | ||
Assert.AreEqual(version2, repository.GetDowngradeSql(2)); | ||
} | ||
} | ||
} |
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
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,65 @@ | ||
using System; | ||
using NHibernate.Tool.hbm2ddl; | ||
using FluentNHibernate.Cfg.Db; | ||
using FluentNHibernate.Cfg; | ||
using Sector.Mappings; | ||
using NHibernate; | ||
using System.IO; | ||
|
||
namespace Sector.Tests | ||
{ | ||
public static class TestUtils | ||
{ | ||
private const string DbServer = "localhost"; | ||
private const string DbUsername = "ahall"; | ||
private const string DbPassword = "temp123"; | ||
private const string Database = "sector_test"; | ||
|
||
private static readonly string ConnectionString = string.Format(CONNSTRING_TEMPLATE, DbServer, | ||
Database, DbUsername, DbPassword); | ||
private static readonly string TestFiles = GetTestFilesDir(); | ||
|
||
private const string CONNSTRING_TEMPLATE = | ||
@"Server={0};Database={1};User Id={2};Password={3}"; | ||
|
||
|
||
private static string GetTestFilesDir() | ||
{ | ||
string solnDir = new DirectoryInfo(Environment.CurrentDirectory) | ||
.Parent.Parent.FullName; | ||
return Path.Combine(solnDir, "testfiles"); | ||
} | ||
|
||
private static IPersistenceConfigurer BuildDatabase() | ||
{ | ||
return PostgreSQLConfiguration.PostgreSQL82.ConnectionString(ConnectionString); | ||
} | ||
|
||
private static void BuildSchema(NHibernate.Cfg.Configuration cfg) | ||
{ | ||
new SchemaExport(cfg).Create(script: false, export: true); | ||
} | ||
|
||
public static ISessionFactory MakeFactory(bool export = false) | ||
{ | ||
FluentConfiguration dbCfg = Fluently.Configure().Database(BuildDatabase()); | ||
dbCfg.Mappings(x => x.FluentMappings.Add<MigrateVersionMap>()); | ||
|
||
if (export) | ||
dbCfg.ExposeConfiguration(BuildSchema); | ||
return dbCfg.BuildSessionFactory(); | ||
} | ||
|
||
public static Repository MakeRepository() | ||
{ | ||
return new Repository(Path.Combine(TestFiles, "repo")); | ||
} | ||
|
||
public static ISectorDb MakeSectorDb() | ||
{ | ||
return new SectorDb(server: DbServer, username: DbUsername, | ||
password: DbPassword, database: Database); | ||
} | ||
} | ||
} | ||
|
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
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
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