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
65bf506e
Commit
65bf506e
authored
May 10, 2019
by
mgravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prep work for adding Microsoft.Data.SqlClient support/tests
parent
d19d6012
Changes
32
Hide whitespace changes
Inline
Side-by-side
Showing
32 changed files
with
393 additions
and
233 deletions
+393
-233
Dapper.StrongName.csproj
Dapper.StrongName/Dapper.StrongName.csproj
+3
-1
Dapper.Tests.Contrib.csproj
Dapper.Tests.Contrib/Dapper.Tests.Contrib.csproj
+1
-0
AsyncTests.cs
Dapper.Tests/AsyncTests.cs
+56
-38
ConstructorTests.cs
Dapper.Tests/ConstructorTests.cs
+4
-1
Dapper.Tests.csproj
Dapper.Tests/Dapper.Tests.csproj
+5
-3
DataReaderTests.cs
Dapper.Tests/DataReaderTests.cs
+4
-1
DecimalTests.cs
Dapper.Tests/DecimalTests.cs
+3
-1
EnumTests.cs
Dapper.Tests/EnumTests.cs
+3
-1
Attributes.cs
Dapper.Tests/Helpers/Attributes.cs
+5
-5
LiteralTests.cs
Dapper.Tests/LiteralTests.cs
+3
-1
MiscTests.cs
Dapper.Tests/MiscTests.cs
+12
-8
MultiMapTests.cs
Dapper.Tests/MultiMapTests.cs
+3
-1
NullTests.cs
Dapper.Tests/NullTests.cs
+5
-1
ParameterTests.cs
Dapper.Tests/ParameterTests.cs
+18
-10
ProcedureTests.cs
Dapper.Tests/ProcedureTests.cs
+3
-1
EntityFrameworkTests.cs
Dapper.Tests/Providers/EntityFrameworkTests.cs
+4
-1
FirebirdTests.cs
Dapper.Tests/Providers/FirebirdTests.cs
+10
-5
Linq2SqlTests.cs
Dapper.Tests/Providers/Linq2SqlTests.cs
+3
-1
MySQLTests.cs
Dapper.Tests/Providers/MySQLTests.cs
+27
-21
OLDEBTests.cs
Dapper.Tests/Providers/OLDEBTests.cs
+8
-8
PostgresqlTests.cs
Dapper.Tests/Providers/PostgresqlTests.cs
+9
-9
SqliteTests.cs
Dapper.Tests/Providers/SqliteTests.cs
+76
-68
QueryMultipleTests.cs
Dapper.Tests/QueryMultipleTests.cs
+3
-1
TestBase.cs
Dapper.Tests/TestBase.cs
+75
-29
TransactionTests.cs
Dapper.Tests/TransactionTests.cs
+3
-1
TupleTests.cs
Dapper.Tests/TupleTests.cs
+3
-1
TypeHandlerTests.cs
Dapper.Tests/TypeHandlerTests.cs
+5
-1
XmlTests.cs
Dapper.Tests/XmlTests.cs
+3
-1
Dapper.csproj
Dapper/Dapper.csproj
+3
-1
SqlDataRecordHandler.cs
Dapper/SqlDataRecordHandler.cs
+5
-2
SqlDataRecordListTVPParameter.cs
Dapper/SqlDataRecordListTVPParameter.cs
+17
-8
SqlMapper.cs
Dapper/SqlMapper.cs
+11
-2
No files found.
Dapper.StrongName/Dapper.StrongName.csproj
View file @
65bf506e
...
@@ -20,9 +20,11 @@
...
@@ -20,9 +20,11 @@
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' OR '$(TargetFramework)' == 'netstandard2.0'">
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' OR '$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Data.SqlClient" Version="4.6.0" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.4.0" />
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.4.0" />
<!-- it would be nice to use System.Data.Common here, but we need SqlClient for SqlDbType in 1.3, and legacy SqlDataRecord API-->
<PackageReference Include="System.Data.SqlClient" Version="4.6.0" />
</ItemGroup>
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<PackageReference Include="System.Collections.Concurrent" Version="4.3.0" />
<PackageReference Include="System.Collections.Concurrent" Version="4.3.0" />
...
...
Dapper.Tests.Contrib/Dapper.Tests.Contrib.csproj
View file @
65bf506e
...
@@ -21,5 +21,6 @@
...
@@ -21,5 +21,6 @@
<PackageReference Include="MySqlConnector" Version="0.44.1" />
<PackageReference Include="MySqlConnector" Version="0.44.1" />
<PackageReference Include="xunit" Version="$(xUnitVersion)" />
<PackageReference Include="xunit" Version="$(xUnitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(xUnitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(xUnitVersion)" />
<PackageReference Include="System.Data.SqlClient" Version="4.6.0" />
</ItemGroup>
</ItemGroup>
</Project>
</Project>
Dapper.Tests/AsyncTests.cs
View file @
65bf506e
...
@@ -4,15 +4,27 @@
...
@@ -4,15 +4,27 @@
using
System
;
using
System
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
System.Threading
;
using
System.Threading
;
using
System.Data.SqlClient
;
using
Xunit
;
using
Xunit
;
using
System.Data.Common
;
namespace
Dapper.Tests
namespace
Dapper.Tests
{
{
public
class
Tests
:
TestBase
[
Collection
(
NonParallelDefinition
.
Name
)]
public
sealed
class
SystemSqlClientAsyncTests
:
AsyncTests
<
SystemSqlClientProvider
>
{
}
[
Collection
(
NonParallelDefinition
.
Name
)]
public
sealed
class
MicrosoftSqlClientAsyncTests
:
AsyncTests
<
MicrosoftSqlClientProvider
>
{
}
[
Collection
(
NonParallelDefinition
.
Name
)]
public
sealed
class
SystemSqlClientAsyncQueryCacheTests
:
AsyncQueryCacheTests
<
SystemSqlClientProvider
>
{
}
[
Collection
(
NonParallelDefinition
.
Name
)]
public
sealed
class
MicrosoftSqlClientAsyncQueryCacheTests
:
AsyncQueryCacheTests
<
MicrosoftSqlClientProvider
>
{
}
public
abstract
class
AsyncTests
<
TProvider
>
:
TestBase
<
TProvider
>
where
TProvider
:
SqlServerDatabaseProvider
{
{
private
SqlConnection
_marsConnection
;
private
DbConnection
_marsConnection
;
private
SqlConnection
MarsConnection
=>
_marsConnection
??
(
_marsConnection
=
GetOpenConnection
(
true
));
private
DbConnection
MarsConnection
=>
_marsConnection
??
(
_marsConnection
=
Provider
.
GetOpenConnection
(
true
));
[
Fact
]
[
Fact
]
public
async
Task
TestBasicStringUsageAsync
()
public
async
Task
TestBasicStringUsageAsync
()
...
@@ -100,7 +112,7 @@ public void TestLongOperationWithCancellation()
...
@@ -100,7 +112,7 @@ public void TestLongOperationWithCancellation()
}
}
catch
(
AggregateException
agg
)
catch
(
AggregateException
agg
)
{
{
Assert
.
True
(
agg
.
InnerException
is
SqlException
);
Assert
.
True
(
agg
.
InnerException
.
GetType
().
Name
==
"SqlException"
);
}
}
}
}
...
@@ -382,38 +394,6 @@ public void RunSequentialVersusParallelSync()
...
@@ -382,38 +394,6 @@ public void RunSequentialVersusParallelSync()
Console
.
WriteLine
(
"Pipeline: {0}ms"
,
watch
.
ElapsedMilliseconds
);
Console
.
WriteLine
(
"Pipeline: {0}ms"
,
watch
.
ElapsedMilliseconds
);
}
}
[
Collection
(
NonParallelDefinition
.
Name
)]
public
class
AsyncQueryCacheTests
:
TestBase
{
private
SqlConnection
_marsConnection
;
private
SqlConnection
MarsConnection
=>
_marsConnection
??
(
_marsConnection
=
GetOpenConnection
(
true
));
[
Fact
]
public
void
AssertNoCacheWorksForQueryMultiple
()
{
const
int
a
=
123
,
b
=
456
;
var
cmdDef
=
new
CommandDefinition
(
"select @a; select @b;"
,
new
{
a
,
b
},
commandType
:
CommandType
.
Text
,
flags
:
CommandFlags
.
NoCache
);
int
c
,
d
;
SqlMapper
.
PurgeQueryCache
();
int
before
=
SqlMapper
.
GetCachedSQLCount
();
using
(
var
multi
=
MarsConnection
.
QueryMultiple
(
cmdDef
))
{
c
=
multi
.
Read
<
int
>().
Single
();
d
=
multi
.
Read
<
int
>().
Single
();
}
int
after
=
SqlMapper
.
GetCachedSQLCount
();
Assert
.
Equal
(
0
,
before
);
Assert
.
Equal
(
0
,
after
);
Assert
.
Equal
(
123
,
c
);
Assert
.
Equal
(
456
,
d
);
}
}
private
class
BasicType
private
class
BasicType
{
{
public
string
Value
{
get
;
set
;
}
public
string
Value
{
get
;
set
;
}
...
@@ -827,7 +807,45 @@ public async Task Issue563_QueryAsyncShouldThrowException()
...
@@ -827,7 +807,45 @@ public async Task Issue563_QueryAsyncShouldThrowException()
var
data
=
(
await
connection
.
QueryAsync
<
int
>(
"select 1 union all select 2; RAISERROR('after select', 16, 1);"
).
ConfigureAwait
(
false
)).
ToList
();
var
data
=
(
await
connection
.
QueryAsync
<
int
>(
"select 1 union all select 2; RAISERROR('after select', 16, 1);"
).
ConfigureAwait
(
false
)).
ToList
();
Assert
.
True
(
false
,
"Expected Exception"
);
Assert
.
True
(
false
,
"Expected Exception"
);
}
}
catch
(
SqlException
ex
)
when
(
ex
.
Message
==
"after select"
)
{
/* swallow only this */
}
catch
(
Exception
ex
)
when
(
ex
.
GetType
().
Name
==
"SqlException"
&&
ex
.
Message
==
"after select"
)
{
/* swallow only this */
}
}
}
public
abstract
class
AsyncQueryCacheTests
<
TProvider
>
:
TestBase
<
TProvider
>
where
TProvider
:
SqlServerDatabaseProvider
{
private
DbConnection
_marsConnection
;
private
DbConnection
MarsConnection
=>
_marsConnection
??
(
_marsConnection
=
Provider
.
GetOpenConnection
(
true
));
public
override
void
Dispose
()
{
_marsConnection
?.
Dispose
();
_marsConnection
=
null
;
base
.
Dispose
();
}
[
Fact
]
public
void
AssertNoCacheWorksForQueryMultiple
()
{
const
int
a
=
123
,
b
=
456
;
var
cmdDef
=
new
CommandDefinition
(
"select @a; select @b;"
,
new
{
a
,
b
},
commandType
:
CommandType
.
Text
,
flags
:
CommandFlags
.
NoCache
);
int
c
,
d
;
SqlMapper
.
PurgeQueryCache
();
int
before
=
SqlMapper
.
GetCachedSQLCount
();
using
(
var
multi
=
MarsConnection
.
QueryMultiple
(
cmdDef
))
{
c
=
multi
.
Read
<
int
>().
Single
();
d
=
multi
.
Read
<
int
>().
Single
();
}
int
after
=
SqlMapper
.
GetCachedSQLCount
();
Assert
.
Equal
(
0
,
before
);
Assert
.
Equal
(
0
,
after
);
Assert
.
Equal
(
123
,
c
);
Assert
.
Equal
(
456
,
d
);
}
}
}
}
}
}
Dapper.Tests/ConstructorTests.cs
View file @
65bf506e
...
@@ -5,7 +5,10 @@
...
@@ -5,7 +5,10 @@
namespace
Dapper.Tests
namespace
Dapper.Tests
{
{
public
class
ConstructorTests
:
TestBase
public
sealed
class
SystemSqlClientConstructorTests
:
ConstructorTests
<
SystemSqlClientProvider
>
{
}
public
sealed
class
MicrosoftSqlClientConstructorTests
:
ConstructorTests
<
MicrosoftSqlClientProvider
>
{
}
public
abstract
class
ConstructorTests
<
TProvider
>
:
TestBase
<
TProvider
>
where
TProvider
:
DatabaseProvider
{
{
[
Fact
]
[
Fact
]
public
void
TestAbstractInheritance
()
public
void
TestAbstractInheritance
()
...
...
Dapper.Tests/Dapper.Tests.csproj
View file @
65bf506e
...
@@ -6,11 +6,11 @@
...
@@ -6,11 +6,11 @@
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<TargetFrameworks>net4
52;netcoreapp1.0
;netcoreapp2.0</TargetFrameworks>
<TargetFrameworks>net4
6
;netcoreapp2.0</TargetFrameworks>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net4
52
' ">
<PropertyGroup Condition=" '$(TargetFramework)' == 'net4
6
' ">
<DefineConstants>$(DefineConstants);ENTITY_FRAMEWORK;LINQ2SQL;OLEDB</DefineConstants>
<DefineConstants>$(DefineConstants);ENTITY_FRAMEWORK;LINQ2SQL;OLEDB</DefineConstants>
</PropertyGroup>
</PropertyGroup>
<ItemGroup>
<ItemGroup>
...
@@ -26,9 +26,11 @@
...
@@ -26,9 +26,11 @@
<PackageReference Include="System.ValueTuple" Version="4.4.0" />
<PackageReference Include="System.ValueTuple" Version="4.4.0" />
<PackageReference Include="xunit" Version="$(xUnitVersion)" />
<PackageReference Include="xunit" Version="$(xUnitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(xUnitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(xUnitVersion)" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="1.0.19128.1-Preview" />
<PackageReference Include="System.Data.SqlClient" Version="4.6.0" />
</ItemGroup>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net4
52
'">
<ItemGroup Condition="'$(TargetFramework)' == 'net4
6
'">
<ProjectReference Include="..\Dapper.EntityFramework\Dapper.EntityFramework.csproj" />
<ProjectReference Include="..\Dapper.EntityFramework\Dapper.EntityFramework.csproj" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="1.1.1" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="1.1.1" />
<PackageReference Include="Microsoft.SqlServer.Types" Version="14.0.314.76" />
<PackageReference Include="Microsoft.SqlServer.Types" Version="14.0.314.76" />
...
...
Dapper.Tests/DataReaderTests.cs
View file @
65bf506e
...
@@ -4,7 +4,10 @@
...
@@ -4,7 +4,10 @@
namespace
Dapper.Tests
namespace
Dapper.Tests
{
{
public
class
DataReaderTests
:
TestBase
public
sealed
class
SystemSqlClientDataReaderTests
:
DataReaderTests
<
SystemSqlClientProvider
>
{
}
public
sealed
class
MicrosoftSqlClientDataReaderTests
:
DataReaderTests
<
MicrosoftSqlClientProvider
>
{
}
public
abstract
class
DataReaderTests
<
TProvider
>
:
TestBase
<
TProvider
>
where
TProvider
:
DatabaseProvider
{
{
[
Fact
]
[
Fact
]
public
void
GetSameReaderForSameShape
()
public
void
GetSameReaderForSameShape
()
...
...
Dapper.Tests/DecimalTests.cs
View file @
65bf506e
...
@@ -5,7 +5,9 @@
...
@@ -5,7 +5,9 @@
namespace
Dapper.Tests
namespace
Dapper.Tests
{
{
public
class
DecimalTests
:
TestBase
public
sealed
class
SystemSqlClientDecimalTests
:
DecimalTests
<
SystemSqlClientProvider
>
{
}
public
sealed
class
MicrosoftSqlClientDecimalTests
:
DecimalTests
<
MicrosoftSqlClientProvider
>
{
}
public
abstract
class
DecimalTests
<
TProvider
>
:
TestBase
<
TProvider
>
where
TProvider
:
DatabaseProvider
{
{
[
Fact
]
[
Fact
]
public
void
Issue261_Decimals
()
public
void
Issue261_Decimals
()
...
...
Dapper.Tests/EnumTests.cs
View file @
65bf506e
...
@@ -4,7 +4,9 @@
...
@@ -4,7 +4,9 @@
namespace
Dapper.Tests
namespace
Dapper.Tests
{
{
public
class
EnumTests
:
TestBase
public
sealed
class
SystemSqlClientEnumTests
:
EnumTests
<
SystemSqlClientProvider
>
{
}
public
sealed
class
MicrosoftSqlClientEnumTests
:
EnumTests
<
MicrosoftSqlClientProvider
>
{
}
public
abstract
class
EnumTests
<
TProvider
>
:
TestBase
<
TProvider
>
where
TProvider
:
DatabaseProvider
{
{
[
Fact
]
[
Fact
]
public
void
TestEnumWeirdness
()
public
void
TestEnumWeirdness
()
...
...
Dapper.Tests/Helpers/Attributes.cs
View file @
65bf506e
using
System
;
using
System
;
using
System.Data.SqlClient
;
using
Xunit
;
using
Xunit
;
namespace
Dapper.Tests
namespace
Dapper.Tests
...
@@ -32,7 +31,7 @@ public FactRequiredCompatibilityLevelAttribute(int level) : base()
...
@@ -32,7 +31,7 @@ public FactRequiredCompatibilityLevelAttribute(int level) : base()
public
static
readonly
int
DetectedLevel
;
public
static
readonly
int
DetectedLevel
;
static
FactRequiredCompatibilityLevelAttribute
()
static
FactRequiredCompatibilityLevelAttribute
()
{
{
using
(
var
conn
=
TestBas
e
.
GetOpenConnection
())
using
(
var
conn
=
DatabaseProvider
<
SystemSqlClientProvider
>.
Instanc
e
.
GetOpenConnection
())
{
{
try
try
{
{
...
@@ -57,15 +56,16 @@ public FactUnlessCaseSensitiveDatabaseAttribute() : base()
...
@@ -57,15 +56,16 @@ public FactUnlessCaseSensitiveDatabaseAttribute() : base()
public
static
readonly
bool
IsCaseSensitive
;
public
static
readonly
bool
IsCaseSensitive
;
static
FactUnlessCaseSensitiveDatabaseAttribute
()
static
FactUnlessCaseSensitiveDatabaseAttribute
()
{
{
using
(
var
conn
=
TestBas
e
.
GetOpenConnection
())
using
(
var
conn
=
DatabaseProvider
<
SystemSqlClientProvider
>.
Instanc
e
.
GetOpenConnection
())
{
{
try
try
{
{
conn
.
Execute
(
"declare @i int; set @I = 1;"
);
conn
.
Execute
(
"declare @i int; set @I = 1;"
);
}
}
catch
(
SqlException
s
)
catch
(
Exception
ex
)
when
(
ex
.
GetType
().
Name
==
"SqlException"
)
{
{
if
(
s
.
Number
==
137
)
int
err
=
((
dynamic
)
ex
).
Number
;
if
(
err
==
137
)
IsCaseSensitive
=
true
;
IsCaseSensitive
=
true
;
else
else
throw
;
throw
;
...
...
Dapper.Tests/LiteralTests.cs
View file @
65bf506e
...
@@ -3,7 +3,9 @@
...
@@ -3,7 +3,9 @@
namespace
Dapper.Tests
namespace
Dapper.Tests
{
{
public
class
LiteralTests
:
TestBase
public
sealed
class
SystemSqlClientLiteralTests
:
LiteralTests
<
SystemSqlClientProvider
>
{
}
public
sealed
class
MicrosoftSqlClientLiteralTests
:
LiteralTests
<
MicrosoftSqlClientProvider
>
{
}
public
abstract
class
LiteralTests
<
TProvider
>
:
TestBase
<
TProvider
>
where
TProvider
:
DatabaseProvider
{
{
[
Fact
]
[
Fact
]
public
void
LiteralReplacementEnumAndString
()
public
void
LiteralReplacementEnumAndString
()
...
...
Dapper.Tests/MiscTests.cs
View file @
65bf506e
...
@@ -3,7 +3,6 @@
...
@@ -3,7 +3,6 @@
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Data
;
using
System.Data
;
using
System.Data.Common
;
using
System.Data.Common
;
using
System.Data.SqlClient
;
using
System.Diagnostics
;
using
System.Diagnostics
;
using
System.Linq
;
using
System.Linq
;
using
Xunit
;
using
Xunit
;
...
@@ -40,7 +39,9 @@ public GenericUriParser(GenericUriParserOptions options)
...
@@ -40,7 +39,9 @@ public GenericUriParser(GenericUriParserOptions options)
namespace
Dapper.Tests
namespace
Dapper.Tests
{
{
public
class
MiscTests
:
TestBase
public
sealed
class
SystemSqlClientMiscTests
:
MiscTests
<
SystemSqlClientProvider
>
{
}
public
sealed
class
MicrosoftSqlClientMiscTests
:
MiscTests
<
MicrosoftSqlClientProvider
>
{
}
public
abstract
class
MiscTests
<
TProvider
>
:
TestBase
<
TProvider
>
where
TProvider
:
DatabaseProvider
{
{
[
Fact
]
[
Fact
]
public
void
TestNullableGuidSupport
()
public
void
TestNullableGuidSupport
()
...
@@ -1026,13 +1027,16 @@ public void Issue178_SqlServer()
...
@@ -1026,13 +1027,16 @@ public void Issue178_SqlServer()
try
{
connection
.
Execute
(
"create table Issue178(id int not null)"
);
}
try
{
connection
.
Execute
(
"create table Issue178(id int not null)"
);
}
catch
{
/* don't care */
}
catch
{
/* don't care */
}
// raw ADO.net
// raw ADO.net
var
sqlCmd
=
new
SqlCommand
(
sql
,
connection
);
using
(
var
sqlCmd
=
connection
.
CreateCommand
())
using
(
IDataReader
reader1
=
sqlCmd
.
ExecuteReader
())
{
{
Assert
.
True
(
reader1
.
Read
());
sqlCmd
.
CommandText
=
sql
;
Assert
.
Equal
(
0
,
reader1
.
GetInt32
(
0
));
using
(
IDataReader
reader1
=
sqlCmd
.
ExecuteReader
())
Assert
.
False
(
reader1
.
Read
());
{
Assert
.
False
(
reader1
.
NextResult
());
Assert
.
True
(
reader1
.
Read
());
Assert
.
Equal
(
0
,
reader1
.
GetInt32
(
0
));
Assert
.
False
(
reader1
.
Read
());
Assert
.
False
(
reader1
.
NextResult
());
}
}
}
// dapper
// dapper
...
...
Dapper.Tests/MultiMapTests.cs
View file @
65bf506e
...
@@ -6,7 +6,9 @@
...
@@ -6,7 +6,9 @@
namespace
Dapper.Tests
namespace
Dapper.Tests
{
{
public
class
MultiMapTests
:
TestBase
public
sealed
class
SystemSqlClientMultiMapTests
:
MultiMapTests
<
SystemSqlClientProvider
>
{
}
public
sealed
class
MicrosoftSqlClientMultiMapTests
:
MultiMapTests
<
MicrosoftSqlClientProvider
>
{
}
public
abstract
class
MultiMapTests
<
TProvider
>
:
TestBase
<
TProvider
>
where
TProvider
:
DatabaseProvider
{
{
[
Fact
]
[
Fact
]
public
void
ParentChildIdentityAssociations
()
public
void
ParentChildIdentityAssociations
()
...
...
Dapper.Tests/NullTests.cs
View file @
65bf506e
...
@@ -3,7 +3,11 @@
...
@@ -3,7 +3,11 @@
namespace
Dapper.Tests
namespace
Dapper.Tests
{
{
[
Collection
(
NonParallelDefinition
.
Name
)]
[
Collection
(
NonParallelDefinition
.
Name
)]
public
class
NullTests
:
TestBase
public
sealed
class
SystemSqlClientNullTests
:
NullTests
<
SystemSqlClientProvider
>
{
}
[
Collection
(
NonParallelDefinition
.
Name
)]
public
sealed
class
MicrosoftSqlClientNullTests
:
NullTests
<
MicrosoftSqlClientProvider
>
{
}
public
abstract
class
NullTests
<
TProvider
>
:
TestBase
<
TProvider
>
where
TProvider
:
DatabaseProvider
{
{
[
Fact
]
[
Fact
]
public
void
TestNullableDefault
()
public
void
TestNullableDefault
()
...
...
Dapper.Tests/ParameterTests.cs
View file @
65bf506e
...
@@ -3,7 +3,6 @@
...
@@ -3,7 +3,6 @@
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.ComponentModel
;
using
System.Data
;
using
System.Data
;
using
System.Data.SqlClient
;
using
System.Data.SqlTypes
;
using
System.Data.SqlTypes
;
using
System.Dynamic
;
using
System.Dynamic
;
using
System.Linq
;
using
System.Linq
;
...
@@ -19,7 +18,9 @@
...
@@ -19,7 +18,9 @@
namespace
Dapper.Tests
namespace
Dapper.Tests
{
{
public
class
ParameterTests
:
TestBase
public
sealed
class
SystemSqlClientParameterTests
:
ParameterTests
<
SystemSqlClientProvider
>
{
}
public
sealed
class
MicrosoftSqlClientParameterTests
:
ParameterTests
<
MicrosoftSqlClientProvider
>
{
}
public
abstract
class
ParameterTests
<
TProvider
>
:
TestBase
<
TProvider
>
where
TProvider
:
DatabaseProvider
{
{
public
class
DbParams
:
SqlMapper
.
IDynamicParameters
,
IEnumerable
<
IDbDataParameter
>
public
class
DbParams
:
SqlMapper
.
IDynamicParameters
,
IEnumerable
<
IDbDataParameter
>
{
{
...
@@ -37,7 +38,7 @@ void SqlMapper.IDynamicParameters.AddParameters(IDbCommand command, SqlMapper.Id
...
@@ -37,7 +38,7 @@ void SqlMapper.IDynamicParameters.AddParameters(IDbCommand command, SqlMapper.Id
command
.
Parameters
.
Add
(
parameter
);
command
.
Parameters
.
Add
(
parameter
);
}
}
}
}
/* problems with conflicting type
private static List<Microsoft.SqlServer.Server.SqlDataRecord> CreateSqlDataRecordList(IEnumerable<int> numbers)
private static List<Microsoft.SqlServer.Server.SqlDataRecord> CreateSqlDataRecordList(IEnumerable<int> numbers)
{
{
var number_list = new List<Microsoft.SqlServer.Server.SqlDataRecord>();
var number_list = new List<Microsoft.SqlServer.Server.SqlDataRecord>();
...
@@ -55,6 +56,7 @@ private static List<Microsoft.SqlServer.Server.SqlDataRecord> CreateSqlDataRecor
...
@@ -55,6 +56,7 @@ private static List<Microsoft.SqlServer.Server.SqlDataRecord> CreateSqlDataRecor
return number_list;
return number_list;
}
}
private class IntDynamicParam : SqlMapper.IDynamicParameters
private class IntDynamicParam : SqlMapper.IDynamicParameters
{
{
...
@@ -66,7 +68,7 @@ public IntDynamicParam(IEnumerable<int> numbers)
...
@@ -66,7 +68,7 @@ public IntDynamicParam(IEnumerable<int> numbers)
public void AddParameters(IDbCommand command, SqlMapper.Identity identity)
public void AddParameters(IDbCommand command, SqlMapper.Identity identity)
{
{
var
sqlCommand
=
(
SqlCommand
)
command
;
var sqlCommand = (S
ystem.Data.SqlClient.S
qlCommand)command;
sqlCommand.CommandType = CommandType.StoredProcedure;
sqlCommand.CommandType = CommandType.StoredProcedure;
var number_list = CreateSqlDataRecordList(numbers);
var number_list = CreateSqlDataRecordList(numbers);
...
@@ -78,7 +80,7 @@ public void AddParameters(IDbCommand command, SqlMapper.Identity identity)
...
@@ -78,7 +80,7 @@ public void AddParameters(IDbCommand command, SqlMapper.Identity identity)
p.Value = number_list;
p.Value = number_list;
}
}
}
}
private class IntCustomParam : SqlMapper.ICustomQueryParameter
private class IntCustomParam : SqlMapper.ICustomQueryParameter
{
{
private readonly IEnumerable<int> numbers;
private readonly IEnumerable<int> numbers;
...
@@ -89,7 +91,7 @@ public IntCustomParam(IEnumerable<int> numbers)
...
@@ -89,7 +91,7 @@ public IntCustomParam(IEnumerable<int> numbers)
public void AddParameter(IDbCommand command, string name)
public void AddParameter(IDbCommand command, string name)
{
{
var
sqlCommand
=
(
SqlCommand
)
command
;
var sqlCommand = (S
ystem.Data.SqlClient.S
qlCommand)command;
sqlCommand.CommandType = CommandType.StoredProcedure;
sqlCommand.CommandType = CommandType.StoredProcedure;
var number_list = CreateSqlDataRecordList(numbers);
var number_list = CreateSqlDataRecordList(numbers);
...
@@ -101,6 +103,7 @@ public void AddParameter(IDbCommand command, string name)
...
@@ -101,6 +103,7 @@ public void AddParameter(IDbCommand command, string name)
p.Value = number_list;
p.Value = number_list;
}
}
}
}
*/
/* TODO:
/* TODO:
*
*
...
@@ -214,6 +217,9 @@ public void TestMassiveStrings()
...
@@ -214,6 +217,9 @@ public void TestMassiveStrings()
Assert
.
Equal
(
connection
.
Query
<
string
>(
"select @a"
,
new
{
a
=
str
}).
First
(),
str
);
Assert
.
Equal
(
connection
.
Query
<
string
>(
"select @a"
,
new
{
a
=
str
}).
First
(),
str
);
}
}
/* problems with conflicting type
*
[Fact]
[Fact]
public void TestTVPWithAnonymousObject()
public void TestTVPWithAnonymousObject()
{
{
...
@@ -312,7 +318,7 @@ public new void AddParameters(IDbCommand command, SqlMapper.Identity identity)
...
@@ -312,7 +318,7 @@ public new void AddParameters(IDbCommand command, SqlMapper.Identity identity)
{
{
base.AddParameters(command, identity);
base.AddParameters(command, identity);
var
sqlCommand
=
(
SqlCommand
)
command
;
var sqlCommand = (S
ystem.Data.SqlClient.S
qlCommand)command;
sqlCommand.CommandType = CommandType.StoredProcedure;
sqlCommand.CommandType = CommandType.StoredProcedure;
var number_list = CreateSqlDataRecordList(numbers);
var number_list = CreateSqlDataRecordList(numbers);
...
@@ -462,6 +468,8 @@ public void TestSqlDataRecordListParametersWithTypeHandlers()
...
@@ -462,6 +468,8 @@ public void TestSqlDataRecordListParametersWithTypeHandlers()
}
}
}
}
*/
#if !NETCOREAPP1_0
#if !NETCOREAPP1_0
[
Fact
]
[
Fact
]
public
void
DataTableParameters
()
public
void
DataTableParameters
()
...
@@ -612,7 +620,7 @@ public SO29596645_RuleTableValuedParameters(string parameterName)
...
@@ -612,7 +620,7 @@ public SO29596645_RuleTableValuedParameters(string parameterName)
public
void
AddParameters
(
IDbCommand
command
,
SqlMapper
.
Identity
identity
)
public
void
AddParameters
(
IDbCommand
command
,
SqlMapper
.
Identity
identity
)
{
{
Debug
.
WriteLine
(
"> AddParameters"
);
Debug
.
WriteLine
(
"> AddParameters"
);
var
lazy
=
(
SqlCommand
)
command
;
var
lazy
=
(
S
ystem
.
Data
.
SqlClient
.
S
qlCommand
)
command
;
lazy
.
Parameters
.
AddWithValue
(
"Id"
,
7
);
lazy
.
Parameters
.
AddWithValue
(
"Id"
,
7
);
var
table
=
new
DataTable
var
table
=
new
DataTable
{
{
...
@@ -733,8 +741,8 @@ public class HazSqlHierarchy
...
@@ -733,8 +741,8 @@ public class HazSqlHierarchy
public
void
TestCustomParameters
()
public
void
TestCustomParameters
()
{
{
var
args
=
new
DbParams
{
var
args
=
new
DbParams
{
new
Sql
Parameter
(
"foo"
,
123
),
Provider
.
CreateRaw
Parameter
(
"foo"
,
123
),
new
Sql
Parameter
(
"bar"
,
"abc"
)
Provider
.
CreateRaw
Parameter
(
"bar"
,
"abc"
)
};
};
var
result
=
connection
.
Query
(
"select Foo=@foo, Bar=@bar"
,
args
).
Single
();
var
result
=
connection
.
Query
(
"select Foo=@foo, Bar=@bar"
,
args
).
Single
();
int
foo
=
result
.
Foo
;
int
foo
=
result
.
Foo
;
...
...
Dapper.Tests/ProcedureTests.cs
View file @
65bf506e
...
@@ -6,7 +6,9 @@
...
@@ -6,7 +6,9 @@
namespace
Dapper.Tests
namespace
Dapper.Tests
{
{
public
class
ProcedureTests
:
TestBase
public
sealed
class
SystemSqlClientProcedureTests
:
ProcedureTests
<
SystemSqlClientProvider
>
{
}
public
sealed
class
MicrosoftSqlClientProcedureTests
:
ProcedureTests
<
MicrosoftSqlClientProvider
>
{
}
public
abstract
class
ProcedureTests
<
TProvider
>
:
TestBase
<
TProvider
>
where
TProvider
:
DatabaseProvider
{
{
[
Fact
]
[
Fact
]
public
void
TestProcWithOutParameter
()
public
void
TestProcWithOutParameter
()
...
...
Dapper.Tests/Providers/EntityFrameworkTests.cs
View file @
65bf506e
...
@@ -6,8 +6,11 @@
...
@@ -6,8 +6,11 @@
namespace
Dapper.Tests.Providers
namespace
Dapper.Tests.Providers
{
{
public
sealed
class
SystemSqlClientEntityFrameworkTests
:
EntityFrameworkTests
<
SystemSqlClientProvider
>
{
}
public
sealed
class
MicrosoftSqlClientEntityFrameworkTests
:
EntityFrameworkTests
<
MicrosoftSqlClientProvider
>
{
}
[
Collection
(
"TypeHandlerTests"
)]
[
Collection
(
"TypeHandlerTests"
)]
public
class
EntityFrameworkTests
:
TestBase
public
abstract
class
EntityFrameworkTests
<
TProvider
>
:
TestBase
<
TProvider
>
where
TProvider
:
DatabaseProvider
{
{
public
EntityFrameworkTests
()
public
EntityFrameworkTests
()
{
{
...
...
Dapper.Tests/Providers/FirebirdTests.cs
View file @
65bf506e
using
FirebirdSql.Data.FirebirdClient
;
using
FirebirdSql.Data.FirebirdClient
;
using
System.Data
;
using
System.Data
;
using
System.Data.Common
;
using
System.Linq
;
using
System.Linq
;
using
Xunit
;
using
Xunit
;
namespace
Dapper.Tests.Providers
namespace
Dapper.Tests.Providers
{
{
public
class
Firebird
Tests
:
TestBase
public
class
Firebird
Provider
:
DatabaseProvider
{
{
public
override
DbProviderFactory
Factory
=>
FirebirdClientFactory
.
Instance
;
public
override
string
GetConnectionString
()
=>
"initial catalog=localhost:database;user id=SYSDBA;password=masterkey"
;
}
public
class
FirebirdTests
:
TestBase
<
FirebirdProvider
>
{
private
FbConnection
GetOpenFirebirdConnection
()
=>
(
FbConnection
)
Provider
.
GetOpenConnection
();
[
Fact
(
Skip
=
"Bug in Firebird; a PR to fix it has been submitted"
)]
[
Fact
(
Skip
=
"Bug in Firebird; a PR to fix it has been submitted"
)]
public
void
Issue178_Firebird
()
public
void
Issue178_Firebird
()
{
{
const
string
cs
=
"initial catalog=localhost:database;user id=SYSDBA;password=masterkey"
;
using
(
var
connection
=
GetOpenFirebirdConnection
())
using
(
var
connection
=
new
FbConnection
(
cs
))
{
{
connection
.
Open
();
const
string
sql
=
"select count(*) from Issue178"
;
const
string
sql
=
"select count(*) from Issue178"
;
try
{
connection
.
Execute
(
"drop table Issue178"
);
}
try
{
connection
.
Execute
(
"drop table Issue178"
);
}
catch
{
/* don't care */
}
catch
{
/* don't care */
}
...
...
Dapper.Tests/Providers/Linq2SqlTests.cs
View file @
65bf506e
...
@@ -8,7 +8,9 @@
...
@@ -8,7 +8,9 @@
namespace
Dapper.Tests
namespace
Dapper.Tests
{
{
public
class
Linq2SqlTests
:
TestBase
public
sealed
class
SystemSqlClientLinq2SqlTests
:
Linq2SqlTests
<
SystemSqlClientProvider
>
{
}
public
sealed
class
MicrosoftSqlClientLinq2SqlTests
:
Linq2SqlTests
<
MicrosoftSqlClientProvider
>
{
}
public
abstract
class
Linq2SqlTests
<
TProvider
>
:
TestBase
<
TProvider
>
where
TProvider
:
DatabaseProvider
{
{
[
Fact
]
[
Fact
]
public
void
TestLinqBinaryToClass
()
public
void
TestLinqBinaryToClass
()
...
...
Dapper.Tests/Providers/MySQLTests.cs
View file @
65bf506e
using
System
;
using
System
;
using
System.Data.Common
;
using
System.Linq
;
using
System.Linq
;
using
Xunit
;
using
Xunit
;
namespace
Dapper.Tests
namespace
Dapper.Tests
{
{
public
class
MySQLTests
:
TestBase
public
sealed
class
MySqlProvider
:
DatabaseProvider
{
{
private
static
MySql
.
Data
.
MySqlClient
.
MySqlConnection
GetMySqlConnection
(
bool
open
=
true
,
public
override
DbProviderFactory
Factory
=>
MySql
.
Data
.
MySqlClient
.
MySqlClientFactory
.
Instance
;
bool
convertZeroDatetime
=
false
,
bool
allowZeroDatetime
=
false
)
public
override
string
GetConnectionString
()
=>
IsAppVeyor
{
string
cs
=
IsAppVeyor
?
"Server=localhost;Database=test;Uid=root;Pwd=Password12!;"
?
"Server=localhost;Database=test;Uid=root;Pwd=Password12!;"
:
"Server=localhost;Database=tests;Uid=test;Pwd=pass;"
;
:
"Server=localhost;Database=tests;Uid=test;Pwd=pass;"
;
var
csb
=
new
MySql
.
Data
.
MySqlClient
.
MySqlConnectionStringBuilder
(
cs
)
{
public
DbConnection
GetMySqlConnection
(
bool
open
=
true
,
AllowZeroDateTime
=
allowZeroDatetime
,
bool
convertZeroDatetime
=
false
,
bool
allowZeroDatetime
=
false
)
ConvertZeroDateTime
=
convertZeroDatetime
{
};
string
cs
=
GetConnectionString
();
var
conn
=
new
MySql
.
Data
.
MySqlClient
.
MySqlConnection
(
csb
.
ConnectionString
);
var
csb
=
Factory
.
CreateConnectionStringBuilder
();
csb
.
ConnectionString
=
cs
;
((
dynamic
)
csb
).
AllowZeroDateTime
=
allowZeroDatetime
;
((
dynamic
)
csb
).
ConvertZeroDateTime
=
convertZeroDatetime
;
var
conn
=
Factory
.
CreateConnection
();
conn
.
ConnectionString
=
csb
.
ConnectionString
;
if
(
open
)
conn
.
Open
();
if
(
open
)
conn
.
Open
();
return
conn
;
return
conn
;
}
}
}
public
class
MySQLTests
:
TestBase
<
MySqlProvider
>
{
[
FactMySql
]
[
FactMySql
]
public
void
DapperEnumValue_Mysql
()
public
void
DapperEnumValue_Mysql
()
{
{
using
(
var
conn
=
GetMySqlConnection
())
using
(
var
conn
=
Provider
.
GetMySqlConnection
())
{
{
Common
.
DapperEnumValue
(
conn
);
Common
.
DapperEnumValue
(
conn
);
}
}
...
@@ -34,7 +40,7 @@ public void DapperEnumValue_Mysql()
...
@@ -34,7 +40,7 @@ public void DapperEnumValue_Mysql()
[
FactMySql
(
Skip
=
"See https://github.com/StackExchange/Dapper/issues/552, not resolved on the MySQL end."
)]
[
FactMySql
(
Skip
=
"See https://github.com/StackExchange/Dapper/issues/552, not resolved on the MySQL end."
)]
public
void
Issue552_SignedUnsignedBooleans
()
public
void
Issue552_SignedUnsignedBooleans
()
{
{
using
(
var
conn
=
GetMySqlConnection
(
true
,
false
,
false
))
using
(
var
conn
=
Provider
.
GetMySqlConnection
(
true
,
false
,
false
))
{
{
conn
.
Execute
(
@"
conn
.
Execute
(
@"
CREATE TEMPORARY TABLE IF NOT EXISTS `bar` (
CREATE TEMPORARY TABLE IF NOT EXISTS `bar` (
...
@@ -74,7 +80,7 @@ private class MySqlHasBool
...
@@ -74,7 +80,7 @@ private class MySqlHasBool
[
FactMySql
]
[
FactMySql
]
public
void
Issue295_NullableDateTime_MySql_Default
()
public
void
Issue295_NullableDateTime_MySql_Default
()
{
{
using
(
var
conn
=
GetMySqlConnection
(
true
,
false
,
false
))
using
(
var
conn
=
Provider
.
GetMySqlConnection
(
true
,
false
,
false
))
{
{
Common
.
TestDateTime
(
conn
);
Common
.
TestDateTime
(
conn
);
}
}
...
@@ -83,7 +89,7 @@ public void Issue295_NullableDateTime_MySql_Default()
...
@@ -83,7 +89,7 @@ public void Issue295_NullableDateTime_MySql_Default()
[
FactMySql
]
[
FactMySql
]
public
void
Issue295_NullableDateTime_MySql_ConvertZeroDatetime
()
public
void
Issue295_NullableDateTime_MySql_ConvertZeroDatetime
()
{
{
using
(
var
conn
=
GetMySqlConnection
(
true
,
true
,
false
))
using
(
var
conn
=
Provider
.
GetMySqlConnection
(
true
,
true
,
false
))
{
{
Common
.
TestDateTime
(
conn
);
Common
.
TestDateTime
(
conn
);
}
}
...
@@ -92,7 +98,7 @@ public void Issue295_NullableDateTime_MySql_ConvertZeroDatetime()
...
@@ -92,7 +98,7 @@ public void Issue295_NullableDateTime_MySql_ConvertZeroDatetime()
[
FactMySql
(
Skip
=
"See https://github.com/StackExchange/Dapper/issues/295, AllowZeroDateTime=True is not supported"
)]
[
FactMySql
(
Skip
=
"See https://github.com/StackExchange/Dapper/issues/295, AllowZeroDateTime=True is not supported"
)]
public
void
Issue295_NullableDateTime_MySql_AllowZeroDatetime
()
public
void
Issue295_NullableDateTime_MySql_AllowZeroDatetime
()
{
{
using
(
var
conn
=
GetMySqlConnection
(
true
,
false
,
true
))
using
(
var
conn
=
Provider
.
GetMySqlConnection
(
true
,
false
,
true
))
{
{
Common
.
TestDateTime
(
conn
);
Common
.
TestDateTime
(
conn
);
}
}
...
@@ -101,7 +107,7 @@ public void Issue295_NullableDateTime_MySql_AllowZeroDatetime()
...
@@ -101,7 +107,7 @@ public void Issue295_NullableDateTime_MySql_AllowZeroDatetime()
[
FactMySql
(
Skip
=
"See https://github.com/StackExchange/Dapper/issues/295, AllowZeroDateTime=True is not supported"
)]
[
FactMySql
(
Skip
=
"See https://github.com/StackExchange/Dapper/issues/295, AllowZeroDateTime=True is not supported"
)]
public
void
Issue295_NullableDateTime_MySql_ConvertAllowZeroDatetime
()
public
void
Issue295_NullableDateTime_MySql_ConvertAllowZeroDatetime
()
{
{
using
(
var
conn
=
GetMySqlConnection
(
true
,
true
,
true
))
using
(
var
conn
=
Provider
.
GetMySqlConnection
(
true
,
true
,
true
))
{
{
Common
.
TestDateTime
(
conn
);
Common
.
TestDateTime
(
conn
);
}
}
...
@@ -110,7 +116,7 @@ public void Issue295_NullableDateTime_MySql_ConvertAllowZeroDatetime()
...
@@ -110,7 +116,7 @@ public void Issue295_NullableDateTime_MySql_ConvertAllowZeroDatetime()
[
FactMySql
]
[
FactMySql
]
public
void
Issue426_SO34439033_DateTimeGainsTicks
()
public
void
Issue426_SO34439033_DateTimeGainsTicks
()
{
{
using
(
var
conn
=
GetMySqlConnection
(
true
,
true
,
true
))
using
(
var
conn
=
Provider
.
GetMySqlConnection
(
true
,
true
,
true
))
{
{
try
{
conn
.
Execute
(
"drop table Issue426_Test"
);
}
catch
{
/* don't care */
}
try
{
conn
.
Execute
(
"drop table Issue426_Test"
);
}
catch
{
/* don't care */
}
try
{
conn
.
Execute
(
"create table Issue426_Test (Id int not null, Time time not null)"
);
}
catch
{
/* don't care */
}
try
{
conn
.
Execute
(
"create table Issue426_Test (Id int not null, Time time not null)"
);
}
catch
{
/* don't care */
}
...
@@ -133,7 +139,7 @@ public void Issue426_SO34439033_DateTimeGainsTicks()
...
@@ -133,7 +139,7 @@ public void Issue426_SO34439033_DateTimeGainsTicks()
[
FactMySql
]
[
FactMySql
]
public
void
SO36303462_Tinyint_Bools
()
public
void
SO36303462_Tinyint_Bools
()
{
{
using
(
var
conn
=
GetMySqlConnection
(
true
,
true
,
true
))
using
(
var
conn
=
Provider
.
GetMySqlConnection
(
true
,
true
,
true
))
{
{
try
{
conn
.
Execute
(
"drop table SO36303462_Test"
);
}
catch
{
/* don't care */
}
try
{
conn
.
Execute
(
"drop table SO36303462_Test"
);
}
catch
{
/* don't care */
}
conn
.
Execute
(
"create table SO36303462_Test (Id int not null, IsBold tinyint not null);"
);
conn
.
Execute
(
"create table SO36303462_Test (Id int not null, IsBold tinyint not null);"
);
...
@@ -176,7 +182,7 @@ static FactMySqlAttribute()
...
@@ -176,7 +182,7 @@ static FactMySqlAttribute()
{
{
try
try
{
{
using
(
GetMySqlConnection
(
true
))
{
/* just trying to see if it works */
}
using
(
DatabaseProvider
<
MySqlProvider
>.
Instance
.
GetMySqlConnection
(
true
))
{
/* just trying to see if it works */
}
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
...
...
Dapper.Tests/Providers/OLDEBTests.cs
View file @
65bf506e
#
if
OLEDB
#
if
OLEDB
using
System
;
using
System
;
using
System.Data.Common
;
using
System.Data.OleDb
;
using
System.Data.OleDb
;
using
System.Linq
;
using
System.Linq
;
using
Xunit
;
using
Xunit
;
namespace
Dapper.Tests
namespace
Dapper.Tests
{
{
public
class
OL
DEBTests
:
TestBase
public
class
OL
EDBProvider
:
DatabaseProvider
{
{
public
static
string
OleDbConnectionString
=>
public
override
DbProviderFactory
Factory
=>
OleDbFactory
.
Instance
;
public
override
string
GetConnectionString
()
=>
IsAppVeyor
IsAppVeyor
?
@"Provider=SQLOLEDB;Data Source=(local)\SQL2016;Initial Catalog=tempdb;User Id=sa;Password=Password12!"
?
@"Provider=SQLOLEDB;Data Source=(local)\SQL2016;Initial Catalog=tempdb;User Id=sa;Password=Password12!"
:
"Provider=SQLOLEDB;Data Source=.;Initial Catalog=tempdb;Integrated Security=SSPI"
;
:
"Provider=SQLOLEDB;Data Source=.;Initial Catalog=tempdb;Integrated Security=SSPI"
;
}
public
OleDbConnection
GetOleDbConnection
()
public
class
OLDEBTests
:
TestBase
<
OLEDBProvider
>
{
{
var
conn
=
new
OleDbConnection
(
OleDbConnectionString
);
public
OleDbConnection
GetOleDbConnection
()
=>
(
OleDbConnection
)
Provider
.
GetOpenConnection
();
conn
.
Open
();
return
conn
;
}
// see https://stackoverflow.com/q/18847510/23354
// see https://stackoverflow.com/q/18847510/23354
[
Fact
]
[
Fact
]
...
...
Dapper.Tests/Providers/PostgresqlTests.cs
View file @
65bf506e
using
System
;
using
System
;
using
System.Data
;
using
System.Data
;
using
System.Data.Common
;
using
System.Linq
;
using
System.Linq
;
using
Xunit
;
using
Xunit
;
namespace
Dapper.Tests
namespace
Dapper.Tests
{
{
public
class
Postgres
qlTests
:
TestBase
public
class
Postgres
Provider
:
DatabaseProvider
{
{
private
static
Npgsql
.
NpgsqlConnection
GetOpenNpgsqlConnection
()
public
override
DbProviderFactory
Factory
=>
Npgsql
.
NpgsqlFactory
.
Instance
;
{
public
override
string
GetConnectionString
()
=>
IsAppVeyor
string
cs
=
IsAppVeyor
?
"Server=localhost;Port=5432;User Id=postgres;Password=Password12!;Database=test"
?
"Server=localhost;Port=5432;User Id=postgres;Password=Password12!;Database=test"
:
"Server=localhost;Port=5432;User Id=dappertest;Password=dapperpass;Database=dappertest"
;
// ;Encoding = UNICODE
:
"Server=localhost;Port=5432;User Id=dappertest;Password=dapperpass;Database=dappertest"
;
// ;Encoding = UNICODE
var
conn
=
new
Npgsql
.
NpgsqlConnection
(
cs
);
}
conn
.
Open
();
public
class
PostgresqlTests
:
TestBase
<
PostgresProvider
>
return
conn
;
{
}
private
Npgsql
.
NpgsqlConnection
GetOpenNpgsqlConnection
()
=>
(
Npgsql
.
NpgsqlConnection
)
Provider
.
GetOpenConnection
();
private
class
Cat
private
class
Cat
{
{
...
@@ -71,7 +71,7 @@ static FactPostgresqlAttribute()
...
@@ -71,7 +71,7 @@ static FactPostgresqlAttribute()
{
{
try
try
{
{
using
(
GetOpenNpgsql
Connection
())
{
/* just trying to see if it works */
}
using
(
DatabaseProvider
<
PostgresProvider
>.
Instance
.
GetOpen
Connection
())
{
/* just trying to see if it works */
}
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
...
...
Dapper.Tests/Providers/SqliteTests.cs
View file @
65bf506e
using
Microsoft.Data.Sqlite
;
using
Microsoft.Data.Sqlite
;
using
System
;
using
System
;
using
System.Data.Common
;
using
System.Linq
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
Xunit
;
using
Xunit
;
namespace
Dapper.Tests
namespace
Dapper.Tests
{
{
public
class
Sqlite
Tests
:
TestBase
public
class
Sqlite
Provider
:
DatabaseProvider
{
{
protected
static
SqliteConnection
GetSQLiteConnection
(
bool
open
=
true
)
public
override
DbProviderFactory
Factory
=>
SqliteFactory
.
Instance
;
public
override
string
GetConnectionString
()
=>
"Data Source=:memory:"
;
}
public
abstract
class
SqliteTypeTestBase
:
TestBase
<
SqliteProvider
>
{
protected
SqliteConnection
GetSQLiteConnection
(
bool
open
=
true
)
=>
(
SqliteConnection
)(
open
?
Provider
.
GetOpenConnection
()
:
Provider
.
GetClosedConnection
());
[
AttributeUsage
(
AttributeTargets
.
Method
,
AllowMultiple
=
false
)]
public
class
FactSqliteAttribute
:
FactAttribute
{
{
var
connection
=
new
SqliteConnection
(
"Data Source=:memory:"
);
public
override
string
Skip
if
(
open
)
connection
.
Open
();
{
return
connection
;
get
{
return
unavailable
??
base
.
Skip
;
}
set
{
base
.
Skip
=
value
;
}
}
private
static
readonly
string
unavailable
;
static
FactSqliteAttribute
()
{
try
{
using
(
DatabaseProvider
<
SqliteProvider
>.
Instance
.
GetOpenConnection
())
{
}
}
catch
(
Exception
ex
)
{
unavailable
=
$"Sqlite is unavailable:
{
ex
.
Message
}
"
;
}
}
}
}
}
[
Collection
(
NonParallelDefinition
.
Name
)]
public
class
SqliteTypeHandlerTests
:
SqliteTypeTestBase
{
[
FactSqlite
]
[
FactSqlite
]
public
void
DapperEnumValue_Sqlite
()
public
void
Issue466_SqliteHatesOptimizations
()
{
{
using
(
var
connection
=
GetSQLiteConnection
())
using
(
var
connection
=
GetSQLiteConnection
())
{
{
Common
.
DapperEnumValue
(
connection
);
SqlMapper
.
ResetTypeHandlers
();
var
row
=
connection
.
Query
<
HazNameId
>(
"select 42 as Id"
).
First
();
Assert
.
Equal
(
42
,
row
.
Id
);
row
=
connection
.
Query
<
HazNameId
>(
"select 42 as Id"
).
First
();
Assert
.
Equal
(
42
,
row
.
Id
);
SqlMapper
.
ResetTypeHandlers
();
row
=
connection
.
QueryFirst
<
HazNameId
>(
"select 42 as Id"
);
Assert
.
Equal
(
42
,
row
.
Id
);
row
=
connection
.
QueryFirst
<
HazNameId
>(
"select 42 as Id"
);
Assert
.
Equal
(
42
,
row
.
Id
);
}
}
}
}
[
Collection
(
NonParallelDefinition
.
Name
)
]
[
FactSqlite
]
public
class
SqliteTypeHandlerTests
:
TestBase
public
async
Task
Issue466_SqliteHatesOptimizations_Async
()
{
{
[
FactSqlite
]
using
(
var
connection
=
GetSQLiteConnection
())
public
void
Issue466_SqliteHatesOptimizations
()
{
{
using
(
var
connection
=
GetSQLiteConnection
())
SqlMapper
.
ResetTypeHandlers
();
{
var
row
=
(
await
connection
.
QueryAsync
<
HazNameId
>(
"select 42 as Id"
).
ConfigureAwait
(
false
)).
First
();
SqlMapper
.
ResetTypeHandlers
();
Assert
.
Equal
(
42
,
row
.
Id
);
var
row
=
connection
.
Query
<
HazNameId
>(
"select 42 as Id"
).
First
();
row
=
(
await
connection
.
QueryAsync
<
HazNameId
>(
"select 42 as Id"
).
ConfigureAwait
(
false
)).
First
();
Assert
.
Equal
(
42
,
row
.
Id
);
Assert
.
Equal
(
42
,
row
.
Id
);
row
=
connection
.
Query
<
HazNameId
>(
"select 42 as Id"
).
First
();
Assert
.
Equal
(
42
,
row
.
Id
);
SqlMapper
.
ResetTypeHandlers
();
SqlMapper
.
ResetTypeHandlers
();
row
=
connection
.
QueryFirst
<
HazNameId
>(
"select 42 as Id"
);
row
=
await
connection
.
QueryFirstAsync
<
HazNameId
>(
"select 42 as Id"
).
ConfigureAwait
(
false
);
Assert
.
Equal
(
42
,
row
.
Id
);
Assert
.
Equal
(
42
,
row
.
Id
);
row
=
connection
.
QueryFirst
<
HazNameId
>(
"select 42 as Id"
);
row
=
await
connection
.
QueryFirstAsync
<
HazNameId
>(
"select 42 as Id"
).
ConfigureAwait
(
false
);
Assert
.
Equal
(
42
,
row
.
Id
);
Assert
.
Equal
(
42
,
row
.
Id
);
}
}
}
}
}
[
FactSqlite
]
public
class
SqliteTests
:
SqliteTypeTestBase
public
async
Task
Issue466_SqliteHatesOptimizations_Async
()
{
[
FactSqlite
]
public
void
DapperEnumValue_Sqlite
()
{
using
(
var
connection
=
GetSQLiteConnection
())
{
{
using
(
var
connection
=
GetSQLiteConnection
())
Common
.
DapperEnumValue
(
connection
);
{
SqlMapper
.
ResetTypeHandlers
();
var
row
=
(
await
connection
.
QueryAsync
<
HazNameId
>(
"select 42 as Id"
).
ConfigureAwait
(
false
)).
First
();
Assert
.
Equal
(
42
,
row
.
Id
);
row
=
(
await
connection
.
QueryAsync
<
HazNameId
>(
"select 42 as Id"
).
ConfigureAwait
(
false
)).
First
();
Assert
.
Equal
(
42
,
row
.
Id
);
SqlMapper
.
ResetTypeHandlers
();
row
=
await
connection
.
QueryFirstAsync
<
HazNameId
>(
"select 42 as Id"
).
ConfigureAwait
(
false
);
Assert
.
Equal
(
42
,
row
.
Id
);
row
=
await
connection
.
QueryFirstAsync
<
HazNameId
>(
"select 42 as Id"
).
ConfigureAwait
(
false
);
Assert
.
Equal
(
42
,
row
.
Id
);
}
}
}
}
}
[
FactSqlite
]
[
FactSqlite
]
public
void
Isse467_SqliteLikesParametersWithPrefix
()
public
void
Isse467_SqliteLikesParametersWithPrefix
()
{
{
...
@@ -89,32 +123,6 @@ private void Isse467_SqliteParameterNaming(bool prefix)
...
@@ -89,32 +123,6 @@ private void Isse467_SqliteParameterNaming(bool prefix)
var
i
=
Convert
.
ToInt32
(
cmd
.
ExecuteScalar
());
var
i
=
Convert
.
ToInt32
(
cmd
.
ExecuteScalar
());
Assert
.
Equal
(
42
,
i
);
Assert
.
Equal
(
42
,
i
);
}
}
}
}
[
AttributeUsage
(
AttributeTargets
.
Method
,
AllowMultiple
=
false
)]
public
class
FactSqliteAttribute
:
FactAttribute
{
public
override
string
Skip
{
get
{
return
unavailable
??
base
.
Skip
;
}
set
{
base
.
Skip
=
value
;
}
}
private
static
readonly
string
unavailable
;
static
FactSqliteAttribute
()
{
try
{
using
(
GetSQLiteConnection
())
{
}
}
catch
(
Exception
ex
)
{
unavailable
=
$"Sqlite is unavailable:
{
ex
.
Message
}
"
;
}
}
}
}
}
}
}
\ No newline at end of file
Dapper.Tests/QueryMultipleTests.cs
View file @
65bf506e
...
@@ -6,7 +6,9 @@
...
@@ -6,7 +6,9 @@
namespace
Dapper.Tests
namespace
Dapper.Tests
{
{
public
class
QueryMultipleTests
:
TestBase
public
sealed
class
SystemSqlClientQueryMultipleTests
:
QueryMultipleTests
<
SystemSqlClientProvider
>
{
}
public
sealed
class
MicrosoftSqlClientQueryMultipleTests
:
QueryMultipleTests
<
MicrosoftSqlClientProvider
>
{
}
public
abstract
class
QueryMultipleTests
<
TProvider
>
:
TestBase
<
TProvider
>
where
TProvider
:
DatabaseProvider
{
{
[
Fact
]
[
Fact
]
public
void
TestQueryMultipleBuffered
()
public
void
TestQueryMultipleBuffered
()
...
...
Dapper.Tests/TestBase.cs
View file @
65bf506e
using
System
;
using
System
;
using
System.Data
;
using
System.Data
;
using
System.Data.SqlClient
;
using
System.Globalization
;
using
System.Globalization
;
using
Xunit
;
using
Xunit
;
using
System.Data.Common
;
#if !NETCOREAPP1_0
#if !NETCOREAPP1_0
using
System.Threading
;
using
System.Threading
;
#endif
#endif
namespace
Dapper.Tests
namespace
Dapper.Tests
{
{
public
abstract
class
TestBase
:
IDisposable
public
static
class
DatabaseProvider
<
TProvider
>
where
TProvider
:
DatabaseProvider
{
{
protected
static
readonly
bool
IsAppVeyor
=
Environment
.
GetEnvironmentVariable
(
"Appveyor"
)?.
ToUpperInvariant
()
==
"TRUE"
;
public
static
TProvider
Instance
{
get
;
}
=
Activator
.
CreateInstance
<
TProvider
>();
}
public
static
string
ConnectionString
=>
public
abstract
class
DatabaseProvider
IsAppVeyor
{
?
@"Server=(local)\SQL2016;Database=tempdb;User ID=sa;Password=Password12!"
public
abstract
DbProviderFactory
Factory
{
get
;
}
:
"Data Source=.;Initial Catalog=tempdb;Integrated Security=True"
;
protected
SqlConnection
_connection
;
public
static
bool
IsAppVeyor
{
get
;
}
=
Environment
.
GetEnvironmentVariable
(
"Appveyor"
)?.
ToUpperInvariant
()
==
"TRUE"
;
protected
SqlConnection
connection
=>
_connection
??
(
_connection
=
GetOpenConnection
());
public
virtual
void
Dispose
()
{
}
public
abstract
string
GetConnectionString
();
public
static
SqlConnection
GetOpenConnection
(
bool
mars
=
false
)
public
DbConnection
GetOpenConnection
(
)
{
{
var
cs
=
ConnectionString
;
var
conn
=
Factory
.
CreateConnection
();
if
(
mars
)
conn
.
ConnectionString
=
GetConnectionString
();
{
conn
.
Open
();
var
scsb
=
new
SqlConnectionStringBuilder
(
cs
)
if
(
conn
.
State
!=
ConnectionState
.
Open
)
throw
new
InvalidOperationException
(
"should be open!"
);
{
return
conn
;
MultipleActiveResultSets
=
true
};
cs
=
scsb
.
ConnectionString
;
}
var
connection
=
new
SqlConnection
(
cs
);
connection
.
Open
();
return
connection
;
}
}
public
Sql
Connection
GetClosedConnection
()
public
Db
Connection
GetClosedConnection
()
{
{
var
conn
=
new
SqlConnection
(
ConnectionString
);
var
conn
=
Factory
.
CreateConnection
();
conn
.
ConnectionString
=
GetConnectionString
();
if
(
conn
.
State
!=
ConnectionState
.
Closed
)
throw
new
InvalidOperationException
(
"should be closed!"
);
if
(
conn
.
State
!=
ConnectionState
.
Closed
)
throw
new
InvalidOperationException
(
"should be closed!"
);
return
conn
;
return
conn
;
}
}
public
DbParameter
CreateRawParameter
(
string
name
,
object
value
)
{
var
p
=
Factory
.
CreateParameter
();
p
.
ParameterName
=
name
;
p
.
Value
=
value
??
DBNull
.
Value
;
return
p
;
}
}
public
abstract
class
SqlServerDatabaseProvider
:
DatabaseProvider
{
public
override
string
GetConnectionString
()
=>
IsAppVeyor
?
@"Server=(local)\SQL2016;Database=tempdb;User ID=sa;Password=Password12!"
:
"Data Source=.;Initial Catalog=tempdb;Integrated Security=True"
;
public
DbConnection
GetOpenConnection
(
bool
mars
)
{
if
(!
mars
)
return
GetOpenConnection
();
var
scsb
=
Factory
.
CreateConnectionStringBuilder
();
scsb
.
ConnectionString
=
GetConnectionString
();
((
dynamic
)
scsb
).
MultipleActiveResultSets
=
true
;
var
conn
=
Factory
.
CreateConnection
();
conn
.
ConnectionString
=
scsb
.
ConnectionString
;
conn
.
Open
();
if
(
conn
.
State
!=
ConnectionState
.
Open
)
throw
new
InvalidOperationException
(
"should be open!"
);
return
conn
;
}
}
public
sealed
class
SystemSqlClientProvider
:
SqlServerDatabaseProvider
{
public
override
DbProviderFactory
Factory
=>
System
.
Data
.
SqlClient
.
SqlClientFactory
.
Instance
;
}
public
sealed
class
MicrosoftSqlClientProvider
:
SqlServerDatabaseProvider
{
public
override
DbProviderFactory
Factory
=>
Microsoft
.
Data
.
SqlClient
.
SqlClientFactory
.
Instance
;
}
public
abstract
class
TestBase
<
TProvider
>
:
IDisposable
where
TProvider
:
DatabaseProvider
{
protected
DbConnection
GetOpenConnection
()
=>
Provider
.
GetOpenConnection
();
protected
DbConnection
GetClosedConnection
()
=>
Provider
.
GetClosedConnection
();
protected
DbConnection
_connection
;
protected
DbConnection
connection
=>
_connection
??
(
_connection
=
Provider
.
GetOpenConnection
());
public
TProvider
Provider
{
get
;
}
=
DatabaseProvider
<
TProvider
>.
Instance
;
protected
static
CultureInfo
ActiveCulture
protected
static
CultureInfo
ActiveCulture
{
{
#if NETCOREAPP1_0
#if NETCOREAPP1_0
...
@@ -58,7 +100,10 @@ protected static CultureInfo ActiveCulture
...
@@ -58,7 +100,10 @@ protected static CultureInfo ActiveCulture
static
TestBase
()
static
TestBase
()
{
{
Console
.
WriteLine
(
"Dapper: "
+
typeof
(
SqlMapper
).
AssemblyQualifiedName
);
Console
.
WriteLine
(
"Dapper: "
+
typeof
(
SqlMapper
).
AssemblyQualifiedName
);
Console
.
WriteLine
(
"Using Connectionstring: {0}"
,
ConnectionString
);
var
provider
=
DatabaseProvider
<
TProvider
>.
Instance
;
Console
.
WriteLine
(
"Using Connectionstring: {0}"
,
provider
.
GetConnectionString
());
var
factory
=
provider
.
Factory
;
Console
.
WriteLine
(
"Using Provider: {0}"
,
factory
.
GetType
().
FullName
);
#if NETCOREAPP1_0
#if NETCOREAPP1_0
Console
.
WriteLine
(
"CoreCLR (netcoreapp1.0)"
);
Console
.
WriteLine
(
"CoreCLR (netcoreapp1.0)"
);
#else
#else
...
@@ -77,14 +122,15 @@ static TestBase()
...
@@ -77,14 +122,15 @@ static TestBase()
#endif
#endif
}
}
public
void
Dispose
()
public
v
irtual
v
oid
Dispose
()
{
{
_connection
?.
Dispose
();
_connection
?.
Dispose
();
_connection
=
null
;
Provider
?.
Dispose
();
}
}
}
}
[
CollectionDefinition
(
Name
,
DisableParallelization
=
true
)]
public
static
class
NonParallelDefinition
public
class
NonParallelDefinition
:
TestBase
{
{
public
const
string
Name
=
"NonParallel"
;
public
const
string
Name
=
"NonParallel"
;
}
}
...
...
Dapper.Tests/TransactionTests.cs
View file @
65bf506e
...
@@ -7,7 +7,9 @@
...
@@ -7,7 +7,9 @@
namespace
Dapper.Tests
namespace
Dapper.Tests
{
{
public
class
TransactionTests
:
TestBase
public
sealed
class
SystemSqlClientTransactionTests
:
TransactionTests
<
SystemSqlClientProvider
>
{
}
public
sealed
class
MicrosoftSqlClientTransactionTests
:
TransactionTests
<
MicrosoftSqlClientProvider
>
{
}
public
abstract
class
TransactionTests
<
TProvider
>
:
TestBase
<
TProvider
>
where
TProvider
:
DatabaseProvider
{
{
[
Fact
]
[
Fact
]
public
void
TestTransactionCommit
()
public
void
TestTransactionCommit
()
...
...
Dapper.Tests/TupleTests.cs
View file @
65bf506e
...
@@ -3,7 +3,9 @@
...
@@ -3,7 +3,9 @@
namespace
Dapper.Tests
namespace
Dapper.Tests
{
{
public
class
TupleTests
:
TestBase
public
sealed
class
SystemSqlClientTupleTests
:
TupleTests
<
SystemSqlClientProvider
>
{
}
public
sealed
class
MicrosoftSqlClientTupleTests
:
TupleTests
<
MicrosoftSqlClientProvider
>
{
}
public
abstract
class
TupleTests
<
TProvider
>
:
TestBase
<
TProvider
>
where
TProvider
:
DatabaseProvider
{
{
[
Fact
]
[
Fact
]
public
void
TupleStructParameter_Fails_HelpfulMessage
()
public
void
TupleStructParameter_Fails_HelpfulMessage
()
...
...
Dapper.Tests/TypeHandlerTests.cs
View file @
65bf506e
...
@@ -9,7 +9,11 @@
...
@@ -9,7 +9,11 @@
namespace
Dapper.Tests
namespace
Dapper.Tests
{
{
[
Collection
(
NonParallelDefinition
.
Name
)]
[
Collection
(
NonParallelDefinition
.
Name
)]
public
class
TypeHandlerTests
:
TestBase
public
sealed
class
SystemSqlClientTypeHandlerTests
:
TypeHandlerTests
<
SystemSqlClientProvider
>
{
}
[
Collection
(
NonParallelDefinition
.
Name
)]
public
sealed
class
MicrosoftSqlClientTypeHandlerTests
:
TypeHandlerTests
<
MicrosoftSqlClientProvider
>
{
}
public
abstract
class
TypeHandlerTests
<
TProvider
>
:
TestBase
<
TProvider
>
where
TProvider
:
DatabaseProvider
{
{
[
Fact
]
[
Fact
]
public
void
TestChangingDefaultStringTypeMappingToAnsiString
()
public
void
TestChangingDefaultStringTypeMappingToAnsiString
()
...
...
Dapper.Tests/XmlTests.cs
View file @
65bf506e
...
@@ -4,7 +4,9 @@
...
@@ -4,7 +4,9 @@
namespace
Dapper.Tests
namespace
Dapper.Tests
{
{
public
class
XmlTests
:
TestBase
public
sealed
class
SystemSqlClientXmlTests
:
XmlTests
<
SystemSqlClientProvider
>
{
}
public
sealed
class
MicrosoftSqlClientXmlTests
:
XmlTests
<
MicrosoftSqlClientProvider
>
{
}
public
abstract
class
XmlTests
<
TProvider
>
:
TestBase
<
TProvider
>
where
TProvider
:
DatabaseProvider
{
{
[
Fact
]
[
Fact
]
public
void
CommonXmlTypesSupported
()
public
void
CommonXmlTypesSupported
()
...
...
Dapper/Dapper.csproj
View file @
65bf506e
...
@@ -15,9 +15,11 @@
...
@@ -15,9 +15,11 @@
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' OR '$(TargetFramework)' == 'netstandard2.0'">
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' OR '$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Data.SqlClient" Version="4.6.0" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.4.0" />
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.4.0" />
<!-- it would be nice to use System.Data.Common here, but we need SqlClient for SqlDbType in 1.3, and legacy SqlDataRecord API-->
<PackageReference Include="System.Data.SqlClient" Version="4.6.0" />
</ItemGroup>
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<PackageReference Include="System.Collections.Concurrent" Version="4.3.0" />
<PackageReference Include="System.Collections.Concurrent" Version="4.3.0" />
...
...
Dapper/SqlDataRecordHandler.cs
View file @
65bf506e
...
@@ -4,7 +4,10 @@
...
@@ -4,7 +4,10 @@
namespace
Dapper
namespace
Dapper
{
{
internal
sealed
class
SqlDataRecordHandler
:
SqlMapper
.
ITypeHandler
internal
sealed
class
SqlDataRecordHandler
<
T
>
:
SqlMapper
.
ITypeHandler
#if !NETSTANDARD1_3
where
T
:
IDataRecord
#endif
{
{
public
object
Parse
(
Type
destinationType
,
object
value
)
public
object
Parse
(
Type
destinationType
,
object
value
)
{
{
...
@@ -13,7 +16,7 @@ public object Parse(Type destinationType, object value)
...
@@ -13,7 +16,7 @@ public object Parse(Type destinationType, object value)
public
void
SetValue
(
IDbDataParameter
parameter
,
object
value
)
public
void
SetValue
(
IDbDataParameter
parameter
,
object
value
)
{
{
SqlDataRecordListTVPParameter
.
Set
(
parameter
,
value
as
IEnumerable
<
Microsoft
.
SqlServer
.
Server
.
SqlDataRecord
>,
null
);
SqlDataRecordListTVPParameter
<
T
>.
Set
(
parameter
,
value
as
IEnumerable
<
T
>,
null
);
}
}
}
}
}
}
Dapper/SqlDataRecordListTVPParameter.cs
View file @
65bf506e
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Data
;
using
System.Data
;
using
System.Linq
;
using
System.Linq
;
using
System.Reflection
;
using
System.Reflection.Emit
;
namespace
Dapper
namespace
Dapper
{
{
/// <summary>
/// <summary>
/// Used to pass a IEnumerable<SqlDataRecord> as a SqlDataRecordListTVPParameter
/// Used to pass a IEnumerable<SqlDataRecord> as a SqlDataRecordListTVPParameter
/// </summary>
/// </summary>
internal
sealed
class
SqlDataRecordListTVPParameter
:
SqlMapper
.
ICustomQueryParameter
internal
sealed
class
SqlDataRecordListTVPParameter
<
T
>
:
SqlMapper
.
ICustomQueryParameter
#if !NETSTANDARD1_3
where
T
:
IDataRecord
#endif
{
{
private
readonly
IEnumerable
<
Microsoft
.
SqlServer
.
Server
.
SqlDataRecord
>
data
;
private
readonly
IEnumerable
<
T
>
data
;
private
readonly
string
typeName
;
private
readonly
string
typeName
;
/// <summary>
/// <summary>
/// Create a new instance of <see cref="SqlDataRecordListTVPParameter"/>.
/// Create a new instance of <see cref="SqlDataRecordListTVPParameter
<T>
"/>.
/// </summary>
/// </summary>
/// <param name="data">The data records to convert into TVPs.</param>
/// <param name="data">The data records to convert into TVPs.</param>
/// <param name="typeName">The parameter type name.</param>
/// <param name="typeName">The parameter type name.</param>
public
SqlDataRecordListTVPParameter
(
IEnumerable
<
Microsoft
.
SqlServer
.
Server
.
SqlDataRecord
>
data
,
string
typeName
)
public
SqlDataRecordListTVPParameter
(
IEnumerable
<
T
>
data
,
string
typeName
)
{
{
this
.
data
=
data
;
this
.
data
=
data
;
this
.
typeName
=
typeName
;
this
.
typeName
=
typeName
;
...
@@ -30,13 +35,17 @@ void SqlMapper.ICustomQueryParameter.AddParameter(IDbCommand command, string nam
...
@@ -30,13 +35,17 @@ void SqlMapper.ICustomQueryParameter.AddParameter(IDbCommand command, string nam
command
.
Parameters
.
Add
(
param
);
command
.
Parameters
.
Add
(
param
);
}
}
internal
static
void
Set
(
IDbDataParameter
parameter
,
IEnumerable
<
Microsoft
.
SqlServer
.
Server
.
SqlDataRecord
>
data
,
string
typeName
)
internal
static
void
Set
(
IDbDataParameter
parameter
,
IEnumerable
<
T
>
data
,
string
typeName
)
{
{
parameter
.
Value
=
data
!=
null
&&
data
.
Any
()
?
data
:
null
;
parameter
.
Value
=
data
!=
null
&&
data
.
Any
()
?
data
:
null
;
if
(
parameter
is
System
.
Data
.
SqlClient
.
SqlParameter
sqlParam
)
var
type
=
parameter
.
GetType
();
if
(
type
.
Name
==
"SqlParameter"
)
{
{
sqlParam
.
SqlDbType
=
SqlDbType
.
Structured
;
var
prop
=
type
.
GetProperty
(
"SqlDbType"
);
sqlParam
.
TypeName
=
typeName
;
prop
?.
SetValue
(
parameter
,
SqlDbType
.
Structured
);
prop
=
type
.
GetProperty
(
"TypeName"
);
prop
?.
SetValue
(
parameter
,
typeName
);
}
}
}
}
}
}
...
...
Dapper/SqlMapper.cs
View file @
65bf506e
...
@@ -237,7 +237,7 @@ private static void ResetTypeHandlers(bool clone)
...
@@ -237,7 +237,7 @@ private static void ResetTypeHandlers(bool clone)
[
MethodImpl
(
MethodImplOptions
.
NoInlining
)]
[
MethodImpl
(
MethodImplOptions
.
NoInlining
)]
private
static
void
AddSqlDataRecordsTypeHandler
(
bool
clone
)
private
static
void
AddSqlDataRecordsTypeHandler
(
bool
clone
)
{
{
AddTypeHandlerImpl
(
typeof
(
IEnumerable
<
Microsoft
.
SqlServer
.
Server
.
SqlDataRecord
>),
new
SqlDataRecordHandler
(),
clone
);
AddTypeHandlerImpl
(
typeof
(
IEnumerable
<
Microsoft
.
SqlServer
.
Server
.
SqlDataRecord
>),
new
SqlDataRecordHandler
<
Microsoft
.
SqlServer
.
Server
.
SqlDataRecord
>
(),
clone
);
}
}
/// <summary>
/// <summary>
...
@@ -3688,13 +3688,22 @@ public static void SetTypeName(this DataTable table, string typeName)
...
@@ -3688,13 +3688,22 @@ public static void SetTypeName(this DataTable table, string typeName)
table
?.
ExtendedProperties
[
DataTableTypeNameKey
]
as
string
;
table
?.
ExtendedProperties
[
DataTableTypeNameKey
]
as
string
;
#endif
#endif
/// <summary>
/// Used to pass a IEnumerable<SqlDataRecord> as a TableValuedParameter.
/// </summary>
/// <param name="list">The list of records to convert to TVPs.</param>
/// <param name="typeName">The sql parameter type name.</param>
public
static
ICustomQueryParameter
AsTableValuedParameter
<
T
>(
this
IEnumerable
<
T
>
list
,
string
typeName
=
null
)
where
T
:
IDataRecord
=>
new
SqlDataRecordListTVPParameter
<
T
>(
list
,
typeName
);
/// <summary>
/// <summary>
/// Used to pass a IEnumerable<SqlDataRecord> as a TableValuedParameter.
/// Used to pass a IEnumerable<SqlDataRecord> as a TableValuedParameter.
/// </summary>
/// </summary>
/// <param name="list">The list of records to convert to TVPs.</param>
/// <param name="list">The list of records to convert to TVPs.</param>
/// <param name="typeName">The sql parameter type name.</param>
/// <param name="typeName">The sql parameter type name.</param>
public
static
ICustomQueryParameter
AsTableValuedParameter
(
this
IEnumerable
<
Microsoft
.
SqlServer
.
Server
.
SqlDataRecord
>
list
,
string
typeName
=
null
)
=>
public
static
ICustomQueryParameter
AsTableValuedParameter
(
this
IEnumerable
<
Microsoft
.
SqlServer
.
Server
.
SqlDataRecord
>
list
,
string
typeName
=
null
)
=>
new
SqlDataRecordListTVPParameter
(
list
,
typeName
);
new
SqlDataRecordListTVPParameter
<
Microsoft
.
SqlServer
.
Server
.
SqlDataRecord
>(
list
,
typeName
);
// ^^^ retained to avoid missing-method-exception; can presumably drop in a "major"
// one per thread
// one per thread
[
ThreadStatic
]
[
ThreadStatic
]
...
...
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