提交 dbd5455f 编写于 作者: M 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
上级 885a8d46
......@@ -8,3 +8,4 @@ NuGet.exe
*.user
*.nupkg
.docstats
*.ide/
\ No newline at end of file
此差异已折叠。
......@@ -17,7 +17,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DefineConstants>TRACE;DEBUG;ASYNC</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
......@@ -28,7 +28,7 @@
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<DefineConstants>TRACE;ASYNC</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\Dapper.xml</DocumentationFile>
......
此差异已折叠。
......@@ -11,6 +11,7 @@
<AssemblyName>DapperTests NET45</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
......
using System;
using System.Data.SqlClient;
using System.Linq;
using System.Reflection;
namespace DapperTests_NET45
......@@ -21,14 +22,29 @@ public static SqlConnection GetOpenConnection()
connection.Open();
return connection;
}
public static SqlConnection GetClosedConnection()
{
return new SqlConnection(connectionString);
}
private static void RunTests()
{
var tester = new Tests();
foreach (var method in typeof(Tests).GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
{
Console.Write("Running " + method.Name);
method.Invoke(tester, null);
Console.WriteLine(" - OK!");
try
{
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()
}
}
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()
{
using (var connection = Program.GetOpenConnection())
......@@ -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()
{
var sql = @"select 1 as id, 'abc' as name, 2 as id, 'def' as name";
......@@ -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
{
public int Id { get; set; }
......
......@@ -14,6 +14,7 @@
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
......
......@@ -2,6 +2,8 @@
using System.Data.SqlClient;
using System.Reflection;
using System.Linq;
using System.Collections.Generic;
namespace SqlMapper
{
[ServiceStack.DataAnnotations.Alias("Posts")]
......@@ -116,6 +118,7 @@ private static void RunTests()
MethodInfo[] methods = typeof(Tests).GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
var activeTests = methods.Where(m => Attribute.IsDefined(m, typeof(ActiveTestAttribute))).ToArray();
if (activeTests.Length != 0) methods = activeTests;
List<string> failNames = new List<string>();
foreach (var method in methods)
{
Console.Write("Running " + method.Name);
......@@ -127,6 +130,7 @@ private static void RunTests()
{
fail++;
Console.WriteLine(" - " + tie.InnerException.Message);
failNames.Add(method.Name);
}catch (Exception ex)
{
......@@ -142,6 +146,10 @@ private static void RunTests()
else
{
Console.WriteLine("#### FAILED: {0}", fail);
foreach(var failName in failNames)
{
Console.WriteLine(failName);
}
}
}
}
......
......@@ -659,6 +659,7 @@ public void TestExpandWithNullableFields()
((int?)row.B)
.IsEqualTo(2);
}
public void TestEnumeration()
{
var en = connection.Query<int>("select 1 as one union all select 2 as one", buffered: false);
......@@ -678,7 +679,7 @@ public void TestEnumeration()
while (i.MoveNext())
{ }
// should not exception, since enumertated
// should not exception, since enumerated
en = connection.Query<int>("select 1 as one", buffered: false);
gotException.IsTrue();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册