Skip to content

Commit

Permalink
netstandard2.0 functionality (w/ runtime breaks)
Browse files Browse the repository at this point in the history
This adds a netstandard2.0 build to Dapper (and StrongName until v2),
adds a netstandard2.0 test lineup, restores most functionality (except
UDTs for SQL, e.g. .UdtTypeName isn't in netstandard2), and also breaks
things not actually implemented or implemented correctly in
netstandard2.0. Pushing this up so we can work through these with the
.NET teams.

Several things are still broken here (and fail tests):
- Parameter decimal values (not filed yet)
- DataTables as parameters
(https://github.com/dotnet/corefx/issues/19708)
- .GetSchemaTable() (not yet filed, implementation is completely missing
from SqlDataReader in CoreFX)

While the compile is clean, the above are runtime issues.
`SqlParameter.UdtTypeName` is a separate issue, that one just wasn't in
`netstandard2.0` at all...so we can't support UDTs there until it is.
See https://github.com/dotnet/corefx/issues/17126 for details.
  • Loading branch information
NickCraver committed May 12, 2017
1 parent d72ae17 commit 7e5bd30
Show file tree
Hide file tree
Showing 37 changed files with 130 additions and 167 deletions.
8 changes: 4 additions & 4 deletions Dapper.Contrib/SqlMapperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

using Dapper;

#if COREFX
#if NETSTANDARD1_3
using DataException = System.InvalidOperationException;
#else
using System.Threading;
Expand Down Expand Up @@ -274,7 +274,7 @@ private static string GetTableName(Type type)
{
//NOTE: This as dynamic trick should be able to handle both our own Table-attribute as well as the one in EntityFramework
var tableAttr = type
#if COREFX
#if NETSTANDARD1_3
.GetTypeInfo()
#endif
.GetCustomAttributes(false).SingleOrDefault(attr => attr.GetType().Name == "TableAttribute") as dynamic;
Expand Down Expand Up @@ -516,7 +516,7 @@ private static class ProxyGenerator

private static AssemblyBuilder GetAsmBuilder(string name)
{
#if COREFX
#if NETSTANDARD1_3
return AssemblyBuilder.DefineDynamicAssembly(new AssemblyName { Name = name }, AssemblyBuilderAccess.Run);
#else
return Thread.GetDomain().DefineDynamicAssembly(new AssemblyName { Name = name }, AssemblyBuilderAccess.Run);
Expand Down Expand Up @@ -551,7 +551,7 @@ public static T GetInterfaceProxy<T>()
CreateProperty<T>(typeBuilder, property.Name, property.PropertyType, setIsDirtyMethod, isId);
}

#if COREFX
#if NETSTANDARD1_3
var generatedType = typeBuilder.CreateTypeInfo().AsType();
#else
var generatedType = typeBuilder.CreateType();
Expand Down
7 changes: 6 additions & 1 deletion Dapper.StrongName/Dapper.StrongName.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Title>Dapper (Strong Named)</Title>
<Description>A high performance Micro-ORM supporting SQL Server, MySQL, Sqlite, SqlCE, Firebird etc..</Description>
<Authors>Sam Saffron;Marc Gravell;Nick Craver</Authors>
<TargetFrameworks>net40;net45;net451;netstandard1.3</TargetFrameworks>
<TargetFrameworks>net40;net45;net451;netstandard1.3;netstandard2.0</TargetFrameworks>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
</PropertyGroup>
Expand All @@ -30,4 +30,9 @@
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
<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.Reflection.Emit" Version="4.3.0" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
</ItemGroup>
</Project>
12 changes: 4 additions & 8 deletions Dapper.Tests.Contrib/Dapper.Tests.Contrib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
<DebugType>portable</DebugType>
<OutputType>Exe</OutputType>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<TargetFramework>netcoreapp1.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<DefineConstants>$(DefineConstants);COREFX;</DefineConstants>
<TargetFrameworks>netcoreapp1.0;netcoreapp2.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Dapper.Tests\Helpers\Assert.cs;..\Dapper.Tests\Helpers\XunitSkippable.cs;..\Dapper\TypeExtensions.cs" />
Expand All @@ -19,15 +16,14 @@
<ProjectReference Include="..\Dapper\Dapper.csproj" />
<ProjectReference Include="..\Dapper.Contrib\Dapper.Contrib.csproj" />
<ProjectReference Include="..\Dapper.SqlBuilder\Dapper.SqlBuilder.csproj" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="1.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.3.0" />
<PackageReference Include="MySql.Data" Version="7.0.7-m61" />
<PackageReference Include="System.Data.SqlClient" Version="4.4.0-preview1-25305-02" />
<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" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<PackageReference Include="Microsoft.Data.Sqlite" Version="1.1.0" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
Expand Down
11 changes: 6 additions & 5 deletions Dapper.Tests.Contrib/TestSuite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

using Dapper.Contrib.Extensions;

#if !COREFX
using System.Data.SqlServerCe;
#if !NETCOREAPP1_0
using System.Transactions;
#endif
#if !NETCOREAPP1_0 && !NETCOREAPP2_0
using System.Data.SqlServerCe;
#endif
using FactAttribute = Dapper.Tests.Contrib.SkippableFactAttribute;

namespace Dapper.Tests.Contrib
Expand Down Expand Up @@ -420,7 +422,7 @@ public void InsertGetUpdate()
}
}

#if !COREFX
#if !NETCOREAPP1_0 && !NETCOREAPP2_0
[Fact(Skip = "Not parallel friendly - thinking about how to test this")]
public void InsertWithCustomDbType()
{
Expand Down Expand Up @@ -525,7 +527,7 @@ public void Transactions()
}
}

#if !COREFX
#if !NETCOREAPP1_0
[Fact]
public void TransactionScope()
{
Expand Down Expand Up @@ -632,4 +634,3 @@ public void DeleteAll()
}
}
}

22 changes: 8 additions & 14 deletions Dapper.Tests.Contrib/TestSuites.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
using System;
using Microsoft.Data.Sqlite;
using MySql.Data.MySqlClient;
using System;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using Xunit;
using Xunit.Sdk;
#if COREFX
using Microsoft.Data.Sqlite;
#else
using System.Data.SQLite;

#if !NETCOREAPP1_0 && !NETCOREAPP2_0
using System.Data.SqlServerCe;
using MySql.Data.MySqlClient;
using SqliteConnection = System.Data.SQLite.SQLiteConnection;
#endif

namespace Dapper.Tests.Contrib
Expand Down Expand Up @@ -60,7 +58,6 @@ static SqlServerTestSuite()
}
}

#if !COREFX
public class MySqlServerTestSuite : TestSuite
{
const string DbName = "DapperContribTests";
Expand Down Expand Up @@ -115,14 +112,11 @@ static MySqlServerTestSuite()
}
}
}

// This doesn't work on COREFX right now due to:
// In Visual Studio: Interop loads (works from console, though)
// In general: parameter names, see https://github.com/StackExchange/dapper-dot-net/issues/375

public class SQLiteTestSuite : TestSuite
{
const string FileName = "Test.DB.sqlite";
public static string ConnectionString => $"Filename={FileName};";
public static string ConnectionString => $"Filename=./{FileName};Mode=ReadWriteCreate;";
public override IDbConnection GetConnection() => new SqliteConnection(ConnectionString);

static SQLiteTestSuite()
Expand All @@ -131,7 +125,6 @@ static SQLiteTestSuite()
{
File.Delete(FileName);
}
SqliteConnection.CreateFile(FileName);
using (var connection = new SqliteConnection(ConnectionString))
{
connection.Open();
Expand All @@ -147,6 +140,7 @@ static SQLiteTestSuite()
}
}

#if !NETCOREAPP1_0 && !NETCOREAPP2_0
public class SqlCETestSuite : TestSuite
{
const string FileName = "Test.DB.sdf";
Expand Down
4 changes: 2 additions & 2 deletions Dapper.Tests.Performance/Benchmarks.HandCoded.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class HandCodedBenchmarks : BenchmarkBase
{
private SqlCommand _postCommand;
private SqlParameter _idParam;
#if !COREFX
#if !NETCOREAPP1_0
private DataTable _table;
#endif

Expand All @@ -24,7 +24,7 @@ public void Setup()
Counter1,Counter2,Counter3,Counter4,Counter5,Counter6,Counter7,Counter8,Counter9 from Posts where Id = @Id"
};
_idParam = _postCommand.Parameters.Add("@Id", SqlDbType.Int);
#if !COREFX
#if !NETCOREAPP1_0
_table = new DataTable
{
Columns =
Expand Down
2 changes: 1 addition & 1 deletion Dapper.Tests.Performance/LegacyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public async Task RunAsync(int iterations)
}
}, "Hand Coded");
#if !COREFX
#if !NETSTANDARD1_3
var table = new DataTable
{
Columns =
Expand Down
2 changes: 1 addition & 1 deletion Dapper.Tests.Performance/Linq2Sql/DataClasses.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Dapper.Tests.Performance/Massive/Massive.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !COREFX
#if !NETSTANDARD1_3
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
Expand Down
2 changes: 1 addition & 1 deletion Dapper.Tests.Performance/PetaPoco/PetaPoco.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !COREFX
#if !NETSTANDARD1_3
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
8 changes: 4 additions & 4 deletions Dapper.Tests/AsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public async Task TestMultiClosedConnAsyncViaFirstOrDefault()
}
}

#if !COREFX
#if !NETCOREAPP1_0
[Fact]
public async Task ExecuteReaderOpenAsync()
{
Expand Down Expand Up @@ -318,8 +318,8 @@ await connection.ExecuteAsync("insert #literalin (id) values (@id)", new[] {
new { ids = new[] { 1, 3, 4 } }).ConfigureAwait(false)).Single();
count.IsEqualTo(2);
}

[Fact]
[FactLongRunning]
public async Task RunSequentialVersusParallelAsync()
{
var ids = Enumerable.Range(1, 20000).Select(id => new { id }).ToArray();
Expand All @@ -336,7 +336,7 @@ public async Task RunSequentialVersusParallelAsync()
Console.WriteLine("Pipeline: {0}ms", watch.ElapsedMilliseconds);
}

[Fact]
[FactLongRunning]
public void RunSequentialVersusParallelSync()
{
var ids = Enumerable.Range(1, 20000).Select(id => new { id }).ToArray();
Expand Down
22 changes: 0 additions & 22 deletions Dapper.Tests/ConstructorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,28 +104,6 @@ public bool GetWentThroughProperConstructor()
}
}

#if LINQ2SQL
private class NoDefaultConstructorWithBinary
{
public System.Data.Linq.Binary Value { get; set; }
public int Ynt { get; set; }
public NoDefaultConstructorWithBinary(System.Data.Linq.Binary val)
{
Value = val;
}
}

[Fact]
public void TestNoDefaultConstructorBinary()
{
byte[] orig = new byte[20];
new Random(123456).NextBytes(orig);
var input = new System.Data.Linq.Binary(orig);
var output = connection.Query<NoDefaultConstructorWithBinary>("select @input as val", new { input }).First().Value;
output.ToArray().IsSequenceEqualTo(orig);
}
#endif

[Fact]
public void Issue461_TypeHandlerWorksInConstructor()
{
Expand Down
21 changes: 8 additions & 13 deletions Dapper.Tests/Dapper.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,34 @@
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<TargetFrameworks>net452;netcoreapp1.0</TargetFrameworks>
<TargetFrameworks>net452;netcoreapp1.0;netcoreapp2.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net452' ">
<DefineConstants>$(DefineConstants);NET45;MYSQL;ENTITY_FRAMEWORK;LINQ2SQL;FIREBIRD;SQL_CE;POSTGRESQL;OLEDB;SQLITE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<DefineConstants>$(DefineConstants);COREFX</DefineConstants>
<DefineConstants>$(DefineConstants);ENTITY_FRAMEWORK;LINQ2SQL;SQL_CE;OLEDB</DefineConstants>
</PropertyGroup>
<ItemGroup>
<None Remove="Test.DB.sdf" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Dapper\Dapper.csproj" />
<ProjectReference Include="..\Dapper.Contrib\Dapper.Contrib.csproj" />
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="5.9.0.1" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="1.1.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.3.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.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" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta1-build3642" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
<ProjectReference Include="..\Dapper.EntityFramework\Dapper.EntityFramework.csproj" />
<PackageReference Include="EntityFramework" Version="6.1.3" />
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="5.8.0" />
<PackageReference Include="Microsoft.SqlServer.Compact" Version="4.0.8876.1" />
<PackageReference Include="Microsoft.SqlServer.Types" Version="14.0.314.76" />
<PackageReference Include="MySql.Data" Version="7.0.7-m61" />
<PackageReference Include="Npgsql" Version="3.2.2" />
<PackageReference Include="System.Data.SQLite" Version="1.0.104" />
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Data.Linq" />
Expand All @@ -49,7 +45,6 @@

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<PackageReference Include="System.Ben" Version="1.0.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="1.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 0 additions & 3 deletions Dapper.Tests/DecimalTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace Dapper.Tests
Expand Down
14 changes: 0 additions & 14 deletions Dapper.Tests/Helpers/Attributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,6 @@

namespace Dapper.Tests
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public sealed class FactUnlessCoreCLRAttribute : FactAttribute
{
public FactUnlessCoreCLRAttribute(string url)
{
#if COREFX
Skip = $"CoreFX: {url}";
#endif
this.Url = url;
}

public string Url { get; }
}

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public sealed class FactLongRunningAttribute : FactAttribute
{
Expand Down
Loading

0 comments on commit 7e5bd30

Please sign in to comment.