Last active
December 14, 2015 13:28
-
-
Save segilbert/5093518 to your computer and use it in GitHub Desktop.
Tell me what is wrong with this unit test? Hint ... Fails with expect count of 5 but count = 8.
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
public void CanExecuteNonQueryWithCommandTextWithDefinedTypeAndTransaction() | |
{ | |
// Arrange | |
int countBefore = Convert.ToInt32(db.ExecuteScalar(countCommand)); | |
using (DbConnection connection = db.CreateConnection()) | |
{ | |
connection.Open(); | |
using (DbTransaction trans = connection.BeginTransaction()) | |
{ | |
// Act | |
db.ExecuteNonQuery(trans, CommandType.Text, insertionCommand.CommandText); | |
trans.Commit(); | |
} | |
} | |
// Assert | |
int countAfter = Convert.ToInt32(db.ExecuteScalar(countCommand)); | |
Assert.AreEqual(1, countAfter - countBefore); | |
// Cleanup | |
string cleanupString = "delete from Region where RegionId = 77"; | |
DbCommand cleanupCommand = db.GetSqlStringCommand(cleanupString); | |
int rowsAffected = db.ExecuteNonQuery(cleanupCommand); | |
// Assert Cleanup | |
Assert.AreEqual(1, rowsAffected); | |
} |
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
public void CanExecuteNonQueryWithCommandTextWithDefinedTypeAndTransaction() | |
{ | |
// Arrange | |
using (DbConnection connection = db.CreateConnection()) | |
{ | |
connection.Open(); | |
using (DbTransaction trans = connection.BeginTransaction()) | |
{ | |
// Act | |
db.ExecuteNonQuery(trans, CommandType.Text, insertionCommand.CommandText); | |
trans.Commit(); | |
} | |
} | |
// Cleanup | |
string cleanupString = "delete from Region where RegionId = 77"; | |
DbCommand cleanupCommand = db.GetSqlStringCommand(cleanupString); | |
int rowsAffected = db.ExecuteNonQuery(cleanupCommand); | |
// Assert | |
Assert.AreEqual(1, rowsAffected); | |
} |
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
public void CanExecuteNonQueryWithCommandTextWithDefinedTypeAndTransaction() | |
{ | |
using (DbConnection connection = db.CreateConnection()) | |
{ | |
connection.Open(); | |
using (DbTransaction trans = connection.BeginTransaction()) | |
{ | |
db.ExecuteNonQuery(trans, CommandType.Text, insertionCommand.CommandText); | |
trans.Commit(); | |
} | |
} | |
string cleanupString = "delete from Region where RegionId = 77"; | |
DbCommand cleanupCommand = db.GetSqlStringCommand(cleanupString); | |
int rowsAffected = db.ExecuteNonQuery(cleanupCommand); | |
int count = Convert.ToInt32(db.ExecuteScalar(countCommand)); | |
Assert.AreEqual(5, count); | |
Assert.AreEqual(1, rowsAffected); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, I'm voting for the "After option"