Skip to content

Commit

Permalink
Updated SqlKihon to include simple INSERT and UPDATE kihon
Browse files Browse the repository at this point in the history
  • Loading branch information
trayburn committed Feb 26, 2011
1 parent f114df4 commit 0144d67
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ build
*.suo
*.trx
Logs
TestResults
TestResult.xml
# This line keeps the db in check - comment it out to update the starting db
data
Expand Down
63 changes: 56 additions & 7 deletions src/Squire/Framework/SqlKihonStructure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,20 @@ namespace Squire.Framework
[TestClass]
public abstract class SqlKihonStructure : BaseDataKihon
{
private static void ExecuteNonQuery(SQLiteConnection dbConn, string cmdText)
private int ExecuteScalarInt(string cmdText)
{
using (SQLiteCommand sQLiteCommand1 = new SQLiteCommand(cmdText, dbConn))
using (SQLiteCommand cmd = new SQLiteCommand(cmdText, dbConn))
{
object result = cmd.ExecuteScalar();
return Convert.ToInt32(result);
}
}

private int ExecuteNonQuery(string cmdText)
{
using (SQLiteCommand cmd = new SQLiteCommand(cmdText, dbConn))
{
sQLiteCommand1.ExecuteNonQuery();
return cmd.ExecuteNonQuery();
}
}

Expand All @@ -28,10 +37,10 @@ private void Execute(string cmdText, Action<IDataReader> rdrAction)

protected override void CreateTestData(SQLiteConnection dbConn)
{
ExecuteNonQuery(dbConn, CreatePersonTable());
ExecuteNonQuery(dbConn, CreateAddressTable());
ExecuteNonQuery(dbConn, SamplePersons());
ExecuteNonQuery(dbConn, SampleAddress());
ExecuteNonQuery(CreatePersonTable());
ExecuteNonQuery(CreateAddressTable());
ExecuteNonQuery(SamplePersons());
ExecuteNonQuery(SampleAddress());
}

private string SamplePersons()
Expand Down Expand Up @@ -170,9 +179,49 @@ public void Actual_Select_All_Fields_From_Person_Left_Outer_Joined_To_Address()
Assert.AreEqual(3, count);
}

[TestMethod]
public void Actual_Insert_PersonId_4_Named_Mike_Johnson_Age_5_To_Person()
{
// Arrange
int count = 0;

// Act
string cmdText = Insert_PersonId_4_Named_Mike_Johnson_Age_5_To_Person();
var rowCount = ExecuteNonQuery(cmdText);

// Assert
Assert.AreEqual(1, rowCount);
Execute("SELECT * FROM PERSON WHERE FIRSTNAME='Mike' AND LASTNAME='Johnson' AND AGE=5",
r =>
{
while (r.Read())
{
count += 1;
}
});
Assert.AreEqual(1, count);
}

[TestMethod]
public void Actual_Update_All_LastNames_Rayburn_To_Johnson_In_Person()
{
// Arrange
int count = 0;

// Act
string cmdText = Update_All_LastNames_Rayburn_To_Johnson_In_Person();
var rowCount = ExecuteNonQuery(cmdText);

// Assert
Assert.AreEqual(2, rowCount);
Assert.AreEqual(2, ExecuteScalarInt("SELECT COUNT(*) FROM PERSON WHERE LASTNAME='Johnson'"));
Assert.AreEqual(0, ExecuteScalarInt("SELECT COUNT(*) FROM PERSON WHERE LASTNAME='Rayburn'"));
}
protected abstract string Select_All_Fields_And_Rows_From_Person();
protected abstract string Select_All_Fields_From_Person_Joined_To_Address();
protected abstract string Select_FirstName_From_Person_Where_LastName_Equals_Rayburn();
protected abstract string Select_All_Fields_From_Person_Left_Outer_Joined_To_Address();
protected abstract string Insert_PersonId_4_Named_Mike_Johnson_Age_5_To_Person();
protected abstract string Update_All_LastNames_Rayburn_To_Johnson_In_Person();
}
}
18 changes: 14 additions & 4 deletions src/Squire/SqlKihon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,32 @@ Zip varchar(9)
*/
protected override string Select_All_Fields_And_Rows_From_Person()
{
return "SELECT * FROM PERSON";
throw new NotImplementedException();
}

protected override string Select_All_Fields_From_Person_Joined_To_Address()
{
return "SELECT * FROM PERSON JOIN ADDRESS ON PERSON.PERSONID = ADDRESS.PERSONID";
throw new NotImplementedException();
}

protected override string Select_FirstName_From_Person_Where_LastName_Equals_Rayburn()
{
return "SELECT FIRSTNAME FROM PERSON WHERE LASTNAME='Rayburn'";
throw new NotImplementedException();
}

protected override string Select_All_Fields_From_Person_Left_Outer_Joined_To_Address()
{
return "SELECT * FROM PERSON LEFT OUTER JOIN ADDRESS ON PERSON.PERSONID = ADDRESS.PERSONID";
throw new NotImplementedException();
}

protected override string Insert_PersonId_4_Named_Mike_Johnson_Age_5_To_Person()
{
throw new NotImplementedException();
}

protected override string Update_All_LastNames_Rayburn_To_Johnson_In_Person()
{
throw new NotImplementedException();
}
}
}

0 comments on commit 0144d67

Please sign in to comment.