Mercurial > pub > bltoolkit
diff HowTo/Mapping/ValueToEnum.cs @ 0:f990fcb411a9
Копия текущей версии из github
author | cin |
---|---|
date | Thu, 27 Mar 2014 21:46:09 +0400 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HowTo/Mapping/ValueToEnum.cs Thu Mar 27 21:46:09 2014 +0400 @@ -0,0 +1,60 @@ +using System; + +using NUnit.Framework; + +using BLToolkit.Mapping; + +namespace HowTo.Mapping +{ + [TestFixture] + public class ValueToEnum + { + public enum Gender1 + { + [MapValue("F")] Female, + [MapValue("M")] Male, + [MapValue("U")] Unknown, + [MapValue("O")] Other + } + + [Test] + public void Test1() + { + Gender1 g = Map./*[a]*/ToEnum<Gender1>/*[/a]*/("M"); + + Assert.AreEqual(Gender1.Male, g); + } + + public enum Gender2 + { + [MapValue(1)] Female, + [MapValue(2)] Male, + [MapValue(3)] Unknown, + [MapValue(4)] Other + } + + [Test] + public void Test2() + { + Gender2 g = Map./*[a]*/ToEnum<Gender2>/*[/a]*/(2); + + Assert.AreEqual(Gender2.Male, g); + } + + public enum Gender3 + { + Female = 1, + Male = 2, + Unknown = 3, + Other = 4 + } + + [Test] + public void Test3() + { + Gender3 g = Map./*[a]*/ToEnum<Gender3>/*[/a]*/(2); + + Assert.AreEqual(Gender3.Male, g); + } + } +}