Permalink
Browse files

Update #283 - Setting up some test cases to make sure we don't break …

…with TransactionScope
  • Loading branch information...
1 parent 5e0124b commit ae60fd142c5dd01affee02f4c00960dc844e5566 @avanderhoorn avanderhoorn committed Mar 25, 2013
Showing with 87 additions and 52 deletions.
  1. +87 −52 source/Glimpse.Mvc3.MusicStore.Sample/Controllers/HomeController.cs
@@ -72,82 +72,117 @@ private List<Album> GetTopSellingAlbums(int count)
var result2 = 0;
var result3 = 0;
- //using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew))
- //{
- var connectionString = ConfigurationManager.ConnectionStrings["MusicStoreEntities"];
- var factory = DbProviderFactories.GetFactory(connectionString.ProviderName);
- using (var connection = factory.CreateConnection())
+ var connectionString = ConfigurationManager.ConnectionStrings["MusicStoreEntities"];
+ var factory = DbProviderFactories.GetFactory(connectionString.ProviderName);
+ using (var connection = factory.CreateConnection())
+ {
+ connection.ConnectionString = connectionString.ConnectionString;
+ connection.Open();
+
+ using (var command = connection.CreateCommand())
+ {
+ command.CommandText = "SELECT COUNT(*) FROM Albums WHERE Title LIKE 'A%'";
+ command.CommandType = CommandType.Text;
+ result3 = (int)command.ExecuteScalar();
+ }
+
+ using (var command = connection.CreateCommand())
{
- connection.ConnectionString = connectionString.ConnectionString;
- connection.Open();
+ command.CommandText = "SELECT COUNT(*) FROM Albums WHERE Title LIKE 'B%'";
+ command.CommandType = CommandType.Text;
+ result3 = (int)command.ExecuteScalar();
+ }
+ using (var transaction = connection.BeginTransaction())
+ {
using (var command = connection.CreateCommand())
- {
- command.CommandText = "SELECT COUNT(*) FROM Albums WHERE Title LIKE 'For%'";
+ {
+ command.Transaction = transaction;
+
+ command.CommandText = "SELECT COUNT(*) FROM Albums";
command.CommandType = CommandType.Text;
- result3 = (int)command.ExecuteScalar();
+ result1 = (int)command.ExecuteScalar();
}
using (var command = connection.CreateCommand())
{
- command.CommandText = "SELECT COUNT(*) FROM Albums WHERE Title LIKE 'Re%'";
+ command.Transaction = transaction;
+
+ command.CommandText = "SELECT COUNT(*) FROM Albums WHERE Title LIKE 'C%'";
command.CommandType = CommandType.Text;
- result3 = (int)command.ExecuteScalar();
+ result2 = (int)command.ExecuteScalar();
}
- using (var transaction = connection.BeginTransaction())
+ transaction.Commit();
+ }
+
+ using (var command = connection.CreateCommand())
+ {
+ command.CommandText = "SELECT COUNT(*) FROM Albums WHERE Title LIKE 'D%'";
+ command.CommandType = CommandType.Text;
+ result3 = (int)command.ExecuteScalar();
+ }
+
+ using (var transaction = connection.BeginTransaction())
+ {
+ using (var command = connection.CreateCommand())
{
- using (var command = connection.CreateCommand())
- {
- command.Transaction = transaction;
+ command.Transaction = transaction;
- command.CommandText = "SELECT COUNT(*) FROM Albums";
- command.CommandType = CommandType.Text;
- result1 = (int)command.ExecuteScalar();
- }
+ command.CommandText = "SELECT COUNT(*) FROM Albums WHERE Title LIKE 'E%'";
+ command.CommandType = CommandType.Text;
+ result3 = (int)command.ExecuteScalar();
+ }
+ //transaction.Commit();
+ }
- using (var command = connection.CreateCommand())
- {
- command.Transaction = transaction;
+ using (var command = connection.CreateCommand())
+ {
+ command.CommandText = "SELECT COUNT(*) FROM Albums WHERE Title LIKE 'F%'";
+ command.CommandType = CommandType.Text;
+ result3 = (int)command.ExecuteScalar();
+ }
- command.CommandText = "SELECT COUNT(*) FROM Albums WHERE Title LIKE 'The%'";
- command.CommandType = CommandType.Text;
- result2 = (int)command.ExecuteScalar();
- }
+ using (var command = connection.CreateCommand())
+ {
+ command.CommandText = "SELECT COUNT(*) FROM Albums WHERE Title LIKE 'G%'";
+ command.CommandType = CommandType.Text;
+ result3 = (int)command.ExecuteScalar();
+ }
+ }
- transaction.Commit();
- }
+ using (var connection = factory.CreateConnection())
+ {
+ connection.ConnectionString = connectionString.ConnectionString;
+ connection.Open();
- using (var command = connection.CreateCommand())
- {
- command.CommandText = "SELECT COUNT(*) FROM Albums WHERE Title LIKE 'L%'";
- command.CommandType = CommandType.Text;
- result3 = (int)command.ExecuteScalar();
- }
-
- using (var transaction = connection.BeginTransaction())
- {
- using (var command = connection.CreateCommand())
- {
- command.Transaction = transaction;
-
- command.CommandText = "SELECT COUNT(*) FROM Albums WHERE Title LIKE 'A%'";
- command.CommandType = CommandType.Text;
- result3 = (int)command.ExecuteScalar();
- }
- //transaction.Commit();
- }
+ using (var command = connection.CreateCommand())
+ {
+ command.CommandText = "SELECT * FROM Albums WHERE Title LIKE 'I%'";
+ command.CommandType = CommandType.Text;
+ var result = command.ExecuteReader();
+ }
+ using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew))
+ {
using (var command = connection.CreateCommand())
{
- command.CommandText = "SELECT COUNT(*) FROM Albums WHERE Title LIKE 'B%'";
+ command.CommandText = "SELECT * FROM Albums WHERE Title LIKE 'J%'";
command.CommandType = CommandType.Text;
- result3 = (int)command.ExecuteScalar();
+ var result = command.ExecuteReader();
}
+
+ scope.Complete();
}
- // scope.Complete();
- //}
+ using (var command = connection.CreateCommand())
+ {
+ command.CommandText = "SELECT COUNT(*) FROM Albums WHERE Title LIKE 'K%'";
+ command.CommandType = CommandType.Text;
+ result3 = (int)command.ExecuteScalar();
+ }
+ }
+
return new Tuple<int, int>(result1, result2);
}

0 comments on commit ae60fd1

Please sign in to comment.