Skip to content

Commit a9560b3

Browse files
sergiivolchkovNickCraver
authored andcommitted
Enable SqlDataRecord TVPs on netstandard1.3. (DapperLib#802)
* Enable SqlDataRecord TVPs on netstandard1.3. * Update netstandard2.0 SqlClient references to Preview 2. * Skip TransactionScope tests for netcoreapp2.0. - According to https://github.com/dotnet/corefx/issues/12534, ambient transaction enlistment is not included with .net core 2.0. * Update references in Dapper.StrongName. * Disable parallel test run to stabilize flaky type handler tests. * Disable parallel test run by assembly attribute. * Move Issue461 tests to TypeHandlerTests. * Group type handler tests in a collection, re-enable parallelization. - Being part of the same collection, type handler tests will run sequentially. All other tests can run in parallel. * Move tests relying on query cache & type maps to a separate collection.
1 parent 910246b commit a9560b3

16 files changed

Lines changed: 358 additions & 293 deletions

Dapper.StrongName/Dapper.StrongName.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
2323
<PackageReference Include="System.Collections.Concurrent" Version="4.3.0" />
2424
<PackageReference Include="System.Collections.NonGeneric" Version="4.3.0" />
25-
<PackageReference Include="System.Data.Common" Version="4.3.0" />
25+
<PackageReference Include="System.Data.SqlClient" Version="4.3.0" />
2626
<PackageReference Include="System.Dynamic.Runtime" Version="4.3.0" />
2727
<PackageReference Include="System.Reflection.Emit" Version="4.3.0" />
2828
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
@@ -31,7 +31,8 @@
3131
<PackageReference Include="System.Xml.XmlDocument" Version="4.3.0" />
3232
</ItemGroup>
3333
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
34-
<PackageReference Include="System.Data.SqlClient" Version="4.4.0-preview1-25305-02" />
34+
<PackageReference Include="System.Data.Common" Version="4.3.0" />
35+
<PackageReference Include="System.Data.SqlClient" Version="4.4.0-preview2-25405-01" />
3536
<PackageReference Include="System.Reflection.Emit" Version="4.3.0" />
3637
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
3738
</ItemGroup>

Dapper.Tests.Contrib/Dapper.Tests.Contrib.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<PackageReference Include="Microsoft.Data.Sqlite" Version="1.1.0" />
2020
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
2121
<PackageReference Include="MySql.Data" Version="7.0.7-m61" />
22-
<PackageReference Include="System.Data.SqlClient" Version="4.4.0-preview1-25305-02" />
22+
<PackageReference Include="System.Data.SqlClient" Version="4.4.0-preview2-25405-01" />
2323
<PackageReference Include="xunit" Version="2.3.0-beta1-build3642" />
2424
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta1-build1309" />
2525
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta1-build3642" />

Dapper.Tests.Contrib/TestSuite.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55

66
using Dapper.Contrib.Extensions;
77

8-
#if !NETCOREAPP1_0
9-
using System.Transactions;
10-
#endif
118
#if !NETCOREAPP1_0 && !NETCOREAPP2_0
9+
using System.Transactions;
1210
using System.Data.SqlServerCe;
1311
#endif
1412
using FactAttribute = Dapper.Tests.Contrib.SkippableFactAttribute;
@@ -527,7 +525,7 @@ public void Transactions()
527525
}
528526
}
529527

530-
#if !NETCOREAPP1_0
528+
#if !NETCOREAPP1_0 && !NETCOREAPP2_0
531529
[Fact]
532530
public void TransactionScope()
533531
{

Dapper.Tests/AsyncTests.cs

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -353,28 +353,35 @@ public void RunSequentialVersusParallelSync()
353353
Console.WriteLine("Pipeline: {0}ms", watch.ElapsedMilliseconds);
354354
}
355355

356-
[Fact]
357-
public void AssertNoCacheWorksForQueryMultiple()
356+
[Collection("QueryCacheTests")]
357+
public class AsyncQueryCacheTests : TestBase
358358
{
359-
const int a = 123, b = 456;
360-
var cmdDef = new CommandDefinition(@"select @a; select @b;", new
361-
{
362-
a, b
363-
}, commandType: CommandType.Text, flags: CommandFlags.NoCache);
359+
private SqlConnection _marsConnection;
360+
private SqlConnection MarsConnection => _marsConnection ?? (_marsConnection = GetOpenConnection(true));
364361

365-
int c, d;
366-
SqlMapper.PurgeQueryCache();
367-
int before = SqlMapper.GetCachedSQLCount();
368-
using (var multi = MarsConnection.QueryMultiple(cmdDef))
362+
[Fact]
363+
public void AssertNoCacheWorksForQueryMultiple()
369364
{
370-
c = multi.Read<int>().Single();
371-
d = multi.Read<int>().Single();
365+
const int a = 123, b = 456;
366+
var cmdDef = new CommandDefinition(@"select @a; select @b;", new
367+
{
368+
a, b
369+
}, commandType: CommandType.Text, flags: CommandFlags.NoCache);
370+
371+
int c, d;
372+
SqlMapper.PurgeQueryCache();
373+
int before = SqlMapper.GetCachedSQLCount();
374+
using (var multi = MarsConnection.QueryMultiple(cmdDef))
375+
{
376+
c = multi.Read<int>().Single();
377+
d = multi.Read<int>().Single();
378+
}
379+
int after = SqlMapper.GetCachedSQLCount();
380+
before.IsEqualTo(0);
381+
after.IsEqualTo(0);
382+
c.IsEqualTo(123);
383+
d.IsEqualTo(456);
372384
}
373-
int after = SqlMapper.GetCachedSQLCount();
374-
before.IsEqualTo(0);
375-
after.IsEqualTo(0);
376-
c.IsEqualTo(123);
377-
d.IsEqualTo(456);
378385
}
379386

380387
private class BasicType

Dapper.Tests/ConstructorTests.cs

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -104,85 +104,6 @@ public bool GetWentThroughProperConstructor()
104104
}
105105
}
106106

107-
[Fact]
108-
public void Issue461_TypeHandlerWorksInConstructor()
109-
{
110-
SqlMapper.AddTypeHandler(new Issue461_BlargHandler());
111-
112-
connection.Execute(@"CREATE TABLE #Issue461 (
113-
Id int not null IDENTITY(1,1),
114-
SomeValue nvarchar(50),
115-
SomeBlargValue nvarchar(200),
116-
)");
117-
const string Expected = "abc123def";
118-
var blarg = new Blarg(Expected);
119-
connection.Execute(
120-
"INSERT INTO #Issue461 (SomeValue, SomeBlargValue) VALUES (@value, @blarg)",
121-
new { value = "what up?", blarg });
122-
123-
// test: without constructor
124-
var parameterlessWorks = connection.QuerySingle<Issue461_ParameterlessTypeConstructor>("SELECT * FROM #Issue461");
125-
parameterlessWorks.Id.IsEqualTo(1);
126-
parameterlessWorks.SomeValue.IsEqualTo("what up?");
127-
parameterlessWorks.SomeBlargValue.Value.IsEqualTo(Expected);
128-
129-
// test: via constructor
130-
var parameterDoesNot = connection.QuerySingle<Issue461_ParameterisedTypeConstructor>("SELECT * FROM #Issue461");
131-
parameterDoesNot.Id.IsEqualTo(1);
132-
parameterDoesNot.SomeValue.IsEqualTo("what up?");
133-
parameterDoesNot.SomeBlargValue.Value.IsEqualTo(Expected);
134-
}
135-
136-
// I would usually expect this to be a struct; using a class
137-
// so that we can't pass unexpectedly due to forcing an unsafe cast - want
138-
// to see an InvalidCastException if it is wrong
139-
private class Blarg
140-
{
141-
public Blarg(string value) { Value = value; }
142-
public string Value { get; }
143-
public override string ToString()
144-
{
145-
return Value;
146-
}
147-
}
148-
149-
private class Issue461_BlargHandler : SqlMapper.TypeHandler<Blarg>
150-
{
151-
public override void SetValue(IDbDataParameter parameter, Blarg value)
152-
{
153-
parameter.Value = ((object)value.Value) ?? DBNull.Value;
154-
}
155-
156-
public override Blarg Parse(object value)
157-
{
158-
string s = (value == null || value is DBNull) ? null : Convert.ToString(value);
159-
return new Blarg(s);
160-
}
161-
}
162-
163-
private class Issue461_ParameterlessTypeConstructor
164-
{
165-
public int Id { get; set; }
166-
167-
public string SomeValue { get; set; }
168-
public Blarg SomeBlargValue { get; set; }
169-
}
170-
171-
private class Issue461_ParameterisedTypeConstructor
172-
{
173-
public Issue461_ParameterisedTypeConstructor(int id, string someValue, Blarg someBlargValue)
174-
{
175-
Id = id;
176-
SomeValue = someValue;
177-
SomeBlargValue = someBlargValue;
178-
}
179-
180-
public int Id { get; }
181-
182-
public string SomeValue { get; }
183-
public Blarg SomeBlargValue { get; }
184-
}
185-
186107
public static class AbstractInheritance
187108
{
188109
public abstract class Order

Dapper.Tests/Dapper.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
2424
<PackageReference Include="MySql.Data" Version="7.0.7-m61" />
2525
<PackageReference Include="Npgsql" Version="3.2.2" />
26-
<PackageReference Include="System.Data.SqlClient" Version="4.4.0-preview1-25305-02" />
26+
<PackageReference Include="System.Data.SqlClient" Version="4.4.0-preview2-25405-01" />
2727
<PackageReference Include="System.ValueTuple" Version="4.3.0" />
2828
<PackageReference Include="xunit" Version="2.3.0-beta1-build3642" />
2929
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta1-build1309" />

Dapper.Tests/DataReaderTests.cs

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,40 @@ namespace Dapper.Tests
66
{
77
public partial class DataReaderTests : TestBase
88
{
9-
[Fact]
10-
public void GetSameReaderForSameShape()
9+
[Collection("QueryCacheTests")]
10+
public class DataReaderQueryCacheTests : TestBase
1111
{
12-
var origReader = connection.ExecuteReader("select 'abc' as Name, 123 as Id");
13-
var origParser = origReader.GetRowParser(typeof(HazNameId));
12+
[Fact]
13+
public void GetSameReaderForSameShape()
14+
{
15+
var origReader = connection.ExecuteReader("select 'abc' as Name, 123 as Id");
16+
var origParser = origReader.GetRowParser(typeof(HazNameId));
1417

15-
var typedParser = origReader.GetRowParser<HazNameId>();
18+
var typedParser = origReader.GetRowParser<HazNameId>();
1619

17-
ReferenceEquals(origParser, typedParser).IsEqualTo(true);
20+
ReferenceEquals(origParser, typedParser).IsEqualTo(true);
1821

19-
var list = origReader.Parse<HazNameId>().ToList();
20-
list.Count.IsEqualTo(1);
21-
list[0].Name.IsEqualTo("abc");
22-
list[0].Id.IsEqualTo(123);
23-
origReader.Dispose();
22+
var list = origReader.Parse<HazNameId>().ToList();
23+
list.Count.IsEqualTo(1);
24+
list[0].Name.IsEqualTo("abc");
25+
list[0].Id.IsEqualTo(123);
26+
origReader.Dispose();
2427

25-
var secondReader = connection.ExecuteReader("select 'abc' as Name, 123 as Id");
26-
var secondParser = secondReader.GetRowParser(typeof(HazNameId));
27-
var thirdParser = secondReader.GetRowParser(typeof(HazNameId), 1);
28+
var secondReader = connection.ExecuteReader("select 'abc' as Name, 123 as Id");
29+
var secondParser = secondReader.GetRowParser(typeof(HazNameId));
30+
var thirdParser = secondReader.GetRowParser(typeof(HazNameId), 1);
2831

29-
list = secondReader.Parse<HazNameId>().ToList();
30-
list.Count.IsEqualTo(1);
31-
list[0].Name.IsEqualTo("abc");
32-
list[0].Id.IsEqualTo(123);
33-
secondReader.Dispose();
32+
list = secondReader.Parse<HazNameId>().ToList();
33+
list.Count.IsEqualTo(1);
34+
list[0].Name.IsEqualTo("abc");
35+
list[0].Id.IsEqualTo(123);
36+
secondReader.Dispose();
3437

35-
// now: should be different readers, but same parser
36-
ReferenceEquals(origReader, secondReader).IsEqualTo(false);
37-
ReferenceEquals(origParser, secondParser).IsEqualTo(true);
38-
ReferenceEquals(secondParser, thirdParser).IsEqualTo(false);
38+
// now: should be different readers, but same parser
39+
ReferenceEquals(origReader, secondReader).IsEqualTo(false);
40+
ReferenceEquals(origParser, secondParser).IsEqualTo(true);
41+
ReferenceEquals(secondParser, thirdParser).IsEqualTo(false);
42+
}
3943
}
4044

4145
[Fact]

Dapper.Tests/NullTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Linq;
33
namespace Dapper.Tests
44
{
5+
[Collection("QueryCacheTests")]
56
public class NullTests : TestBase
67
{
78
[Fact]

0 commit comments

Comments
 (0)