Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A brave attempt to fix the most voted issue - support |DataDirectory| with .NET Core client #284

Merged
merged 11 commits into from
Nov 14, 2019
Prev Previous commit
Next Next commit
Move localized string
Add SqlConnectionStringBuilder tests
  • Loading branch information
ErikEJ committed Nov 9, 2019
commit 41ede3503e02becd72a27ba74b159459a45c2e67
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,9 @@ internal static Exception InvalidConnectionOptionValue(string key, Exception inn
{
return Argument(System.SRHelper.Format(SR.ADP_InvalidConnectionOptionValue, key), inner);
}

static internal InvalidOperationException InvalidDataDirectory()
{
InvalidOperationException e = new InvalidOperationException("The DataDirectory substitute is not a string.");
InvalidOperationException e = new InvalidOperationException(SR.ADP_InvalidDataDirectory);
return e;
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Microsoft.Data.SqlClient/netcore/src/Resources/SR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@
<data name="ADP_InternalConnectionError" xml:space="preserve">
<value>Internal DbConnection Error: {0}</value>
</data>
<data name="ADP_InvalidDataDirectory" xml:space="preserve">
<value>The DataDirectory substitute is not a string.</value>
</data>
<data name="ADP_InvalidEnumerationValue" xml:space="preserve">
<value>The {0} enumeration value, {1}, is invalid.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,45 @@ public void UnexpectedKeywordRetrieval()
Assert.Throws<ArgumentException>(() => builder["RandomKeyword"]);
}

[Theory]
[InlineData(@"C:\test\attach.mdf", "AttachDbFilename=C:\\test\\attach.mdf")]
[InlineData(@"C:\test\attach.mdf;", "AttachDbFilename=\"C:\\test\\attach.mdf;\"")]
public void ConnectionString_AttachDbFileName_Plain(string value, string expected)
{
var builder = new SqlConnectionStringBuilder();
builder.AttachDBFilename = value;
Assert.Equal(expected, builder.ConnectionString);
}

[Theory]
[PlatformSpecific(TestPlatforms.Windows)]
[InlineData(@"|DataDirectory|\attach.mdf",
@"AttachDbFilename=|DataDirectory|\attach.mdf",
@"C:\test\")]
[InlineData(@"|DataDirectory|\attach.mdf",
@"AttachDbFilename=|DataDirectory|\attach.mdf",
@"C:\test")]
[InlineData(@"|DataDirectory|attach.mdf",
@"AttachDbFilename=|DataDirectory|attach.mdf",
@"C:\test")]
[InlineData(@"|DataDirectory|attach.mdf",
@"AttachDbFilename=|DataDirectory|attach.mdf",
@"C:\test\")]
[InlineData(@" |DataDirectory|attach.mdf",
"AttachDbFilename=\" |DataDirectory|attach.mdf\"",
@"C:\test\")]
[InlineData(@"|DataDirectory|attach.mdf ",
"AttachDbFilename=\"|DataDirectory|attach.mdf \"",
@"C:\test\")]
public void ConnectionStringBuilder_AttachDbFileName_DataDirectory(string value, string expected, string dataDirectory)
{
AppDomain.CurrentDomain.SetData("DataDirectory", dataDirectory);

var builder = new SqlConnectionStringBuilder();
builder.AttachDBFilename = value;
Assert.Equal(expected, builder.ConnectionString);
}

private void ExecuteConnectionStringTests(string connectionString)
{
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectionString);
Expand Down