From 202ab85a2f04f7c6c7327c88800fb3313c43074c Mon Sep 17 00:00:00 2001 From: Turnerj Date: Thu, 25 Feb 2021 16:11:24 +1030 Subject: [PATCH] Added increased readability property tests for InlineFormatter --- tests/MiniProfiler.Tests/SqlFormatterTests.cs | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/tests/MiniProfiler.Tests/SqlFormatterTests.cs b/tests/MiniProfiler.Tests/SqlFormatterTests.cs index d3af571a..ab92138e 100644 --- a/tests/MiniProfiler.Tests/SqlFormatterTests.cs +++ b/tests/MiniProfiler.Tests/SqlFormatterTests.cs @@ -91,7 +91,10 @@ private void AddDbParameter(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 { new SqlTimingParameter() { DbType = "string", Name = "url", Value = "http://www.example.com?myid=1" }, @@ -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() { @@ -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 + { + 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 + { + 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() {