Skip to content

Commit

Permalink
Added increased readability property tests for InlineFormatter
Browse files Browse the repository at this point in the history
  • Loading branch information
Turnerj committed Jul 1, 2021
1 parent d17357b commit 202ab85
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions tests/MiniProfiler.Tests/SqlFormatterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ private void AddDbParameter<T>(SqlCommand command, string name, object value, Pa
[Fact]
public void InlineParameterNamesInParameterValues()
{
var formatter = new InlineFormatter();
var formatter = new InlineFormatter()
{
IncreaseReadability = false
};
var parameters = new List<SqlTimingParameter>
{
new SqlTimingParameter() { DbType = "string", Name = "url", Value = "http://www.example.com?myid=1" },
Expand All @@ -101,7 +104,6 @@ public void InlineParameterNamesInParameterValues()
var formatted = formatter.FormatSql(command, parameters);
Assert.Equal("SELECT * FROM urls WHERE url = 'http://www.example.com?myid=1' OR myid = '1'", formatted);
}

[Fact]
public void InlineParameterValuesDisplayNullForStrings()
{
Expand All @@ -116,6 +118,40 @@ public void InlineParameterValuesDisplayNullForStrings()
Assert.Equal("SELECT * FROM urls WHERE url = 'http://www.example.com?myid=1' OR null IS NULL", formatted);
}

[Fact]
public void InlineIncreaseReadabilityEnabled()
{
var formatter = new InlineFormatter()
{
IncreaseReadability = true
};
var parameters = new List<SqlTimingParameter>
{
new SqlTimingParameter() { DbType = "string", Name = "url", Value = "http://www.example.com?myid=1" },
new SqlTimingParameter() { DbType = "string", Name = "myid", Value = "1" }
};
const string command = "SELECT myid,url FROM urls WHERE url = @url OR myid = @myid";
var formatted = formatter.FormatSql(command, parameters);
Assert.Equal("SELECT myid, url FROM urls WHERE url = 'http://www.example.com?myid=1' OR myid = '1'", formatted);
}

[Fact]
public void InlineIncreaseReadabilityDisabled()
{
var formatter = new InlineFormatter()
{
IncreaseReadability = false
};
var parameters = new List<SqlTimingParameter>
{
new SqlTimingParameter() { DbType = "string", Name = "url", Value = "http://www.example.com?myid=1" },
new SqlTimingParameter() { DbType = "string", Name = "myid", Value = "1" }
};
const string command = "SELECT myid,url FROM urls WHERE url = @url OR myid = @myid";
var formatted = formatter.FormatSql(command, parameters);
Assert.Equal("SELECT myid,url FROM urls WHERE url = 'http://www.example.com?myid=1' OR myid = '1'", formatted);
}

[Fact]
public void EnsureVerboseSqlServerFormatterOnlyAddsInformation()
{
Expand Down

0 comments on commit 202ab85

Please sign in to comment.