Skip to content
Advertisement

How to write a multiline SQL string in C# but treat it as a single line string

There is a part in the application where SQL statements are generated. There is a unit test for it that currently only compares if the given query string matches the expected query string. I’m using a multiline string with interpolation (simplified example)

Writing it this way the multiline string looks like this

The identations are filled with empty characters. The generated SQL string by code is this

The unit test fails because the generated string does not match the expected string. How can I remove the empty characters from the expected string? Because currently the test fails with

Expected string to be … with a length of 377, but … has a length of 206 …

Advertisement

Answer

You can use string concatenation to achieve a similar kind of formatting in source code, and the desired string value:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement