Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable SqlDataRecord TVPs on netstandard1.3. #802

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Dapper.StrongName/Dapper.StrongName.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<PackageReference Include="System.Collections.Concurrent" Version="4.3.0" />
<PackageReference Include="System.Collections.NonGeneric" Version="4.3.0" />
<PackageReference Include="System.Data.Common" Version="4.3.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.3.0" />
<PackageReference Include="System.Dynamic.Runtime" Version="4.3.0" />
<PackageReference Include="System.Reflection.Emit" Version="4.3.0" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
Expand All @@ -31,7 +31,8 @@
<PackageReference Include="System.Xml.XmlDocument" Version="4.3.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Data.SqlClient" Version="4.4.0-preview1-25305-02" />
<PackageReference Include="System.Data.Common" Version="4.3.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.4.0-preview2-25405-01" />
<PackageReference Include="System.Reflection.Emit" Version="4.3.0" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Dapper.Tests.Contrib/Dapper.Tests.Contrib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PackageReference Include="Microsoft.Data.Sqlite" Version="1.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="MySql.Data" Version="7.0.7-m61" />
<PackageReference Include="System.Data.SqlClient" Version="4.4.0-preview1-25305-02" />
<PackageReference Include="System.Data.SqlClient" Version="4.4.0-preview2-25405-01" />
<PackageReference Include="xunit" Version="2.3.0-beta1-build3642" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta1-build1309" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta1-build3642" />
Expand Down
6 changes: 2 additions & 4 deletions Dapper.Tests.Contrib/TestSuite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@

using Dapper.Contrib.Extensions;

#if !NETCOREAPP1_0
using System.Transactions;
#endif
#if !NETCOREAPP1_0 && !NETCOREAPP2_0
using System.Transactions;
using System.Data.SqlServerCe;
#endif
using FactAttribute = Dapper.Tests.Contrib.SkippableFactAttribute;
Expand Down Expand Up @@ -527,7 +525,7 @@ public void Transactions()
}
}

#if !NETCOREAPP1_0
#if !NETCOREAPP1_0 && !NETCOREAPP2_0
[Fact]
public void TransactionScope()
{
Expand Down
43 changes: 25 additions & 18 deletions Dapper.Tests/AsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,28 +353,35 @@ public void RunSequentialVersusParallelSync()
Console.WriteLine("Pipeline: {0}ms", watch.ElapsedMilliseconds);
}

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

int c, d;
SqlMapper.PurgeQueryCache();
int before = SqlMapper.GetCachedSQLCount();
using (var multi = MarsConnection.QueryMultiple(cmdDef))
[Fact]
public void AssertNoCacheWorksForQueryMultiple()
{
c = multi.Read<int>().Single();
d = multi.Read<int>().Single();
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();
before.IsEqualTo(0);
after.IsEqualTo(0);
c.IsEqualTo(123);
d.IsEqualTo(456);
}
int after = SqlMapper.GetCachedSQLCount();
before.IsEqualTo(0);
after.IsEqualTo(0);
c.IsEqualTo(123);
d.IsEqualTo(456);
}

private class BasicType
Expand Down
79 changes: 0 additions & 79 deletions Dapper.Tests/ConstructorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,85 +104,6 @@ public bool GetWentThroughProperConstructor()
}
}

[Fact]
public void Issue461_TypeHandlerWorksInConstructor()
{
SqlMapper.AddTypeHandler(new Issue461_BlargHandler());

connection.Execute(@"CREATE TABLE #Issue461 (
Id int not null IDENTITY(1,1),
SomeValue nvarchar(50),
SomeBlargValue nvarchar(200),
)");
const string Expected = "abc123def";
var blarg = new Blarg(Expected);
connection.Execute(
"INSERT INTO #Issue461 (SomeValue, SomeBlargValue) VALUES (@value, @blarg)",
new { value = "what up?", blarg });

// test: without constructor
var parameterlessWorks = connection.QuerySingle<Issue461_ParameterlessTypeConstructor>("SELECT * FROM #Issue461");
parameterlessWorks.Id.IsEqualTo(1);
parameterlessWorks.SomeValue.IsEqualTo("what up?");
parameterlessWorks.SomeBlargValue.Value.IsEqualTo(Expected);

// test: via constructor
var parameterDoesNot = connection.QuerySingle<Issue461_ParameterisedTypeConstructor>("SELECT * FROM #Issue461");
parameterDoesNot.Id.IsEqualTo(1);
parameterDoesNot.SomeValue.IsEqualTo("what up?");
parameterDoesNot.SomeBlargValue.Value.IsEqualTo(Expected);
}

// I would usually expect this to be a struct; using a class
// so that we can't pass unexpectedly due to forcing an unsafe cast - want
// to see an InvalidCastException if it is wrong
private class Blarg
{
public Blarg(string value) { Value = value; }
public string Value { get; }
public override string ToString()
{
return Value;
}
}

private class Issue461_BlargHandler : SqlMapper.TypeHandler<Blarg>
{
public override void SetValue(IDbDataParameter parameter, Blarg value)
{
parameter.Value = ((object)value.Value) ?? DBNull.Value;
}

public override Blarg Parse(object value)
{
string s = (value == null || value is DBNull) ? null : Convert.ToString(value);
return new Blarg(s);
}
}

private class Issue461_ParameterlessTypeConstructor
{
public int Id { get; set; }

public string SomeValue { get; set; }
public Blarg SomeBlargValue { get; set; }
}

private class Issue461_ParameterisedTypeConstructor
{
public Issue461_ParameterisedTypeConstructor(int id, string someValue, Blarg someBlargValue)
{
Id = id;
SomeValue = someValue;
SomeBlargValue = someBlargValue;
}

public int Id { get; }

public string SomeValue { get; }
public Blarg SomeBlargValue { get; }
}

public static class AbstractInheritance
{
public abstract class Order
Expand Down
2 changes: 1 addition & 1 deletion Dapper.Tests/Dapper.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="MySql.Data" Version="7.0.7-m61" />
<PackageReference Include="Npgsql" Version="3.2.2" />
<PackageReference Include="System.Data.SqlClient" Version="4.4.0-preview1-25305-02" />
<PackageReference Include="System.Data.SqlClient" Version="4.4.0-preview2-25405-01" />
<PackageReference Include="System.ValueTuple" Version="4.3.0" />
<PackageReference Include="xunit" Version="2.3.0-beta1-build3642" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta1-build1309" />
Expand Down
50 changes: 27 additions & 23 deletions Dapper.Tests/DataReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,40 @@ namespace Dapper.Tests
{
public partial class DataReaderTests : TestBase
{
[Fact]
public void GetSameReaderForSameShape()
[Collection("QueryCacheTests")]
public class DataReaderQueryCacheTests : TestBase
{
var origReader = connection.ExecuteReader("select 'abc' as Name, 123 as Id");
var origParser = origReader.GetRowParser(typeof(HazNameId));
[Fact]
public void GetSameReaderForSameShape()
{
var origReader = connection.ExecuteReader("select 'abc' as Name, 123 as Id");
var origParser = origReader.GetRowParser(typeof(HazNameId));

var typedParser = origReader.GetRowParser<HazNameId>();
var typedParser = origReader.GetRowParser<HazNameId>();

ReferenceEquals(origParser, typedParser).IsEqualTo(true);
ReferenceEquals(origParser, typedParser).IsEqualTo(true);

var list = origReader.Parse<HazNameId>().ToList();
list.Count.IsEqualTo(1);
list[0].Name.IsEqualTo("abc");
list[0].Id.IsEqualTo(123);
origReader.Dispose();
var list = origReader.Parse<HazNameId>().ToList();
list.Count.IsEqualTo(1);
list[0].Name.IsEqualTo("abc");
list[0].Id.IsEqualTo(123);
origReader.Dispose();

var secondReader = connection.ExecuteReader("select 'abc' as Name, 123 as Id");
var secondParser = secondReader.GetRowParser(typeof(HazNameId));
var thirdParser = secondReader.GetRowParser(typeof(HazNameId), 1);
var secondReader = connection.ExecuteReader("select 'abc' as Name, 123 as Id");
var secondParser = secondReader.GetRowParser(typeof(HazNameId));
var thirdParser = secondReader.GetRowParser(typeof(HazNameId), 1);

list = secondReader.Parse<HazNameId>().ToList();
list.Count.IsEqualTo(1);
list[0].Name.IsEqualTo("abc");
list[0].Id.IsEqualTo(123);
secondReader.Dispose();
list = secondReader.Parse<HazNameId>().ToList();
list.Count.IsEqualTo(1);
list[0].Name.IsEqualTo("abc");
list[0].Id.IsEqualTo(123);
secondReader.Dispose();

// now: should be different readers, but same parser
ReferenceEquals(origReader, secondReader).IsEqualTo(false);
ReferenceEquals(origParser, secondParser).IsEqualTo(true);
ReferenceEquals(secondParser, thirdParser).IsEqualTo(false);
// now: should be different readers, but same parser
ReferenceEquals(origReader, secondReader).IsEqualTo(false);
ReferenceEquals(origParser, secondParser).IsEqualTo(true);
ReferenceEquals(secondParser, thirdParser).IsEqualTo(false);
}
}

[Fact]
Expand Down
1 change: 1 addition & 0 deletions Dapper.Tests/NullTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
namespace Dapper.Tests
{
[Collection("QueryCacheTests")]
public class NullTests : TestBase
{
[Fact]
Expand Down
Loading