Skip to content

Commit

Permalink
Test for SupportLegacyParameterTokens
Browse files Browse the repository at this point in the history
  • Loading branch information
Giorgi committed Oct 10, 2023
1 parent 4885264 commit c92c912
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/Dapper.Tests/ParameterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,36 @@ public void Issue601_InternationalParameterNamesWork()
[FactLongRunning]
public void TestListExpansionPadding_Disabled() => TestListExpansionPadding(false);

[Theory]
[InlineData(true)]
[InlineData(false)]
public void OleDbParamFilterFails(bool legacyParameterToken)
{
SqlMapper.PurgeQueryCache();
var oldValue = SqlMapper.Settings.SupportLegacyParameterTokens;
try
{
SqlMapper.Settings.SupportLegacyParameterTokens = legacyParameterToken;

if (legacyParameterToken) // OLE DB parameter support enabled; can false-positive
{
Assert.Throws<NotImplementedException>(() => GetValue(connection));
}
else // OLE DB parameter support disabled; more reliable
{
Assert.Equal("this ? could be awkward", GetValue(connection));
}
}
finally
{
SqlMapper.Settings.SupportLegacyParameterTokens = oldValue;
}

static string GetValue(DbConnection connection)
=> connection.QuerySingle<string>("select 'this ? could be awkward'",
new TypeWithDodgyProperties());
}

private void TestListExpansionPadding(bool enabled)
{
bool oldVal = SqlMapper.Settings.PadListExpansions;
Expand Down Expand Up @@ -1706,5 +1736,10 @@ class HazNullableSqlDecimal
public int Id { get; set; }
public SqlDecimal? Value { get; set; }
}

class TypeWithDodgyProperties
{
public string Name => throw new NotSupportedException();
}
}
}

0 comments on commit c92c912

Please sign in to comment.