Skip to content

Commit c357320

Browse files
Add Non Primitive out types tests
1 parent cef7194 commit c357320

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

tests/SqlClient.Tests/ProgrammabilityTests.fs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,30 @@ let ResultSetAndOutParam() =
232232
Assert.Equal<_ list>([ Some "donkey" ], [ for x in result -> x.myName ] )
233233
Assert.Equal(2L, !total)
234234

235+
// Fix #340:
236+
// The type provider cannot use Expr.Value(Activator.CreateInstance(t),t) for
237+
// non primitive types, like System.Guid.
238+
// It now use Expr.DefaultValue(t) for non primite types.
239+
// The PassGuid SP copies the input guid to the output parameter when the boolean
240+
// parameter is true, and let the out parameter uninitialized when false
241+
[<Fact>]
242+
let NonPrimitiveOutParam() =
243+
let guid = Guid.NewGuid()
244+
let cmd = new AdventureWorks.dbo.PassGuid()
245+
let _,result = cmd.Execute(guid, true)
246+
Assert.Equal(guid, result)
247+
248+
// Fix #340:
249+
// When an output parameter has not been set, its value is DBNull which cannot
250+
// be unboxed. The fix sets the parameter to defaultOf<'t>.
251+
// The PassGuid SP copies the input guid to the output parameter when the boolean
252+
// parameter is true, and let the out parameter uninitialized when false
253+
[<Fact>]
254+
let NonPrimitiveNullOutParam() =
255+
let guid = Guid.NewGuid()
256+
let cmd = new AdventureWorks.dbo.PassGuid()
257+
let _,result = cmd.Execute(guid, false)
258+
Assert.Equal(Guid.Empty, result)
235259

236260
[<Fact>]
237261
let PassingImageAsParamDoesntGetCut() =

tests/SqlClient.Tests/extensions.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ USE AdventureWorks2012
77
IF OBJECT_ID('dbo.AddRef') IS NOT NULL
88
DROP PROCEDURE dbo.AddRef;
99
GO
10+
IF OBJECT_ID('dbo.PassGuid') IS NOT NULL
11+
DROP PROCEDURE dbo.PassGuid;
12+
GO
1013
IF OBJECT_ID('dbo.MyProc') IS NOT NULL
1114
DROP PROCEDURE dbo.MyProc;
1215
GO
@@ -169,6 +172,16 @@ BEGIN
169172
END
170173
GO
171174

175+
CREATE PROCEDURE dbo.PassGuid @x AS UNIQUEIDENTIFIER, @b AS BIT, @result AS UNIQUEIDENTIFIER OUTPUT
176+
AS
177+
BEGIN
178+
IF (@b = 1)
179+
BEGIN
180+
SET @result = @x
181+
END
182+
END
183+
GO
184+
172185
CREATE PROCEDURE dbo.MyProc @p1 dbo.MyTableType readonly AS
173186
BEGIN
174187
SELECT * from @p1 p

0 commit comments

Comments
 (0)