forked from DapperLib/Dapper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Define expected behaviour for value-tuple parameters and returns, and…
… implement
- Loading branch information
Showing
3 changed files
with
82 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using Xunit; | ||
|
||
namespace Dapper.Tests | ||
{ | ||
public class TupleTests : TestBase | ||
{ | ||
[Fact] | ||
public void TupleStructParameter_Fails_HelpfulMessage() | ||
{ | ||
try | ||
{ | ||
// I can see this happening... | ||
connection.QuerySingle<int>("select @id", (id: 42, name: "Fred")); | ||
Assert.Fail(); | ||
ValueTuple<int, int> b = (24, 13); | ||
b.Item1.IsEqualTo(24); | ||
} | ||
catch (NotSupportedException ex) | ||
{ | ||
ex.Message.IsEqualTo("ValueTuple should not be used for parameters - the language-level names are not available to use as parameter names, and it adds unnecessary boxing"); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void TupleClassParameter_Works() | ||
{ | ||
connection.QuerySingle<int>("select @Item1", Tuple.Create(42, "Fred")).IsEqualTo(42); | ||
} | ||
|
||
[Fact] | ||
public void TupleReturnValue_Works_ByPosition() | ||
{ | ||
var val = connection.QuerySingle<(int id, string name)>("select 42, 'Fred'"); | ||
val.id.IsEqualTo(42); | ||
val.name.IsEqualTo("Fred"); | ||
} | ||
|
||
[Fact] | ||
public void TupleReturnValue_Works_NamesIgnored() | ||
{ | ||
var val = connection.QuerySingle<(int id, string name)>("select 42 as [Item2], 'Fred' as [Item1]"); | ||
val.id.IsEqualTo(42); | ||
val.name.IsEqualTo("Fred"); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters