forked from DapperLib/Dapper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DapperLib#259: Order of processing value was changed.
- Loading branch information
Maksim Golev
authored and
Maksim Golev
committed
Jun 28, 2018
1 parent
4e62055
commit b9b0bd2
Showing
4 changed files
with
157 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Collections.Generic; | ||
using Dapper.Tests.TestEntities; | ||
|
||
namespace Dapper.Tests.TestCases | ||
{ | ||
public class EnumTestCases | ||
{ | ||
public static IEnumerable<object[]> TestEnumParsingWithHandlerCases | ||
{ | ||
get | ||
{ | ||
yield return new object[] { "SELECT 1 AS Id, 'F' AS Type", new List<Item>() { new Item(1, ItemType.Foo) } }; | ||
yield return new object[] { "SELECT 22 AS Id, 'B' AS Type", new List<Item>() { new Item(22, ItemType.Bar) } }; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using System; | ||
using System.Data; | ||
|
||
namespace Dapper.Tests.TestEntities | ||
{ | ||
public enum ItemType | ||
{ | ||
Foo = 1, | ||
Bar = 2, | ||
} | ||
|
||
public class ItemTypeHandler : SqlMapper.TypeHandler<ItemType> | ||
{ | ||
public override ItemType Parse(object value) | ||
{ | ||
var c = ((string)value)[0]; | ||
switch (c) | ||
{ | ||
case 'F': return ItemType.Foo; | ||
case 'B': return ItemType.Bar; | ||
default: throw new ArgumentOutOfRangeException(); | ||
} | ||
} | ||
|
||
public override void SetValue(IDbDataParameter p, ItemType value) | ||
{ | ||
p.DbType = DbType.AnsiStringFixedLength; | ||
p.Size = 1; | ||
|
||
switch (value) | ||
{ | ||
case ItemType.Foo: | ||
{ | ||
p.Value = "F"; | ||
break; | ||
} | ||
case ItemType.Bar: | ||
{ | ||
p.Value = "B"; | ||
break; | ||
} | ||
default: | ||
{ | ||
throw new ArgumentOutOfRangeException(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public class Item : IEquatable<Item> | ||
{ | ||
public long Id { get; set; } | ||
public ItemType Type { get; set; } | ||
|
||
public Item(long id, ItemType type) | ||
{ | ||
Id = id; | ||
Type = type; | ||
} | ||
|
||
public Item() | ||
: this(default(long), default(ItemType)) | ||
{ | ||
|
||
} | ||
|
||
public bool Equals(Item other) | ||
{ | ||
bool returnValue; | ||
if ((Id == other.Id) && (Type == other.Type)) | ||
{ | ||
returnValue = true; | ||
} | ||
else | ||
{ | ||
returnValue = false; | ||
} | ||
return returnValue; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters