Add Newtonsoft.Json to the references of TestSiteBrail
[castle.git] / Components / Binder / Castle.Components.Binder.Tests / NullablesTestCase.cs
blobbb996a42b94397463686524abeb255a987c189d8
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.Components.Binder.Tests
17 using System;
18 using System.Globalization;
19 using System.Threading;
20 using Nullables;
21 using NUnit.Framework;
23 [TestFixture]
24 public class NullablesTestCase
26 private bool convSucceed;
28 [TestFixtureSetUp]
29 public void Init()
31 CultureInfo en = CultureInfo.CreateSpecificCulture( "en" );
33 Thread.CurrentThread.CurrentCulture = en;
34 Thread.CurrentThread.CurrentUICulture = en;
37 [Test]
38 public void NullableIntConversion()
40 Assert.AreEqual(new NullableInt32(10), Convert(typeof(NullableInt32), "10"));
41 Assert.IsTrue(convSucceed);
43 NullableInt32 val = (NullableInt32) Convert(typeof(NullableInt32), "");
44 Assert.IsFalse(val.HasValue);
45 Assert.IsTrue(convSucceed);
48 private object Convert(Type desiredType, string input)
50 return new DefaultConverter().Convert(desiredType, input, out convSucceed);