forked from subsonic/SubSonic-3.0
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMigrationTests.cs
103 lines (85 loc) · 3.3 KB
/
MigrationTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//
// SubSonic - http://subsonicproject.com
//
// The contents of this file are subject to the New BSD
// License (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of
// the License at http://www.opensource.org/licenses/bsd-license.php
//
// Software distributed under the License is distributed on an
// "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
// implied. See the License for the specific language governing
// rights and limitations under the License.
//
using System;
using System.IO;
using System.Reflection;
using SubSonic.DataProviders;
using SubSonic.Query;
using Xunit;
namespace SubSonic.Tests.Migrations
{
public partial class SubSonicTest
{
//public DateTime ThingyDate { get; set; }
}
internal class SQLitey
{
public SQLitey()
{
if (!File.Exists(TestConfiguration.SQLiteTestsFilePath))
throw new InvalidOperationException("Can't find the DB");
Connection = TestConfiguration.SQLiteTestsConnectionString;
}
public string Connection { get; set; }
}
public class MigrationTests
{
static void DropTestTable(IDataProvider provider)
{
var qry = new CodingHorror(provider, "DROP TABLE SubSonicTests");
try
{
qry.Execute();
}
catch
{
//nada
}
}
[Fact]
public void Migration_MigrateToDb_Should_Save_Schema_To_SqlLite()
{
if (!File.Exists(TestConfiguration.SQLiteMigrationsFilePath))
throw new InvalidOperationException("Can't find the DB");
string connString = TestConfiguration.SQLiteMigrationsConnectionString;
var provider = ProviderFactory.GetProvider(connString, DbClientTypeName.SqlLite);
DropTestTable(provider);
var assembly = Assembly.GetExecutingAssembly();
provider.MigrateToDatabase<SubSonicTest>(assembly);
//query it to make sure it's there
var qry = new CodingHorror(provider, "SELECT * FROM SubSonicTests").ExecuteTypedList<SubSonicTest>();
Assert.Equal(0, qry.Count);
}
[Fact]
public void Migration_Update_Should_Add_DateTime_With_Update()
{
//this is a silly manual test - I wish I could add a property on the fly
//but I can't!
var provider = ProviderFactory.GetProvider(new SQLitey().Connection, DbClientTypeName.SqlLite);
var assembly = Assembly.GetExecutingAssembly();
provider.MigrateToDatabase<SubSonicTest>(assembly);
}
[Fact]
public void Migration_MigrateToDb_Should_Save_Schema_To_MySQL()
{
var provider = ProviderFactory.GetProvider(TestConfiguration.MySqlTestConnectionString, DbClientTypeName.MySql);
DropTestTable(provider);
var assembly = Assembly.GetExecutingAssembly();
provider.MigrateToDatabase<SubSonicTest>(assembly);
//query it to make sure it's there
var qry = new CodingHorror(provider, "SELECT * FROM SubSonicTests").ExecuteTypedList<SubSonicTest>();
Assert.Equal(0, qry.Count);
}
}
}