Skip to content

Commit 9a4f46e

Browse files
committed
Test for CreateIndexStatementCollection and some refactorings.
1 parent 14ebf84 commit 9a4f46e

File tree

8 files changed

+50
-11
lines changed

8 files changed

+50
-11
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<Compile Include="Statement\StatementTestBase.cs" />
7272
<Compile Include="Statement\ForeignKeyStatementTest.cs" />
7373
<Compile Include="Statement\CreateTableStatementTest.cs" />
74+
<Compile Include="Statement\CreateIndexStatementCollectionTest.cs" />
7475
</ItemGroup>
7576
<ItemGroup>
7677
<Folder Include="Builder\" />
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using SQLite.CodeFirst.Statement;
3+
4+
namespace SQLite.CodeFirst.Test.Statement
5+
{
6+
[TestClass]
7+
public class CreateIndexStatementCollectionTest : StatementTestBase
8+
{
9+
[TestMethod]
10+
public void CreateStatementOneEntryTest()
11+
{
12+
var createIndexStatementCollection = new CreateIndexStatementCollection(new[]
13+
{
14+
CreateStatementMock("dummy1").Object,
15+
});
16+
17+
string output = createIndexStatementCollection.CreateStatement();
18+
Assert.AreEqual(createIndexStatementCollection.Count, 1);
19+
Assert.AreEqual(output, "dummy1");
20+
}
21+
22+
[TestMethod]
23+
public void CreateStatementTwoEntryTest()
24+
{
25+
var createIndexStatementCollection = new CreateIndexStatementCollection(new[]
26+
{
27+
CreateStatementMock("dummy1").Object,
28+
CreateStatementMock("dummy2").Object
29+
});
30+
31+
string output = createIndexStatementCollection.CreateStatement();
32+
Assert.AreEqual(createIndexStatementCollection.Count, 2);
33+
Assert.AreEqual(output, "dummy1\r\ndummy2");
34+
}
35+
}
36+
}

SQLite.CodeFirst.Test/Statement/CreateTableStatementTest.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Microsoft.VisualStudio.TestTools.UnitTesting;
2-
using Moq;
32
using SQLite.CodeFirst.Statement;
43

54
namespace SQLite.CodeFirst.Test.Statement
@@ -10,13 +9,10 @@ public class CreateTableStatementTest : StatementTestBase
109
[TestMethod]
1110
public void CreateStatementTest()
1211
{
13-
var statementCollectionMock = new Mock<IStatementCollection>();
14-
statementCollectionMock.Setup(s => s.CreateStatement()).Returns("dummyColumnDefinition");
15-
1612
var createTableStatement = new CreateTableStatement
1713
{
1814
TableName = "dummyTable",
19-
ColumnStatementCollection = statementCollectionMock.Object
15+
ColumnStatementCollection = CreateStatementCollectionMock("dummyColumnDefinition").Object
2016
};
2117

2218
string output = createTableStatement.CreateStatement();

SQLite.CodeFirst.Test/Statement/ForeignKeyStatementTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace SQLite.CodeFirst.Test.Statement
66
{
77
[TestClass]
8-
public class ForeignKeyStatementTest
8+
public class ForeignKeyStatementTest : StatementTestBase
99
{
1010
[TestMethod]
1111
public void CreateStatementOneForeignKeyTest()

SQLite.CodeFirst.Test/Statement/PrimaryKeyStatementTest.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using Microsoft.VisualStudio.TestTools.UnitTesting;
43
using SQLite.CodeFirst.Statement;
54

SQLite.CodeFirst.Test/Statement/StatementTestBase.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,12 @@ protected Mock<IStatement> CreateStatementMock(string createStatementReturnValue
1111
statementMock.Setup(s => s.CreateStatement()).Returns(createStatementReturnValue);
1212
return statementMock;
1313
}
14+
15+
protected Mock<IStatementCollection> CreateStatementCollectionMock(string createStatementReturnValue)
16+
{
17+
var statementCollectionMock = new Mock<IStatementCollection>();
18+
statementCollectionMock.Setup(s => s.CreateStatement()).Returns(createStatementReturnValue);
19+
return statementCollectionMock;
20+
}
1421
}
1522
}

SQLite.CodeFirst/Statement/CreateIndexStatementCollection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
namespace SQLite.CodeFirst.Statement
77
{
8-
internal class CreateIndexStatementCollection : Collection<CreateIndexStatement>, IStatement
8+
internal class CreateIndexStatementCollection : Collection<IStatement>, IStatementCollection
99
{
1010
private const string StatementSeperator = "\r\n";
1111

12-
public CreateIndexStatementCollection(IEnumerable<CreateIndexStatement> createIndexStatements)
12+
public CreateIndexStatementCollection(IEnumerable<IStatement> createIndexStatements)
1313
{
1414
foreach (var createIndexStatement in createIndexStatements)
1515
{

SQLite.CodeFirst/Statement/IStatementCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace SQLite.CodeFirst.Statement
44
{
5-
internal interface IStatementCollection : IStatement, ICollection<IStatement>
5+
public interface IStatementCollection : IStatement, ICollection<IStatement>
66
{
77
}
88
}

0 commit comments

Comments
 (0)