Skip to content

Commit 4f1c25b

Browse files
committed
Test for the ForeignKeyStatement.
1 parent 14ebdb1 commit 4f1c25b

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

SQLite.CodeFirst.Test/SQLite.CodeFirst.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
<Compile Include="Statement\PrimaryKeyStatementTest.cs" />
7070
<Compile Include="Statement\CreateDatabaseStatementTest.cs" />
7171
<Compile Include="Statement\StatementTestBase.cs" />
72+
<Compile Include="Statement\ForeignKeyStatementTest.cs" />
7273
</ItemGroup>
7374
<ItemGroup>
7475
<Folder Include="Builder\" />
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
using System.Collections.Generic;
2+
using Microsoft.VisualStudio.TestTools.UnitTesting;
3+
using SQLite.CodeFirst.Statement;
4+
5+
namespace SQLite.CodeFirst.Test.Statement
6+
{
7+
[TestClass]
8+
public class ForeignKeyStatementTest
9+
{
10+
[TestMethod]
11+
public void CreateStatementOneForeignKeyTest()
12+
{
13+
var foreignKeyStatement = new ForeignKeyStatement
14+
{
15+
CascadeDelete = false,
16+
ForeignKey = new List<string> { "dummyForeignKey1" },
17+
ForeignPrimaryKey = new List<string> { "dummForeignPrimaryKey1" },
18+
ForeignTable = "dummyForeignTable"
19+
};
20+
21+
string output = foreignKeyStatement.CreateStatement();
22+
Assert.AreEqual(output, "FOREIGN KEY (dummyForeignKey1) REFERENCES dummyForeignTable(dummForeignPrimaryKey1)");
23+
}
24+
25+
[TestMethod]
26+
public void CreateStatementOneForeignKeyCascadeDeleteTest()
27+
{
28+
var foreignKeyStatement = new ForeignKeyStatement
29+
{
30+
CascadeDelete = true,
31+
ForeignKey = new List<string> { "dummyForeignKey1" },
32+
ForeignPrimaryKey = new List<string> { "dummForeignPrimaryKey1" },
33+
ForeignTable = "dummyForeignTable"
34+
};
35+
36+
string output = foreignKeyStatement.CreateStatement();
37+
Assert.AreEqual(output, "FOREIGN KEY (dummyForeignKey1) REFERENCES dummyForeignTable(dummForeignPrimaryKey1) ON DELETE CASCADE");
38+
}
39+
40+
[TestMethod]
41+
public void CreateStatementTwoForeignKeyTest()
42+
{
43+
var foreignKeyStatement = new ForeignKeyStatement
44+
{
45+
CascadeDelete = false,
46+
ForeignKey = new List<string> { "dummyForeignKey1", "dummyForeignKey2" },
47+
ForeignPrimaryKey = new List<string> { "dummForeignPrimaryKey1" },
48+
ForeignTable = "dummyForeignTable"
49+
};
50+
51+
string output = foreignKeyStatement.CreateStatement();
52+
Assert.AreEqual(output, "FOREIGN KEY (dummyForeignKey1, dummyForeignKey2) REFERENCES dummyForeignTable(dummForeignPrimaryKey1)");
53+
}
54+
55+
[TestMethod]
56+
public void CreateStatementTwoForeignKeyTwoPrimaryKeyTest()
57+
{
58+
var foreignKeyStatement = new ForeignKeyStatement
59+
{
60+
CascadeDelete = false,
61+
ForeignKey = new List<string> { "dummyForeignKey1", "dummyForeignKey2" },
62+
ForeignPrimaryKey = new List<string> { "dummForeignPrimaryKey1", "dummForeignPrimaryKey2" },
63+
ForeignTable = "dummyForeignTable"
64+
};
65+
66+
string output = foreignKeyStatement.CreateStatement();
67+
Assert.AreEqual(output, "FOREIGN KEY (dummyForeignKey1, dummyForeignKey2) REFERENCES dummyForeignTable(dummForeignPrimaryKey1, dummForeignPrimaryKey2)");
68+
}
69+
70+
[TestMethod]
71+
public void CreateStatementOneForeignKeyTwoPrimaryKeyTest()
72+
{
73+
var foreignKeyStatement = new ForeignKeyStatement
74+
{
75+
CascadeDelete = false,
76+
ForeignKey = new List<string> { "dummyForeignKey1" },
77+
ForeignPrimaryKey = new List<string> { "dummForeignPrimaryKey1", "dummForeignPrimaryKey2" },
78+
ForeignTable = "dummyForeignTable"
79+
};
80+
81+
string output = foreignKeyStatement.CreateStatement();
82+
Assert.AreEqual(output, "FOREIGN KEY (dummyForeignKey1) REFERENCES dummyForeignTable(dummForeignPrimaryKey1, dummForeignPrimaryKey2)");
83+
}
84+
}
85+
}

0 commit comments

Comments
 (0)