mirror of
https://github.com/DapperLib/Dapper.git
synced 2026-10-18 14:27:47 +08:00
aecffecae1
* attempt NRT makeover - annotate NRTs on GridReader API - add protected access to some of the GridReader internals - switch GridReader callbacks to be more type-independent docs lib updates; deal with yellow warnings and test failures (SQL server certs and cancellation surfacing differently) fix break simplify proposed GridReader changes to protected OnBeforeGrid and OnAfterGrid[Async] Builds: Bump library versions (#1935) Tests: Upgrade dependencies for Dependabot (#1936) I'll do a pass at all of these later, but getting CVE versions out of the pipe. Resolving 4 alerts here: https://github.com/DapperLib/Dapper/security/dependabot merge and lib updates allow Identity to be constructed on-the-fly inside GridReader fix build warnings include readme rev minor - enable [SkipLocalsInit] everywhere - use NET5_0_OR_GREATER for remoting check # Conflicts: # Dapper/CommandDefinition.cs # Dapper/DefaultTypeMap.cs # Dapper/SqlMapper.Async.cs # Dapper/SqlMapper.IDataReader.cs # Dapper/SqlMapper.Link.cs # Dapper/SqlMapper.cs # Directory.Build.props * shipped, not unshipped * fixup SqlBuilder; use is null / is not null * use central package management (#1949) * Nullable test tweaks * Nuget: let's just remove it! * 2 test fixes from review * fix FindExplicitConstructor * add GetPropertySetterOrThrow * fix NRT on FindConstructor * DapperRow: value is object? * use NotNullWhen * make constructor problem more obvious * test fixes --------- Co-authored-by: Nick Craver <nrcraver@gmail.com>
70 lines
2.7 KiB
C#
70 lines
2.7 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Data.Common;
|
|
using Xunit;
|
|
|
|
namespace Dapper.Tests
|
|
{
|
|
public static class Common
|
|
{
|
|
public static Type GetSomeType() => typeof(SomeType);
|
|
|
|
public static void DapperEnumValue(IDbConnection connection)
|
|
{
|
|
// test passing as AsEnum, reading as int
|
|
var v = (AnEnum)connection.QuerySingle<int>("select @v, @y, @z", new { v = AnEnum.B, y = (AnEnum?)AnEnum.B, z = (AnEnum?)null });
|
|
Assert.Equal(AnEnum.B, v);
|
|
|
|
var args = new DynamicParameters();
|
|
args.Add("v", AnEnum.B);
|
|
args.Add("y", AnEnum.B);
|
|
args.Add("z", null);
|
|
v = (AnEnum)connection.QuerySingle<int>("select @v, @y, @z", args);
|
|
Assert.Equal(AnEnum.B, v);
|
|
|
|
// test passing as int, reading as AnEnum
|
|
var k = (int)connection.QuerySingle<AnEnum>("select @v, @y, @z", new { v = (int)AnEnum.B, y = (int?)(int)AnEnum.B, z = (int?)null });
|
|
Assert.Equal((int)AnEnum.B, k);
|
|
|
|
args = new DynamicParameters();
|
|
args.Add("v", (int)AnEnum.B);
|
|
args.Add("y", (int)AnEnum.B);
|
|
args.Add("z", null);
|
|
k = (int)connection.QuerySingle<AnEnum>("select @v, @y, @z", args);
|
|
Assert.Equal((int)AnEnum.B, k);
|
|
}
|
|
|
|
public static void TestDateTime(DbConnection connection)
|
|
{
|
|
DateTime? now = DateTime.UtcNow;
|
|
try { connection.Execute("DROP TABLE Persons"); } catch { /* don't care */ }
|
|
connection.Execute("CREATE TABLE Persons (id int not null, dob datetime null)");
|
|
connection.Execute("INSERT Persons (id, dob) values (@id, @dob)",
|
|
new { id = 7, dob = (DateTime?)null });
|
|
connection.Execute("INSERT Persons (id, dob) values (@id, @dob)",
|
|
new { id = 42, dob = now });
|
|
|
|
var row = connection.QueryFirstOrDefault<NullableDatePerson>(
|
|
"SELECT id, dob, dob as dob2 FROM Persons WHERE id=@id", new { id = 7 });
|
|
Assert.NotNull(row);
|
|
Assert.Equal(7, row.Id);
|
|
Assert.Null(row.DoB);
|
|
Assert.Null(row.DoB2);
|
|
|
|
row = connection.QueryFirstOrDefault<NullableDatePerson>(
|
|
"SELECT id, dob FROM Persons WHERE id=@id", new { id = 42 });
|
|
Assert.NotNull(row);
|
|
Assert.Equal(42, row.Id);
|
|
row.DoB.Equals(now);
|
|
row.DoB2.Equals(now);
|
|
}
|
|
|
|
private class NullableDatePerson
|
|
{
|
|
public int Id { get; set; }
|
|
public DateTime? DoB { get; set; }
|
|
public DateTime? DoB2 { get; set; }
|
|
}
|
|
}
|
|
}
|