Skip to content

Commit

Permalink
Merge pull request MiniProfiler#73 from MiniProfiler/v3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
yellis committed Jun 10, 2014
2 parents e915f44 + 616d18a commit 5b73a3a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
24 changes: 24 additions & 0 deletions StackExchange.Profiling.Tests/SqlFormatterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Transactions;
using NUnit.Framework;
using StackExchange.Profiling.SqlFormatters;
using IsolationLevel = System.Data.IsolationLevel;

namespace StackExchange.Profiling.Tests
{
Expand Down Expand Up @@ -115,6 +117,28 @@ public void EnsureVerboseSqlServerFormatterOnlyAddsInformation()
Assert.AreEqual(expectedOutput, actualOutput);
}

[Test]
public void VerboseSqlServerFormatterAddsTransactionInformation()
{
// note: since we don't have an active sql connection we cannot test the transactions coupled to a connection
// the only thing we can do is test the TransactionScope transaction

// arrange
// overwrite the formatter
_formatter = new VerboseSqlServerFormatter(true);
_commandText = "select 1";
const string expectedOutput = "-- Command Type: Text\r\n-- Database: TestDatabase\r\n-- Transaction Iso Level: Serializable\r\n\r\nselect 1;";
CreateDbCommand(CommandType.Text);
TransactionScope transactionScope = new TransactionScope();

// act
var actualOutput = GenerateOutput();
transactionScope.Dispose();

// assert
Assert.AreEqual(expectedOutput, actualOutput);
}

[Test]
public void TabelQueryWithoutParameters()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Transactions;

namespace StackExchange.Profiling.SqlFormatters
{
Expand Down Expand Up @@ -39,6 +40,11 @@ public string FormatSql(string commandText, List<SqlTimingParameter> parameters,
{
buffer.AppendLine("-- Transaction Iso Level: " + command.Transaction.IsolationLevel);
}
if (Transaction.Current != null)
{
// transactions issued by TransactionScope are not bound to the database command but exists globally
buffer.AppendLine("-- Transaction Iso Level: " + Transaction.Current.IsolationLevel);
}
buffer.AppendLine();
}

Expand Down

0 comments on commit 5b73a3a

Please sign in to comment.