Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
Dapper
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
Dapper
Commits
dc374ad1
Commit
dc374ad1
authored
Oct 28, 2017
by
ydango
Committed by
Nick Craver
Nov 05, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Shortened the changes
Combined 2 tests into one
parent
5b52424c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
57 deletions
+71
-57
ProcedureTests.cs
Dapper.Tests/ProcedureTests.cs
+71
-57
No files found.
Dapper.Tests/ProcedureTests.cs
View file @
dc374ad1
...
@@ -11,12 +11,12 @@ public class ProcedureTests : TestBase
...
@@ -11,12 +11,12 @@ public class ProcedureTests : TestBase
public
void
TestProcWithOutParameter
()
public
void
TestProcWithOutParameter
()
{
{
connection
.
Execute
(
connection
.
Execute
(
@"CREATE PROCEDURE #TestProcWithOutParameter
@"CREATE PROCEDURE #TestProcWithOutParameter
@ID int output,
@ID int output,
@Foo varchar(100),
@Foo varchar(100),
@Bar int
@Bar int
AS
AS
SET @ID = @Bar + LEN(@Foo)"
);
SET @ID = @Bar + LEN(@Foo)"
);
var
obj
=
new
var
obj
=
new
{
{
ID
=
0
,
ID
=
0
,
...
@@ -33,13 +33,13 @@ @Bar int
...
@@ -33,13 +33,13 @@ @Bar int
public
void
TestProcWithOutAndReturnParameter
()
public
void
TestProcWithOutAndReturnParameter
()
{
{
connection
.
Execute
(
connection
.
Execute
(
@"CREATE PROCEDURE #TestProcWithOutAndReturnParameter
@"CREATE PROCEDURE #TestProcWithOutAndReturnParameter
@ID int output,
@ID int output,
@Foo varchar(100),
@Foo varchar(100),
@Bar int
@Bar int
AS
AS
SET @ID = @Bar + LEN(@Foo)
SET @ID = @Bar + LEN(@Foo)
RETURN 42"
);
RETURN 42"
);
var
obj
=
new
var
obj
=
new
{
{
ID
=
0
,
ID
=
0
,
...
@@ -63,19 +63,18 @@ public void TestIssue17648290()
...
@@ -63,19 +63,18 @@ public void TestIssue17648290()
p
.
Add
(
"@MessageControlID"
,
getMessageControlId
);
p
.
Add
(
"@MessageControlID"
,
getMessageControlId
);
p
.
Add
(
"@SuccessCode"
,
dbType
:
DbType
.
Int32
,
direction
:
ParameterDirection
.
Output
);
p
.
Add
(
"@SuccessCode"
,
dbType
:
DbType
.
Int32
,
direction
:
ParameterDirection
.
Output
);
p
.
Add
(
"@ErrorDescription"
,
dbType
:
DbType
.
String
,
direction
:
ParameterDirection
.
Output
,
size
:
255
);
p
.
Add
(
"@ErrorDescription"
,
dbType
:
DbType
.
String
,
direction
:
ParameterDirection
.
Output
,
size
:
255
);
connection
.
Execute
(
@"CREATE PROCEDURE #up_MessageProcessed_get
connection
.
Execute
(
@Code varchar(10),
@"CREATE PROCEDURE #up_MessageProcessed_get
@MessageControlID varchar(22),
@Code varchar(10),
@SuccessCode int OUTPUT,
@MessageControlID varchar(22),
@ErrorDescription varchar(255) OUTPUT
@SuccessCode int OUTPUT,
AS
@ErrorDescription varchar(255) OUTPUT
AS
BEGIN
BEGIN
Select 2 as MessageProcessID, 38349348 as StartNum, 3874900 as EndNum, GETDATE() as StartDate, GETDATE() as EndDate
Select 2 as MessageProcessID, 38349348 as StartNum, 3874900 as EndNum, GETDATE() as StartDate, GETDATE() as EndDate
SET @SuccessCode = 0
SET @SuccessCode = 0
SET @ErrorDescription = 'Completed successfully'
SET @ErrorDescription = 'Completed successfully'
END"
);
END"
);
var
result
=
connection
.
Query
(
sql
:
"#up_MessageProcessed_get"
,
param
:
p
,
commandType
:
CommandType
.
StoredProcedure
);
var
result
=
connection
.
Query
(
sql
:
"#up_MessageProcessed_get"
,
param
:
p
,
commandType
:
CommandType
.
StoredProcedure
);
var
row
=
result
.
Single
();
var
row
=
result
.
Single
();
Assert
.
Equal
(
2
,
(
int
)
row
.
MessageProcessID
);
Assert
.
Equal
(
2
,
(
int
)
row
.
MessageProcessID
);
...
@@ -89,7 +88,10 @@ public void TestIssue17648290()
...
@@ -89,7 +88,10 @@ public void TestIssue17648290()
[
Fact
]
[
Fact
]
public
void
SO24605346_ProcsAndStrings
()
public
void
SO24605346_ProcsAndStrings
()
{
{
connection
.
Execute
(
@"create proc #GetPracticeRebateOrderByInvoiceNumber @TaxInvoiceNumber nvarchar(20) as
connection
.
Execute
(
@"create proc #GetPracticeRebateOrderByInvoiceNumber
@TaxInvoiceNumber nvarchar(20)
as
select @TaxInvoiceNumber as [fTaxInvoiceNumber]"
);
select @TaxInvoiceNumber as [fTaxInvoiceNumber]"
);
const
string
InvoiceNumber
=
"INV0000000028PPN"
;
const
string
InvoiceNumber
=
"INV0000000028PPN"
;
var
result
=
connection
.
Query
<
PracticeRebateOrders
>(
"#GetPracticeRebateOrderByInvoiceNumber"
,
new
var
result
=
connection
.
Query
<
PracticeRebateOrders
>(
"#GetPracticeRebateOrderByInvoiceNumber"
,
new
...
@@ -118,10 +120,10 @@ public void Issue327_ReadEmptyProcedureResults()
...
@@ -118,10 +120,10 @@ public void Issue327_ReadEmptyProcedureResults()
{
{
// Actually testing for not erroring here on the mapping having no rows to map on in Read<T>();
// Actually testing for not erroring here on the mapping having no rows to map on in Read<T>();
connection
.
Execute
(
@"
connection
.
Execute
(
@"
CREATE PROCEDURE #TestEmptyResults
CREATE PROCEDURE #TestEmptyResults
AS
AS
SELECT Top 0 1 Id, 'Bob' Name;
SELECT Top 0 1 Id, 'Bob' Name;
SELECT Top 0 'Billy Goat' Creature, 'Unicorn' SpiritAnimal, 'Rainbow' Location;"
);
SELECT Top 0 'Billy Goat' Creature, 'Unicorn' SpiritAnimal, 'Rainbow' Location;"
);
var
query
=
connection
.
QueryMultiple
(
"#TestEmptyResults"
,
commandType
:
CommandType
.
StoredProcedure
);
var
query
=
connection
.
QueryMultiple
(
"#TestEmptyResults"
,
commandType
:
CommandType
.
StoredProcedure
);
var
result1
=
query
.
Read
<
Issue327_Person
>();
var
result1
=
query
.
Read
<
Issue327_Person
>();
var
result2
=
query
.
Read
<
Issue327_Magic
>();
var
result2
=
query
.
Read
<
Issue327_Magic
>();
...
@@ -150,15 +152,16 @@ public void TestProcSupport()
...
@@ -150,15 +152,16 @@ public void TestProcSupport()
p
.
Add
(
"b"
,
dbType
:
DbType
.
Int32
,
direction
:
ParameterDirection
.
Output
);
p
.
Add
(
"b"
,
dbType
:
DbType
.
Int32
,
direction
:
ParameterDirection
.
Output
);
p
.
Add
(
"c"
,
dbType
:
DbType
.
Int32
,
direction
:
ParameterDirection
.
ReturnValue
);
p
.
Add
(
"c"
,
dbType
:
DbType
.
Int32
,
direction
:
ParameterDirection
.
ReturnValue
);
connection
.
Execute
(
@"create proc #TestProc
connection
.
Execute
(
@"
@a int,
create proc #TestProc
@b int output
@a int,
as
@b int output
begin
as
set @b = 999
begin
select 1111
set @b = 999
return @a
select 1111
end"
);
return @a
end"
);
Assert
.
Equal
(
1111
,
connection
.
Query
<
int
>(
"#TestProc"
,
p
,
commandType
:
CommandType
.
StoredProcedure
).
First
());
Assert
.
Equal
(
1111
,
connection
.
Query
<
int
>(
"#TestProc"
,
p
,
commandType
:
CommandType
.
StoredProcedure
).
First
());
Assert
.
Equal
(
11
,
p
.
Get
<
int
>(
"c"
));
Assert
.
Equal
(
11
,
p
.
Get
<
int
>(
"c"
));
...
@@ -187,17 +190,15 @@ public void TestListOfAnsiStrings()
...
@@ -187,17 +190,15 @@ public void TestListOfAnsiStrings()
[
Fact
]
[
Fact
]
public
void
TestDateTime2PrecisionPreservedInDynamicParameters
()
public
void
TestDateTime2PrecisionPreservedInDynamicParameters
()
{
{
const
string
tempSPName
=
"#"
+
nameof
(
TestDateTime2PrecisionPreservedInDynamicParameters
);
DateTime
datetimeDefault
=
new
DateTime
(
2000
,
1
,
1
,
0
,
0
,
0
,
DateTimeKind
.
Utc
);
DateTime
datetimeDefault
=
new
DateTime
(
2000
,
1
,
1
,
0
,
0
,
0
,
DateTimeKind
.
Utc
);
DateTime
datetime2
=
datetimeDefault
.
AddTicks
(
1
);
// Add 100 ns
DateTime
datetime2
=
datetimeDefault
.
AddTicks
(
1
);
// Add 100 ns
Assert
.
True
(
datetimeDefault
<
datetime2
);
Assert
.
True
(
datetimeDefault
<
datetime2
);
var
p
=
new
DynamicParameters
();
connection
.
Execute
(
// Note: parameters declared as DateTime2
$@"create proc
{
tempSPName
}
p
.
Add
(
"a"
,
datetime2
,
dbType
:
DbType
.
DateTime2
,
direction
:
ParameterDirection
.
Input
);
p
.
Add
(
"b"
,
dbType
:
DbType
.
DateTime2
,
direction
:
ParameterDirection
.
Output
);
connection
.
Execute
(
@"create proc #TestProc
@a datetime2,
@a datetime2,
@b datetime2 output
@b datetime2 output
as
as
...
@@ -205,26 +206,33 @@ public void TestDateTime2PrecisionPreservedInDynamicParameters()
...
@@ -205,26 +206,33 @@ public void TestDateTime2PrecisionPreservedInDynamicParameters()
set @b = @a
set @b = @a
select DATEADD(ns, -100, @b)
select DATEADD(ns, -100, @b)
end"
);
end"
);
DateTime
fromSelect
=
connection
.
Query
<
DateTime
>(
"#TestProc"
,
p
,
commandType
:
CommandType
.
StoredProcedure
).
First
();
var
p
=
new
DynamicParameters
();
// Note: parameters declared as DateTime2
p
.
Add
(
"a"
,
datetime2
,
dbType
:
DbType
.
DateTime2
,
direction
:
ParameterDirection
.
Input
);
p
.
Add
(
"b"
,
dbType
:
DbType
.
DateTime2
,
direction
:
ParameterDirection
.
Output
);
DateTime
fromSelect
=
connection
.
Query
<
DateTime
>(
tempSPName
,
p
,
commandType
:
CommandType
.
StoredProcedure
).
First
();
Assert
.
Equal
(
datetimeDefault
,
fromSelect
);
Assert
.
Equal
(
datetimeDefault
,
fromSelect
);
Assert
.
Equal
(
datetime2
,
p
.
Get
<
DateTime
>(
"b"
));
Assert
.
Equal
(
datetime2
,
p
.
Get
<
DateTime
>(
"b"
));
}
}
[
Fact
]
[
Theory
()]
public
void
TestDateTime2LosePrecisionInDynamicParameters
()
[
InlineData
(
null
)]
[
InlineData
(
DbType
.
DateTime
)]
public
void
TestDateTime2LosePrecisionInDynamicParameters
(
DbType
?
dbType
)
{
{
const
string
tempSPName
=
"#"
+
nameof
(
TestDateTime2LosePrecisionInDynamicParameters
);
DateTime
datetimeDefault
=
new
DateTime
(
2000
,
1
,
1
,
0
,
0
,
0
,
DateTimeKind
.
Utc
);
DateTime
datetimeDefault
=
new
DateTime
(
2000
,
1
,
1
,
0
,
0
,
0
,
DateTimeKind
.
Utc
);
DateTime
datetime2
=
datetimeDefault
.
AddTicks
(
1
);
// Add 100 ns
DateTime
datetime2
=
datetimeDefault
.
AddTicks
(
1
);
// Add 100 ns
Assert
.
True
(
datetimeDefault
<
datetime2
);
Assert
.
True
(
datetimeDefault
<
datetime2
);
var
p
=
new
DynamicParameters
();
connection
.
Execute
(
// Note: parameters declared as DateTime but SP has them as DateTime2
$@"create proc
{
tempSPName
}
p
.
Add
(
"a"
,
datetime2
,
dbType
:
DbType
.
DateTime
,
direction
:
ParameterDirection
.
Input
);
p
.
Add
(
"b"
,
dbType
:
DbType
.
DateTime
,
direction
:
ParameterDirection
.
Output
);
connection
.
Execute
(
@"create proc #TestProc
@a datetime2,
@a datetime2,
@b datetime2 output
@b datetime2 output
as
as
...
@@ -233,11 +241,17 @@ public void TestDateTime2LosePrecisionInDynamicParameters()
...
@@ -233,11 +241,17 @@ public void TestDateTime2LosePrecisionInDynamicParameters()
select @b
select @b
end"
);
end"
);
DateTime
fromSelect
=
connection
.
Query
<
DateTime
>(
"#TestProc"
,
p
,
commandType
:
CommandType
.
StoredProcedure
).
First
();
var
p
=
new
DynamicParameters
();
// Note: input parameter declared as DateTime (or implicitly as this) but SP has DateTime2
p
.
Add
(
"a"
,
datetime2
,
dbType
:
dbType
,
direction
:
ParameterDirection
.
Input
);
p
.
Add
(
"b"
,
dbType
:
DbType
.
DateTime
,
direction
:
ParameterDirection
.
Output
);
DateTime
fromSelect
=
connection
.
Query
<
DateTime
>(
tempSPName
,
p
,
commandType
:
CommandType
.
StoredProcedure
).
First
();
// @a truncates to datetimeDefault when passed into SP by DynamicParameters, add 100ns and it comes out as DateTime2
// @a truncates to datetimeDefault when passed into SP by DynamicParameters, add 100ns and it comes out as DateTime2
Assert
.
Equal
(
datetime2
,
fromSelect
);
Assert
.
Equal
(
datetime2
,
fromSelect
);
// @b gets set to datetime2 value but is truncated back to DbType.DateTime by DynamicParameter
s
declaration
// @b gets set to datetime2 value but is truncated back to DbType.DateTime by DynamicParameter
's Output
declaration
Assert
.
Equal
(
datetimeDefault
,
p
.
Get
<
DateTime
>(
"b"
));
Assert
.
Equal
(
datetimeDefault
,
p
.
Get
<
DateTime
>(
"b"
));
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment