mirror of
https://github.com/DapperLib/Dapper.git
synced 2026-10-18 22:31:08 +08:00
fd10fe7ccb
This eliminates the dual solutions and brings Contrib into the project.json fold. - Tests are ported to xUnit though SQLite is disabled on DNX due to Issue #375 (Interop loads fail in the VS runner and params are busted regardless). - Projects are consolidated down to what's currently possible with project.json. - Contrib moved to: Dapper.Contrib and Dapper.Tests.Contrib (so tests appear at the end, no other reason vs. Dapper.Contrib.Tests) - EF moved to: Dapper.EntityFramework(.StrongName) - Rainbow moved to: Dapper.Rainbow - SqlBuilder moved to: Dapper.SqlBuilder - Packages are removed since it's not current-tooling friendly to keep them (nor was it using them). - xUnit implemented in Contrib via abstracts - this allow us to very quickly add any database provider to the rig in a very concise way. - Contrib unit tests fixed in various places - they were not parallel-runner friendly - Nuspecs removed, since they aren't used anymore (to eliminate confusion) - Removed speed tests for libraries that aren't on current versions of .Net (what would we be comparing?) - Perf tests moved to Dapper.Tests (consolidation from Dapper.DNX.Tests), but aren't activated yet (no define)
149 lines
4.7 KiB
C#
149 lines
4.7 KiB
C#
using Dapper;
|
|
using System;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using Xunit;
|
|
|
|
#if COREFX
|
|
using IDbCommand = System.Data.Common.DbCommand;
|
|
using IDbDataParameter = System.Data.Common.DbParameter;
|
|
using IDbConnection = System.Data.Common.DbConnection;
|
|
using IDbTransaction = System.Data.Common.DbTransaction;
|
|
using IDataReader = System.Data.Common.DbDataReader;
|
|
#endif
|
|
|
|
namespace Dapper.Tests
|
|
{
|
|
public partial class TestSuite
|
|
{
|
|
[Fact]
|
|
public void TestQueryMultipleBuffered()
|
|
{
|
|
using (var grid = connection.QueryMultiple("select 1; select 2; select @x; select 4", new { x = 3 }))
|
|
{
|
|
var a = grid.Read<int>();
|
|
var b = grid.Read<int>();
|
|
var c = grid.Read<int>();
|
|
var d = grid.Read<int>();
|
|
|
|
a.Single().Equals(1);
|
|
b.Single().Equals(2);
|
|
c.Single().Equals(3);
|
|
d.Single().Equals(4);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void TestQueryMultipleNonBufferedIncorrectOrder()
|
|
{
|
|
using (var grid = connection.QueryMultiple("select 1; select 2; select @x; select 4", new { x = 3 }))
|
|
{
|
|
var a = grid.Read<int>(false);
|
|
try
|
|
{
|
|
var b = grid.Read<int>(false);
|
|
throw new InvalidOperationException(); // should have thrown
|
|
}
|
|
catch (InvalidOperationException)
|
|
{
|
|
// that's expected
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void TestQueryMultipleNonBufferedCorrectOrder()
|
|
{
|
|
using (var grid = connection.QueryMultiple("select 1; select 2; select @x; select 4", new { x = 3 }))
|
|
{
|
|
var a = grid.Read<int>(false).Single();
|
|
var b = grid.Read<int>(false).Single();
|
|
var c = grid.Read<int>(false).Single();
|
|
var d = grid.Read<int>(false).Single();
|
|
|
|
a.Equals(1);
|
|
b.Equals(2);
|
|
c.Equals(3);
|
|
d.Equals(4);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void TestMultiReaderBasic()
|
|
{
|
|
var sql = @"select 1 as Id union all select 2 as Id select 'abc' as name select 1 as Id union all select 2 as Id";
|
|
int i, j;
|
|
string s;
|
|
using (var multi = connection.QueryMultiple(sql))
|
|
{
|
|
i = multi.Read<int>().First();
|
|
s = multi.Read<string>().Single();
|
|
j = multi.Read<int>().Sum();
|
|
}
|
|
Assert.IsEqualTo(i, 1);
|
|
Assert.IsEqualTo(s, "abc");
|
|
Assert.IsEqualTo(j, 3);
|
|
}
|
|
|
|
[Fact]
|
|
public void TestReadDynamicWithGridReader()
|
|
{
|
|
var createSql = @"
|
|
create table #Users (Id int, Name varchar(20))
|
|
create table #Posts (Id int, OwnerId int, Content varchar(20))
|
|
|
|
insert #Users values(99, 'Sam')
|
|
insert #Users values(2, 'I am')
|
|
|
|
insert #Posts values(1, 99, 'Sams Post1')
|
|
insert #Posts values(2, 99, 'Sams Post2')
|
|
insert #Posts values(3, null, 'no ones post')";
|
|
try
|
|
{
|
|
connection.Execute(createSql);
|
|
|
|
var sql = @"SELECT * FROM #Users ORDER BY Id
|
|
SELECT * FROM #Posts ORDER BY Id DESC";
|
|
|
|
var grid = connection.QueryMultiple(sql);
|
|
|
|
var users = grid.Read().ToList();
|
|
var posts = grid.Read().ToList();
|
|
|
|
users.Count.IsEqualTo(2);
|
|
posts.Count.IsEqualTo(3);
|
|
|
|
((int)users.First().Id).IsEqualTo(2);
|
|
((int)posts.First().Id).IsEqualTo(3);
|
|
}
|
|
finally
|
|
{
|
|
connection.Execute("drop table #Users drop table #Posts");
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void Issue268_ReturnQueryMultiple()
|
|
{
|
|
connection.Execute(@"create proc #TestProc268 (@a int, @b int, @c int)as
|
|
begin
|
|
select @a;
|
|
|
|
select @b
|
|
|
|
return @c;
|
|
end");
|
|
var p = new DynamicParameters(new { a = 1, b = 2, c = 3 });
|
|
p.Add("RetVal", dbType: DbType.Int32, direction: ParameterDirection.ReturnValue);
|
|
|
|
using (var reader = connection.QueryMultiple("#TestProc268", p, commandType: CommandType.StoredProcedure))
|
|
{
|
|
reader.Read();
|
|
}
|
|
var retVal = p.Get<int>("RetVal");
|
|
retVal.IsEqualTo(3);
|
|
}
|
|
}
|
|
}
|