提交 ec6faf54 编写于 作者: M Marc Gravell

Fixes for CoreCLR and DNX

上级 a161cb5a
......@@ -7,16 +7,16 @@
*/
#if DNXCORE50
using IDbDataParameter = System.Data.Common.DbParameter;
using IDataParameter = System.Data.Common.DbParameter;
using IDbTransaction = System.Data.Common.DbTransaction;
using IDbConnection = System.Data.Common.DbConnection;
using IDbCommand = System.Data.Common.DbCommand;
using IDataReader = System.Data.Common.DbDataReader;
using IDataRecord = System.Data.Common.DbDataReader;
using IDataParameterCollection = System.Data.Common.DbParameterCollection;
using DataException = System.InvalidOperationException;
using ApplicationException = System.InvalidOperationException;
using IDbDataParameter = global::System.Data.Common.DbParameter;
using IDataParameter = global::System.Data.Common.DbParameter;
using IDbTransaction = global::System.Data.Common.DbTransaction;
using IDbConnection = global::System.Data.Common.DbConnection;
using IDbCommand = global::System.Data.Common.DbCommand;
using IDataReader = global::System.Data.Common.DbDataReader;
using IDataRecord = global::System.Data.Common.DbDataReader;
using IDataParameterCollection = global::System.Data.Common.DbParameterCollection;
using DataException = global::System.InvalidOperationException;
using ApplicationException = global::System.InvalidOperationException;
#endif
using System;
......@@ -4907,10 +4907,10 @@ public DynamicParameters Output<T>(T target, Expression<Func<T, object>> express
#if DNXCORE50
lock (cache)
{
#endif
setter = (Action<object, DynamicParameters>)cache[lookup];
#if DNXCORE50
if(!cache.TryGetValue(lookup, out setter)) setter = null;
}
#else
setter = (Action<object, DynamicParameters>)cache[lookup];
#endif
if (setter != null) goto MAKECALLBACK;
......
using System;
using System.Linq;
using System.Data.SqlClient;
using System.Threading.Tasks;
using System.Reflection;
namespace Dapper.DNX.Tests
{
public class Program
{
public void Main()
{
#if DNXCORE50
Console.WriteLine("From: {0}", typeof(int).AssemblyQualifiedName);
#else
Console.WriteLine("Version: {0}", Environment.Version);
#endif
const string connectionString = "Data Source=.;Initial Catalog=tempdb;Integrated Security=True";
using (var conn = new SqlConnection(connectionString))
{
conn.Open();
var row = conn.Query<Foo>("select @a as X", new { a = 123 }).Single();
Console.WriteLine(row.X);
var methods = typeof(Dapper.SqlMapper).GetMethods().Where(x => x.Name == "QueryAsync").ToList();
#if ASYNC
row = conn.QueryAsync<Foo>("select @a as X", new { a = 123 }).Result.Single();
#endif
Console.WriteLine(row.X);
}
}
class Foo
{
public int X { get; set; }
}
}
}
......@@ -6,26 +6,32 @@
"commands": {
"Dapper.DNX.Tests": "Dapper.DNX.Tests"
},
"compile": [ "../Tests/Tests.cs", "../Tests/Program.cs", "../Tests/Assert.cs" ],
"compilationOptions": { "define": [ "NOEXTERNALS" ] },
"frameworks": {
"net45": {
"compilationOptions": { "define": [ "ASYNC" ], "warningsAsErrors": true },
"dependencies": {
"System.Threading.Thread": "4.0.0-beta-22816"
},
"frameworkAssemblies": {
"System.Data": "4.0.0.0"
"System.Data": "4.0.0.0",
"System.Xml": "4.0.0.0"
}
},
"net40": {
"dependencies": {
},
"frameworkAssemblies": {
"System.Data": "4.0.0.0"
"System.Data": "4.0.0.0",
"System.Xml": "4.0.0.0"
}
},
"dnx451": {
"compilationOptions": { "define": [ "ASYNC" ], "warningsAsErrors": true },
"frameworkAssemblies": {
"System.Data": "4.0.0.0"
"System.Data": "4.0.0.0",
"System.Xml": "4.0.0.0"
}
},
......@@ -33,7 +39,14 @@
"compilationOptions": { "define": [ ], "warningsAsErrors": true },
"dependencies": {
"System.Console": "4.0.0-beta-*",
"System.Reflection": "4.0.10-beta-*"
"System.Reflection": "4.0.10-beta-*",
"System.Linq": "4.0.0-beta-*",
"System.Data.Common": "4.0.0-beta-*",
"System.Data.SqlClient": "4.0.0-beta-*",
"System.Threading": "4.0.10-beta-*",
"System.Threading.Thread": "4.0.0-beta-*",
"System.Reflection.TypeExtensions": "4.0.0-beta-*"
//"System.Xml": "4.0.10-beta-*"
}
}
}
......
......@@ -16,6 +16,20 @@
"runtime": [
"lib/net45/System.Runtime.dll"
]
},
"System.Threading.Thread/4.0.0-beta-22816": {
"dependencies": {
"System.Runtime": "4.0.20-beta-22816"
},
"frameworkAssemblies": [
"mscorlib"
],
"compile": [
"lib/net45/System.Threading.Thread.dll"
],
"runtime": [
"lib/net45/System.Threading.Thread.dll"
]
}
},
".NETFramework,Version=v4.0": {},
......@@ -325,6 +339,17 @@
"lib/aspnetcore50/System.Threading.Tasks.dll"
]
},
"System.Threading.Thread/4.0.0-beta-22816": {
"dependencies": {
"System.Runtime": "4.0.20-beta-22816"
},
"compile": [
"lib/contract/System.Threading.Thread.dll"
],
"runtime": [
"lib/aspnetcore50/System.Threading.Thread.dll"
]
},
"System.Xml.ReaderWriter/4.0.10-beta-22816": {
"dependencies": {
"System.IO": "4.0.10-beta-22816",
......@@ -669,6 +694,19 @@
"lib/portable-wpa81+wp80+win80+net45+aspnetcore50/System.Threading.Tasks.dll"
]
},
"System.Threading.Thread/4.0.0-beta-22816": {
"sha512": "hq1pNoES0jEKslftDhBeJnRUBSjEepiya+39oH/7yCvOp4xMnXHlWe9G7ZS/dg2n4k+3VY21AUifisybcFjcCQ==",
"files": [
"License.rtf",
"System.Threading.Thread.4.0.0-beta-22816.nupkg",
"System.Threading.Thread.4.0.0-beta-22816.nupkg.sha512",
"System.Threading.Thread.nuspec",
"lib/aspnetcore50/System.Threading.Thread.dll",
"lib/contract/System.Threading.Thread.dll",
"lib/net45/System.Threading.Thread.dll",
"lib/portable-wpa81+wp80+win80+net45+aspnetcore50/System.Threading.Thread.dll"
]
},
"System.Xml.ReaderWriter/4.0.10-beta-22816": {
"sha512": "G0aLPtC/phTfiJPwe0VA3tB3x8YFQ1dHFuE1xaHNr9eQm/AfBp4Pk+fn3s7ABJDus/T89EtIHQ9C+O6VmqXIQQ==",
"files": [
......@@ -688,17 +726,27 @@
"Dapper >= 1.41-*"
],
".NETFramework,Version=v4.5": [
"framework/System.Data >= 4.0.0.0"
"System.Threading.Thread >= 4.0.0-beta-22816",
"framework/System.Data >= 4.0.0.0",
"framework/System.Xml >= 4.0.0.0"
],
".NETFramework,Version=v4.0": [
"framework/System.Data >= 4.0.0.0"
"framework/System.Data >= 4.0.0.0",
"framework/System.Xml >= 4.0.0.0"
],
"DNX,Version=v4.5.1": [
"framework/System.Data >= 4.0.0.0"
"framework/System.Data >= 4.0.0.0",
"framework/System.Xml >= 4.0.0.0"
],
"DNXCore,Version=v5.0": [
"System.Console >= 4.0.0-beta-*",
"System.Reflection >= 4.0.10-beta-*"
"System.Reflection >= 4.0.10-beta-*",
"System.Linq >= 4.0.0-beta-*",
"System.Data.Common >= 4.0.0-beta-*",
"System.Data.SqlClient >= 4.0.0-beta-*",
"System.Threading >= 4.0.10-beta-*",
"System.Threading.Thread >= 4.0.0-beta-*",
"System.Reflection.TypeExtensions >= 4.0.0-beta-*"
]
}
}
\ No newline at end of file

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.22728.1
VisualStudioVersion = 14.0.22823.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Dapper", "Dapper\Dapper.xproj", "{088D8CC4-E71E-44B6-9B87-4060B043983D}"
EndProject
......@@ -9,8 +9,11 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Dapper.DNX.Tests", "Dapper.
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{03340C6E-4176-4C42-9C76-D5DFC79D1A22}"
ProjectSection(SolutionItems) = preProject
Tests\Assert.cs = Tests\Assert.cs
Tests\Program.cs = Tests\Program.cs
Dapper NET40\SqlMapper.cs = Dapper NET40\SqlMapper.cs
Dapper NET45\SqlMapperAsync.cs = Dapper NET45\SqlMapperAsync.cs
Tests\Tests.cs = Tests\Tests.cs
EndProjectSection
EndProject
Global
......
{
"authors": [ "Sam Saffron", "Marc Gravell" ],
"owners": [ "Sam Saffron", "Marc Gravell" ],
"projectUrl": "https://github.com/StackExchange/dapper-dot-net",
"licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0",
"summary": "A high performance Micro-ORM",
"description": "A high performance Micro-ORM supporting Sql Server, MySQL, Sqlite, SqlCE, Firebird etc..",
"version": "1.41-beta",
"version": "1.41-beta2",
"compile": [ "../Dapper NET40/*.cs", "../Dapper NET45/*.cs" ],
"title": "Dapper dot net",
"tags": [ "orm", "sql", "micro-orm" ],
"frameworks": {
"net45": {
"compilationOptions": { "define": [ "ASYNC" ], "warningsAsErrors": true },
......@@ -21,6 +27,14 @@
"System.Data": "4.0.0.0"
}
},
//"net35": {
// "compilationOptions": { "warningsAsErrors": true, "languageVersion": "csharp3", "define": ["CSHARP30"] },
// "dependencies": {
// },
// "frameworkAssemblies": {
// "System.Data": "4.0.0.0"
// }
//},
"dnx451": {
"compilationOptions": { "define": [ "ASYNC" ], "warningsAsErrors": true },
"dependencies": {
......
......@@ -21,7 +21,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;NET35</DefineConstants>
<DefineConstants>TRACE;DEBUG;NET35 EXTERNALS</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
......@@ -30,9 +30,10 @@
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;NET35</DefineConstants>
<DefineConstants>TRACE;NET35 EXTERNALS</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
......
......@@ -19,7 +19,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DefineConstants>TRACE;DEBUG;EXTERNALS</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
......@@ -28,7 +28,7 @@
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<DefineConstants>TRACE;EXTERNALS</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
......
......@@ -3,6 +3,10 @@
using System.Linq;
using System.Text;
#if DNXCORE50
using ApplicationException = global::System.InvalidOperationException;
#endif
namespace SqlMapper
{
static class Assert
......
......@@ -22,7 +22,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DefineConstants>TRACE;DEBUG;EXTERNALS PERF</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
......@@ -32,10 +32,11 @@
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<DefineConstants>TRACE;EXTERNALS PERF</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="BLToolkit.4">
......
......@@ -6,11 +6,15 @@
namespace SqlMapper
{
#if EXTERNALS
[ServiceStack.DataAnnotations.Alias("Posts")]
[Soma.Core.Table(Name = "Posts")]
#endif
public class Post
{
#if EXTERNALS
[Soma.Core.Id(Soma.Core.IdKind.Identity)]
#endif
public int Id { get; set; }
public string Text { get; set; }
public DateTime CreationDate { get; set; }
......@@ -42,10 +46,14 @@ public static SqlConnection GetOpenConnection()
static void RunPerformanceTests()
{
#if PERF
var test = new PerformanceTests();
const int iterations = 500;
Console.WriteLine("Running {0} iterations that load up a post entity", iterations);
test.Run(iterations);
#else
Console.WriteLine("Performance tests have not been built; add the PERF symbol");
#endif
}
static void Main()
......@@ -53,13 +61,18 @@ static void Main()
#if DEBUG
RunTests();
#else
#else
EnsureDBSetup();
RunPerformanceTests();
#endif
Console.WriteLine("(end of tests; press any key)");
#if DNXCORE50
Console.WriteLine("(end of tests; press return)");
Console.ReadLine();
#else
Console.WriteLine("(end of tests; press any key)");
Console.ReadKey();
#endif
}
private static void EnsureDBSetup()
......@@ -110,27 +123,46 @@ insert Posts ([Text],CreationDate, LastChangeDate) values (replicate('x', 2000),
cmd.ExecuteNonQuery();
}
}
private static bool HasAttribute<T>(MemberInfo member) where T : Attribute
{
#if DNXCORE50
return member.CustomAttributes.Any(x => x.AttributeType == typeof(T));
#else
return Attribute.IsDefined(member, typeof(T), true);
#endif
}
private static void RunTests()
{
var tester = new Tests();
int fail = 0;
int fail = 0, skip = 0, pass = 0;
MethodInfo[] methods = typeof(Tests).GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
var activeTests = methods.Where(m => Attribute.IsDefined(m, typeof(ActiveTestAttribute))).ToArray();
var activeTests = methods.Where(m => HasAttribute<ActiveTestAttribute>(m)).ToArray();
if (activeTests.Length != 0) methods = activeTests;
List<string> failNames = new List<string>();
foreach (var method in methods)
{
if (HasAttribute<SkipTestAttribute>(method))
{
Console.Write("Skipping " + method.Name);
skip++;
continue;
}
Console.Write("Running " + method.Name);
try
{
method.Invoke(tester, null);
Console.WriteLine(" - OK!");
pass++;
} catch(TargetInvocationException tie)
{
fail++;
Console.WriteLine(" - " + tie.InnerException.Message);
failNames.Add(method.Name);
if(tie.InnerException is TypeInitializationException)
{
Console.WriteLine("> " + tie.InnerException.InnerException.Message);
}
}catch (Exception ex)
{
......@@ -139,13 +171,15 @@ private static void RunTests()
}
}
Console.WriteLine();
Console.WriteLine("Passed: {0}, Failed: {1}, Skipped: {2}", pass, fail, skip);
if(fail == 0)
{
Console.WriteLine("(all tests successful)");
}
else
{
Console.WriteLine("#### FAILED: {0}", fail);
Console.WriteLine("Failures:");
foreach(var failName in failNames)
{
Console.WriteLine(failName);
......@@ -156,5 +190,7 @@ private static void RunTests()
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public sealed class ActiveTestAttribute : Attribute {}
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public sealed class SkipTestAttribute : Attribute { }
}
//#define POSTGRESQL // uncomment to run postgres tests
#if DNXCORE50
using IDbCommand = global::System.Data.Common.DbCommand;
using IDbDataParameter = global::System.Data.Common.DbParameter;
using IDbConnection = global::System.Data.Common.DbConnection;
using IDbTransaction = global::System.Data.Common.DbTransaction;
using IDataReader = global::System.Data.Common.DbDataReader;
#endif
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using Dapper;
using System.Data.SqlServerCe;
using System.IO;
using System.Data;
using System.Collections;
......@@ -15,14 +23,46 @@
using System.Data.Common;
using System.Globalization;
using System.Threading;
using System.Data.Entity.Spatial;
using Microsoft.SqlServer.Types;
using System.Data.SqlTypes;
using FirebirdSql.Data.FirebirdClient;
using System.Diagnostics;
#if EXTERNALS
using FirebirdSql.Data.FirebirdClient;
using System.Data.Entity.Spatial;
using Microsoft.SqlServer.Types;
using System.Data.SqlServerCe;
#if POSTGRESQL
using Npgsql;
#endif
#endif
#if DNXCORE50
namespace System.ComponentModel {
public sealed class DescriptionAttribute : Attribute {
public DescriptionAttribute(string description)
{
Description = description;
}
public string Description {get;private set;}
}
}
namespace System
{
public enum GenericUriParserOptions
{
Default
}
public class GenericUriParser
{
private GenericUriParserOptions options;
public GenericUriParser(GenericUriParserOptions options)
{
this.options = options;
}
}
}
#endif
namespace SqlMapper
{
......@@ -222,7 +262,7 @@ public void TestNoDefaultConstructorWithEnum()
nodef.NE1.IsEqualTo(ShortEnum.Five);
nodef.NE2.IsEqualTo(null);
}
#if EXTERNALS
class NoDefaultConstructorWithBinary
{
public System.Data.Linq.Binary Value { get; set; }
......@@ -232,7 +272,6 @@ public NoDefaultConstructorWithBinary(System.Data.Linq.Binary val)
Value = val;
}
}
public void TestNoDefaultConstructorBinary()
{
byte[] orig = new byte[20];
......@@ -241,7 +280,7 @@ public void TestNoDefaultConstructorBinary()
var output = connection.Query<NoDefaultConstructorWithBinary>("select @input as val", new { input }).First().Value;
output.ToArray().IsSequenceEqualTo(orig);
}
#endif
// http://stackoverflow.com/q/8593871
public void TestAbstractInheritance()
{
......@@ -515,7 +554,7 @@ public void TestExtraFields()
dog.First().Id
.IsEqualTo(guid);
}
#if EXTERNALS
// see http://stackoverflow.com/q/18847510/23354
public void TestOleDbParameters()
{
......@@ -537,7 +576,7 @@ System.Data.OleDb.OleDbConnection ConnectViaOledb()
conn.Open();
return conn;
}
#endif
public void TestStrongType()
{
var guid = Guid.NewGuid();
......@@ -1109,7 +1148,7 @@ public void TestFieldsAndPrivates()
}
#if EXTERNALS
public void ExecuteReader()
{
var dt = new DataTable();
......@@ -1121,7 +1160,7 @@ public void ExecuteReader()
((int)dt.Rows[0][0]).IsEqualTo(3);
((int)dt.Rows[0][1]).IsEqualTo(4);
}
#endif
private class TestFieldCaseAndPrivatesEntity
{
public int a { get; set; }
......@@ -1235,7 +1274,7 @@ public class AuthorCE
public int ID { get; set; }
public string Name { get; set; }
}
#if EXTERNALS
public void MultiRSSqlCE()
{
if (File.Exists("Test.sdf"))
......@@ -1264,7 +1303,7 @@ public void MultiRSSqlCE()
cnn.Close();
}
}
#endif
enum TestEnum : byte
{
Bla = 1
......@@ -1486,14 +1525,14 @@ public void TestDbString()
{
var obj = connection.Query("select datalength(@a) as a, datalength(@b) as b, datalength(@c) as c, datalength(@d) as d, datalength(@e) as e, datalength(@f) as f",
new
{
a = new DbString { Value = "abcde", IsFixedLength = true, Length = 10, IsAnsi = true },
b = new DbString { Value = "abcde", IsFixedLength = true, Length = 10, IsAnsi = false },
c = new DbString { Value = "abcde", IsFixedLength = false, Length = 10, IsAnsi = true },
d = new DbString { Value = "abcde", IsFixedLength = false, Length = 10, IsAnsi = false },
e = new DbString { Value = "abcde", IsAnsi = true },
f = new DbString { Value = "abcde", IsAnsi = false },
}).First();
{
a = new DbString { Value = "abcde", IsFixedLength = true, Length = 10, IsAnsi = true },
b = new DbString { Value = "abcde", IsFixedLength = true, Length = 10, IsAnsi = false },
c = new DbString { Value = "abcde", IsFixedLength = false, Length = 10, IsAnsi = true },
d = new DbString { Value = "abcde", IsFixedLength = false, Length = 10, IsAnsi = false },
e = new DbString { Value = "abcde", IsAnsi = true },
f = new DbString { Value = "abcde", IsAnsi = false },
}).First();
((int)obj.a).IsEqualTo(10);
((int)obj.b).IsEqualTo(20);
((int)obj.c).IsEqualTo(5);
......@@ -1656,7 +1695,7 @@ public void AddParameters(IDbCommand command, Dapper.SqlMapper.Identity identity
}
}
#if EXTERNALS
// SQL Server specific test to demonstrate TVP
public void TestTVP()
{
......@@ -1755,7 +1794,7 @@ public void TestTVPWithAdditionalParams()
}
}
}
#endif
class IntCustomParam : Dapper.SqlMapper.ICustomQueryParameter
{
IEnumerable<int> numbers;
......@@ -1789,7 +1828,7 @@ public void AddParameter(IDbCommand command, string name)
p.Value = number_list;
}
}
#if EXTERNALS
public void TestTVPWithAnonymousObject()
{
try
......@@ -1816,6 +1855,7 @@ public void TestTVPWithAnonymousObject()
}
}
}
#endif
class Parent
{
......@@ -1864,6 +1904,7 @@ class WithBizarreData
public GenericUriParser Foo { get; set; }
public int Bar { get; set; }
}
public void TestUnexpectedDataMessage()
{
string msg = null;
......@@ -1878,6 +1919,7 @@ public void TestUnexpectedDataMessage()
}
msg.IsEqualTo("The member Foo of type System.GenericUriParser cannot be used as a parameter value");
}
public void TestUnexpectedButFilteredDataMessage()
{
int i = connection.Query<int>("select @Bar", new WithBizarreData { Foo = new GenericUriParser(GenericUriParserOptions.Default), Bar = 23 }).Single();
......@@ -2094,6 +2136,8 @@ public void TestMultiMapperIsNotConfusedWithUnorderedCols()
result.Item2.BarId.IsEqualTo(3);
result.Item2.Name.IsEqualTo("a");
}
#if EXTERNALS
public void TestLinqBinaryToClass()
{
byte[] orig = new byte[20];
......@@ -2120,7 +2164,7 @@ class WithBinary
{
public System.Data.Linq.Binary Value { get; set; }
}
#endif
class WithPrivateConstructor
{
......@@ -2489,7 +2533,7 @@ public void TestCustomTypeMap()
// custom mapping
var map = new CustomPropertyTypeMap(typeof(TypeWithMapping),
(type, columnName) => type.GetProperties().Where(prop => prop.GetCustomAttributes(false).OfType<DescriptionAttribute>().Any(attr => attr.Description == columnName)).FirstOrDefault());
(type, columnName) => type.GetProperties().Where(prop => GetDescriptionFromAttribute(prop) == columnName).FirstOrDefault());
Dapper.SqlMapper.SetTypeMap(typeof(TypeWithMapping), map);
item = connection.Query<TypeWithMapping>("Select 'AVal' as A, 'BVal' as B").Single();
......@@ -2502,7 +2546,17 @@ public void TestCustomTypeMap()
item.A.IsEqualTo("AVal");
item.B.IsEqualTo("BVal");
}
static string GetDescriptionFromAttribute(MemberInfo member)
{
if (member == null) return null;
#if DNXCORE50
var data = member.CustomAttributes.FirstOrDefault(x => x.AttributeType == typeof(DescriptionAttribute));
return data == null ? null : (string)data.ConstructorArguments.Single().Value;
#else
var attrib = (DescriptionAttribute)Attribute.GetCustomAttribute(member, typeof(DescriptionAttribute), false);
return attrib == null ? null : attrib.Description;
#endif
}
public class TypeWithMapping
{
[Description("B")]
......@@ -2872,7 +2926,70 @@ public void TestChangingDefaultStringTypeMappingToAnsiString()
Dapper.SqlMapper.PurgeQueryCache();
Dapper.SqlMapper.AddTypeMap(typeof(string), DbType.String); // Restore Default to Unicode String
}
#if DNXCORE50
class TransactedConnection : IDbConnection
{
IDbConnection _conn;
IDbTransaction _tran;
public TransactedConnection(IDbConnection conn, IDbTransaction tran)
{
_conn = conn;
_tran = tran;
}
public override string ConnectionString { get { return _conn.ConnectionString; } set { _conn.ConnectionString = value; } }
public override int ConnectionTimeout { get { return _conn.ConnectionTimeout; } }
public override string Database { get { return _conn.Database; } }
public override ConnectionState State { get { return _conn.State; } }
protected override IDbTransaction BeginDbTransaction(IsolationLevel isolationLevel)
{
return _tran;
}
public override void ChangeDatabase(string databaseName)
{
_conn.ChangeDatabase(databaseName);
}
public override string DataSource
{
get
{
return _conn.DataSource;
}
}
public override string ServerVersion
{
get
{
return _conn.ServerVersion;
}
}
public override void Close()
{
_conn.Close();
}
protected override IDbCommand CreateDbCommand()
{
// The command inherits the "current" transaction.
var command = _conn.CreateCommand();
command.Transaction = _tran;
return command;
}
protected override void Dispose(bool disposing)
{
if(disposing) _conn.Dispose();
base.Dispose(disposing);
}
public override void Open()
{
_conn.Open();
}
}
#else
class TransactedConnection : IDbConnection
{
IDbConnection _conn;
......@@ -2927,7 +3044,7 @@ public void Open()
_conn.Open();
}
}
#endif
public void TestDapperTableMetadataRetrieval()
{
// Test for a bug found in CS 51509960 where the following sequence would result in an InvalidOperationException being
......@@ -3004,20 +3121,29 @@ public void TestDoubleDecimalConversions_SO18228523_Nulls()
row.C.Equals(0.0M);
row.D.IsNull();
}
private static CultureInfo ActiveCulture
{
#if DNXCORE50
get { return CultureInfo.CurrentCulture; }
set { CultureInfo.CurrentCulture = value; }
#else
get { return Thread.CurrentThread.CurrentCulture; }
set { Thread.CurrentThread.CurrentCulture = value; }
#endif
}
public void TestParameterInclusionNotSensitiveToCurrentCulture()
{
// note this might fail if your database server is case-sensitive
CultureInfo current = Thread.CurrentThread.CurrentCulture;
CultureInfo current = ActiveCulture;
try
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("tr-TR");
ActiveCulture = new CultureInfo("tr-TR");
connection.Query<int>("select @pid", new { PId = 1 }).Single();
}
finally
{
Thread.CurrentThread.CurrentCulture = current;
ActiveCulture = current;
}
}
public void LiteralReplacement()
......@@ -3173,7 +3299,7 @@ class HasDoubleDecimal
public decimal C { get; set; }
public decimal? D { get; set; }
}
#if EXTERNALS
public void DataTableParameters()
{
try { connection.Execute("drop proc #DataTableParameters"); }
......@@ -3277,7 +3403,7 @@ public void SupportInit()
obj.Value.Equals("abc");
obj.Flags.Equals(31);
}
#endif
public void GuidIn_SO_24177902()
{
// invent and populate
......@@ -3304,7 +3430,7 @@ public void GuidIn_SO_24177902()
rows[1].i.Equals(3);
rows[1].g.Equals(c);
}
#if EXTERNALS
class HazGeo
{
public int Id { get; set; }
......@@ -3372,7 +3498,7 @@ public class HazSqlHierarchy
public int Id { get; set; }
public SqlHierarchyId Path { get; set; }
}
#endif
public void TypeBasedViaDynamic()
{
Type type = GetSomeType();
......@@ -3432,7 +3558,7 @@ public class SomeType
public int A { get; set; }
public string B { get; set; }
}
#if !DNXCORE50
class WithInit : ISupportInitialize
{
public string Value { get; set; }
......@@ -3448,7 +3574,7 @@ void ISupportInitialize.EndInit()
Flags += 30;
}
}
#endif
public void SO24607639_NullableBools()
{
var obj = connection.Query<HazBools>(
......@@ -3482,7 +3608,9 @@ public void SO24605346_ProcsAndStrings()
class PracticeRebateOrders
{
public string fTaxInvoiceNumber;
#if EXTERNALS
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
#endif
public string TaxInvoiceNumber { get { return fTaxInvoiceNumber; } set { fTaxInvoiceNumber = value; } }
}
......@@ -3498,7 +3626,7 @@ public override RatingValue Parse(object value)
throw new FormatException("Invalid conversion to RatingValue");
}
public override void SetValue(System.Data.IDbDataParameter parameter, RatingValue value)
public override void SetValue(IDbDataParameter parameter, RatingValue value)
{
// ... null, range checks etc ...
parameter.DbType = System.Data.DbType.Int32;
......@@ -3566,10 +3694,12 @@ public void Issue22_ExecuteScalar()
int? k = connection.ExecuteScalar<int?>("select @i", new { i = default(int?) });
k.IsNull();
#if EXTERNALS
Dapper.EntityFramework.Handlers.Register();
var geo = DbGeography.LineFromText("LINESTRING(-122.360 47.656, -122.343 47.656 )", 4326);
var geo2 = connection.ExecuteScalar<DbGeography>("select @geo", new { geo });
geo2.IsNotNull();
#endif
}
public void Issue142_FailsNamedStatus()
......@@ -3955,7 +4085,7 @@ public void Issue178_SqlServer()
Assert.IsFalse(reader2.NextResult());
}
}
#if EXTERNALS
public void Issue178_Firebird() // we expect this to fail due to a bug in Firebird; a PR to fix it has been submitted
{
var cs = @"initial catalog=localhost:database;user id=SYSDBA;password=masterkey";
......@@ -4000,6 +4130,7 @@ public void PseudoPositionalParameters_Simple()
value.IsEqualTo(9);
}
}
public void PseudoPositionalParameters_Dynamic()
{
using (var connection = ConnectViaOledb())
......@@ -4013,6 +4144,7 @@ public void PseudoPositionalParameters_Dynamic()
value.IsEqualTo(9);
}
}
public void PseudoPositionalParameters_ReusedParameter()
{
using (var connection = ConnectViaOledb())
......@@ -4058,7 +4190,7 @@ public void PseudoPositionalParameters_ExecMulti()
sum.IsEqualTo(10);
}
}
#endif
public void QueryBasicWithoutQuery()
{
int? i = connection.Query<int?>("print 'not a query'").FirstOrDefault();
......@@ -4210,7 +4342,7 @@ public void BasicDecimals()
var c = connection.Query<decimal>("select @c", new { c = 11.884M }).Single();
c.IsEqualTo(11.884M);
}
[SkipTest]
public void Issue263_Timeout()
{
var watch = Stopwatch.StartNew();
......@@ -4220,7 +4352,7 @@ public void Issue263_Timeout()
var minutes = watch.ElapsedMilliseconds / 1000 / 60;
Assert.IsTrue(minutes >= 0.95 && minutes <= 1.05);
}
#if EXTERNALS
public void SO29596645_TvpProperty()
{
try { connection.Execute("CREATE TYPE SO29596645_ReminderRuleType AS TABLE (id int NOT NULL)"); }
......@@ -4234,7 +4366,7 @@ public void SO29596645_TvpProperty()
val.IsEqualTo(20);
}
#endif
public void Issue268_ReturnQueryMultiple()
{
connection.Execute(@"create proc #TestProc268 (@a int, @b int, @c int)as
......@@ -4257,7 +4389,7 @@ select @b
var retVal = p.Get<int>("RetVal");
retVal.IsEqualTo(3);
}
#if EXTERNALS
class SO29596645_RuleTableValuedParameters : Dapper.SqlMapper.IDynamicParameters {
private string parameterName;
......@@ -4289,7 +4421,7 @@ public SO29596645_OrganisationDTO()
Rules = new SO29596645_RuleTableValuedParameters("@Rules");
}
}
#endif
#if POSTGRESQL
class Cat
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册