Commit 4a9f0500 authored by Marc Gravell's avatar Marc Gravell

The "first column as null gives null object" is by-design;

tweak tests to represent this (and workaround)

Added [ActiveTest] to allow trivial debugging individual tests
parent d0331a03
......@@ -16,6 +16,7 @@
using System.Text;
using System.Threading;
using System.Text.RegularExpressions;
using System.Diagnostics;
namespace Dapper
{
......@@ -1622,8 +1623,8 @@ static List<FieldInfo> GetSettableFields(Type t)
#endif
)
{
var dm = new DynamicMethod(string.Format("Deserialize{0}", Guid.NewGuid()), typeof(object), new[] { typeof(IDataReader) }, true);
var il = dm.GetILGenerator();
il.DeclareLocal(typeof(int));
il.DeclareLocal(type);
......
using System;
using System.Data.SqlClient;
using System.Reflection;
using System.Linq;
namespace SqlMapper
{
[ServiceStack.DataAnnotations.Alias("Posts")]
......@@ -112,7 +112,10 @@ private static void RunTests()
{
var tester = new Tests();
int fail = 0;
foreach (var method in 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();
if (activeTests.Length != 0) methods = activeTests;
foreach (var method in methods)
{
Console.Write("Running " + method.Name);
try
......@@ -136,4 +139,8 @@ private static void RunTests()
}
}
}
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public sealed class ActiveTestAttribute : Attribute {}
}
......@@ -798,6 +798,19 @@ class Category
// assertions
product.Id.IsEqualTo(1);
product.Name.IsEqualTo("abc");
product.Category.IsNull();
}
public void TestMultiMapWithSplitWithNullValueAndSpoofColumn() // http://stackoverflow.com/q/10744728/449906
{
var sql = @"select 1 as id, 'abc' as name, 1 as spoof, NULL as description, 'def' as name";
var product = connection.Query<Product, Category, Product>(sql, (prod, cat) =>
{
prod.Category = cat;
return prod;
}, splitOn: "spoof").First();
// assertions
product.Id.IsEqualTo(1);
product.Name.IsEqualTo("abc");
product.Category.IsNotNull();
product.Category.Id.IsEqualTo(0);
product.Category.Name.IsEqualTo("def");
......
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