From: <fab...@us...> - 2010-07-23 14:37:09
|
Revision: 5055 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5055&view=rev Author: fabiomaulo Date: 2010-07-23 14:37:02 +0000 (Fri, 23 Jul 2010) Log Message: ----------- Fix NH-2194 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Util/PropertiesHelper.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/UtilityTest/PropertiesHelperTest.cs Modified: trunk/nhibernate/src/NHibernate/Util/PropertiesHelper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Util/PropertiesHelper.cs 2010-07-23 05:37:14 UTC (rev 5054) +++ trunk/nhibernate/src/NHibernate/Util/PropertiesHelper.cs 2010-07-23 14:37:02 UTC (rev 5055) @@ -12,29 +12,29 @@ { string toParse; properties.TryGetValue(property, out toParse); - - return toParse == null ? defaultValue : bool.Parse(toParse); + bool result; + return bool.TryParse(toParse, out result) ? result : defaultValue; } public static bool GetBoolean(string property, IDictionary<string, string> properties) { - string toParse; - properties.TryGetValue(property, out toParse); - return toParse == null ? false : bool.Parse(properties[property]); + return GetBoolean(property, properties, false); } public static int GetInt32(string property, IDictionary<string, string> properties, int defaultValue) { string toParse; properties.TryGetValue(property, out toParse); - return toParse == null ? defaultValue : int.Parse(toParse); + int result; + return int.TryParse(toParse, out result) ? result : defaultValue; } public static long GetInt64(string property, IDictionary<string, string> properties, long defaultValue) { string toParse; properties.TryGetValue(property, out toParse); - return toParse == null ? defaultValue : long.Parse(toParse); + long result; + return long.TryParse(toParse, out result) ? result : defaultValue; } public static string GetString(string property, IDictionary<string, string> properties, string defaultValue) Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-23 05:37:14 UTC (rev 5054) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-23 14:37:02 UTC (rev 5055) @@ -1610,6 +1610,7 @@ <Compile Include="UtilityTest\JoinedEnumerableGenericFixture.cs" /> <Compile Include="UtilityTest\LinkedHashMapFixture.cs" /> <Compile Include="UtilityTest\LRUMapFixture.cs" /> + <Compile Include="UtilityTest\PropertiesHelperTest.cs" /> <Compile Include="UtilityTest\ReflectHelperFixture.cs" /> <Compile Include="UtilityTest\SafetyEnumerableFixture.cs" /> <Compile Include="UtilityTest\SequencedHashMapFixture.cs" /> Added: trunk/nhibernate/src/NHibernate.Test/UtilityTest/PropertiesHelperTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/UtilityTest/PropertiesHelperTest.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/UtilityTest/PropertiesHelperTest.cs 2010-07-23 14:37:02 UTC (rev 5055) @@ -0,0 +1,46 @@ +using System.Collections.Generic; +using NHibernate.Util; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.UtilityTest +{ + public class PropertiesHelperTest + { + [Test] + public void WhenInvalidBoolValueThenUseDefault() + { + PropertiesHelper.GetBoolean("myProp", new Dictionary<string, string> {{"myProp", "pizza"}}, false).Should().Be.False(); + } + + [Test] + public void WhenInvalidInt32ValueThenUseDefault() + { + PropertiesHelper.GetInt32("myProp", new Dictionary<string, string> { { "myProp", "pizza" } }, 5).Should().Be(5); + } + + [Test] + public void WhenInvalidInt64ValueThenUseDefault() + { + PropertiesHelper.GetInt64("myProp", new Dictionary<string, string> { { "myProp", "pizza" } }, 5).Should().Be(5); + } + + [Test] + public void WhenValidBoolValueThenValue() + { + PropertiesHelper.GetBoolean("myProp", new Dictionary<string, string> { { "myProp", "true" } }, false).Should().Be.True(); + } + + [Test] + public void WhenValidInt32ValueThenValue() + { + PropertiesHelper.GetInt32("myProp", new Dictionary<string, string> { { "myProp", int.MaxValue.ToString() } }, 5).Should().Be(int.MaxValue); + } + + [Test] + public void WhenValidInt64ValueThenValue() + { + PropertiesHelper.GetInt64("myProp", new Dictionary<string, string> { { "myProp", long.MaxValue.ToString() } }, 5).Should().Be(long.MaxValue); + } + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |