From 603b212522b8d37cf751f9ae069d20c6f9da08a9 Mon Sep 17 00:00:00 2001 From: Marc Gravell Date: Tue, 26 Jul 2016 12:52:38 +0100 Subject: [PATCH] Added tests to complement documentation of pseudo-positional parameters --- Dapper.Tests/Tests.cs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Dapper.Tests/Tests.cs b/Dapper.Tests/Tests.cs index e90e2e6..8126536 100644 --- a/Dapper.Tests/Tests.cs +++ b/Dapper.Tests/Tests.cs @@ -3315,6 +3315,38 @@ public void Issue569_SO38527197_PseudoPositionalParameters_In() } } + [Fact] + public void PseudoPositional_CanUseVariable() + { + using (var connection = ConnectViaOledb()) + { + int id = 42; + var row = connection.QuerySingle("declare @id int = ?id?; select @id as [A], @id as [B];", new { id }); + int a = (int)row.A; + int b = (int)row.B; + a.IsEqualTo(42); + b.IsEqualTo(42); + } + } + [Fact] + public void PseudoPositional_CannotUseParameterMultipleTimes() + { + + using (var connection = ConnectViaOledb()) + { + try + { + int id = 42; + var row = connection.QuerySingle("select ?id? as [A], ?id? as [B];", new { id }); + Assert.Fail(); + } + catch (InvalidOperationException ex) when (ex.Message == "When passing parameters by position, each parameter can only be referenced once") + { + // that's a win + } + } + } + [Fact] public void PseudoPositionalParameters_ExecSingle() { -- GitLab