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
Show 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
...
@@ -63,15 +63,14 @@ public void TestIssue17648290()
...
@@ -63,15 +63,14 @@ 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
(
@"CREATE PROCEDURE #up_MessageProcessed_get
@Code varchar(10),
@Code varchar(10),
@MessageControlID varchar(22),
@MessageControlID varchar(22),
@SuccessCode int OUTPUT,
@SuccessCode int OUTPUT,
@ErrorDescription varchar(255) OUTPUT
@ErrorDescription varchar(255) OUTPUT
AS
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'
...
@@ -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
...
@@ -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
(
@"
create proc #TestProc
@a int,
@a int,
@b int output
@b int output
as
as
begin
begin
set @b = 999
set @b = 999
select 1111
select 1111
return @a
return @a
end"
);
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