Commit dbd5455f authored by Marc Gravell's avatar Marc Gravell

Async cleanup; implement missing async methods based on multiple pull...

Async cleanup; implement missing async methods based on multiple pull requests, but introducing CommandDefinition to preserve binary compatibility while allowing new options
parent 885a8d46
...@@ -8,3 +8,4 @@ NuGet.exe ...@@ -8,3 +8,4 @@ NuGet.exe
*.user *.user
*.nupkg *.nupkg
.docstats .docstats
*.ide/
\ No newline at end of file
This diff is collapsed.
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath> <OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>TRACE;DEBUG;ASYNC</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath> <OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE;ASYNC</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\Dapper.xml</DocumentationFile> <DocumentationFile>bin\Release\Dapper.xml</DocumentationFile>
......
This diff is collapsed.
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
<AssemblyName>DapperTests NET45</AssemblyName> <AssemblyName>DapperTests NET45</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
......
using System; using System;
using System.Data.SqlClient; using System.Data.SqlClient;
using System.Linq;
using System.Reflection; using System.Reflection;
namespace DapperTests_NET45 namespace DapperTests_NET45
...@@ -21,14 +22,29 @@ public static SqlConnection GetOpenConnection() ...@@ -21,14 +22,29 @@ public static SqlConnection GetOpenConnection()
connection.Open(); connection.Open();
return connection; return connection;
} }
public static SqlConnection GetClosedConnection()
{
return new SqlConnection(connectionString);
}
private static void RunTests() private static void RunTests()
{ {
var tester = new Tests(); var tester = new Tests();
foreach (var method in typeof(Tests).GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)) foreach (var method in typeof(Tests).GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
{ {
Console.Write("Running " + method.Name); Console.Write("Running " + method.Name);
method.Invoke(tester, null); try
Console.WriteLine(" - OK!"); {
method.Invoke(tester, null);
Console.WriteLine(" - OK!");
} catch(TargetInvocationException ex)
{
var inner = ex.InnerException;
if(inner is AggregateException && ((AggregateException)inner).InnerExceptions.Count == 1)
{
inner = ((AggregateException)inner).InnerExceptions.Single();
}
Console.WriteLine(" - ERR: " + inner.Message);
}
} }
} }
} }
......
...@@ -16,6 +16,16 @@ public void TestBasicStringUsageAsync() ...@@ -16,6 +16,16 @@ public void TestBasicStringUsageAsync()
} }
} }
public void TestBasicStringUsageClosedAsync()
{
using (var connection = Program.GetClosedConnection())
{
var query = connection.QueryAsync<string>("select 'abc' as [Value] union all select @txt", new { txt = "def" });
var arr = query.Result.ToArray();
arr.IsSequenceEqualTo(new[] { "abc", "def" });
}
}
public void TestClassWithStringUsageAsync() public void TestClassWithStringUsageAsync()
{ {
using (var connection = Program.GetOpenConnection()) using (var connection = Program.GetOpenConnection())
...@@ -26,6 +36,25 @@ public void TestClassWithStringUsageAsync() ...@@ -26,6 +36,25 @@ public void TestClassWithStringUsageAsync()
} }
} }
public void TestExecuteAsync()
{
using (var connection = Program.GetOpenConnection())
{
var query = connection.ExecuteAsync("declare @foo table(id int not null); insert @foo values(@id);", new { id = 1 });
var val = query.Result;
val.Equals(1);
}
}
public void TestExecuteClosedConnAsync()
{
using (var connection = Program.GetClosedConnection())
{
var query = connection.ExecuteAsync("declare @foo table(id int not null); insert @foo values(@id);", new { id = 1 });
var val = query.Result;
val.Equals(1);
}
}
public void TestMultiMapWithSplitAsync() public void TestMultiMapWithSplitAsync()
{ {
var sql = @"select 1 as id, 'abc' as name, 2 as id, 'def' as name"; var sql = @"select 1 as id, 'abc' as name, 2 as id, 'def' as name";
...@@ -46,6 +75,49 @@ public void TestMultiMapWithSplitAsync() ...@@ -46,6 +75,49 @@ public void TestMultiMapWithSplitAsync()
} }
} }
public void TestMultiMapWithSplitClosedConnAsync()
{
var sql = @"select 1 as id, 'abc' as name, 2 as id, 'def' as name";
using (var connection = Program.GetClosedConnection())
{
var productQuery = connection.QueryAsync<Product, Category, Product>(sql, (prod, cat) =>
{
prod.Category = cat;
return prod;
});
var product = productQuery.Result.First();
// assertions
product.Id.IsEqualTo(1);
product.Name.IsEqualTo("abc");
product.Category.Id.IsEqualTo(2);
product.Category.Name.IsEqualTo("def");
}
}
public void TestMultiAsync()
{
using(var conn = Program.GetOpenConnection())
{
using(Dapper.SqlMapper.GridReader multi = conn.QueryMultipleAsync("select 1; select 2").Result)
{
multi.Read<int>().Single().IsEqualTo(1);
multi.Read<int>().Single().IsEqualTo(2);
}
}
}
public void TestMultiClosedConnAsync()
{
using (var conn = Program.GetClosedConnection())
{
using (Dapper.SqlMapper.GridReader multi = conn.QueryMultipleAsync("select 1; select 2").Result)
{
multi.Read<int>().Single().IsEqualTo(1);
multi.Read<int>().Single().IsEqualTo(2);
}
}
}
class Product class Product
{ {
public int Id { get; set; } public int Id { get; set; }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
<TargetFrameworkProfile> <TargetFrameworkProfile>
</TargetFrameworkProfile> </TargetFrameworkProfile>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
using System.Data.SqlClient; using System.Data.SqlClient;
using System.Reflection; using System.Reflection;
using System.Linq; using System.Linq;
using System.Collections.Generic;
namespace SqlMapper namespace SqlMapper
{ {
[ServiceStack.DataAnnotations.Alias("Posts")] [ServiceStack.DataAnnotations.Alias("Posts")]
...@@ -116,6 +118,7 @@ private static void RunTests() ...@@ -116,6 +118,7 @@ private static void RunTests()
MethodInfo[] methods = typeof(Tests).GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); 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 => Attribute.IsDefined(m, typeof(ActiveTestAttribute))).ToArray();
if (activeTests.Length != 0) methods = activeTests; if (activeTests.Length != 0) methods = activeTests;
List<string> failNames = new List<string>();
foreach (var method in methods) foreach (var method in methods)
{ {
Console.Write("Running " + method.Name); Console.Write("Running " + method.Name);
...@@ -127,6 +130,7 @@ private static void RunTests() ...@@ -127,6 +130,7 @@ private static void RunTests()
{ {
fail++; fail++;
Console.WriteLine(" - " + tie.InnerException.Message); Console.WriteLine(" - " + tie.InnerException.Message);
failNames.Add(method.Name);
}catch (Exception ex) }catch (Exception ex)
{ {
...@@ -142,6 +146,10 @@ private static void RunTests() ...@@ -142,6 +146,10 @@ private static void RunTests()
else else
{ {
Console.WriteLine("#### FAILED: {0}", fail); Console.WriteLine("#### FAILED: {0}", fail);
foreach(var failName in failNames)
{
Console.WriteLine(failName);
}
} }
} }
} }
......
...@@ -659,6 +659,7 @@ public void TestExpandWithNullableFields() ...@@ -659,6 +659,7 @@ public void TestExpandWithNullableFields()
((int?)row.B) ((int?)row.B)
.IsEqualTo(2); .IsEqualTo(2);
} }
public void TestEnumeration() public void TestEnumeration()
{ {
var en = connection.Query<int>("select 1 as one union all select 2 as one", buffered: false); var en = connection.Query<int>("select 1 as one union all select 2 as one", buffered: false);
...@@ -678,7 +679,7 @@ public void TestEnumeration() ...@@ -678,7 +679,7 @@ public void TestEnumeration()
while (i.MoveNext()) while (i.MoveNext())
{ } { }
// should not exception, since enumertated // should not exception, since enumerated
en = connection.Query<int>("select 1 as one", buffered: false); en = connection.Query<int>("select 1 as one", buffered: false);
gotException.IsTrue(); gotException.IsTrue();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment