Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / Components / Binder / Castle.Components.Binder.Tests / GenericBindingTestCase.cs
blob12b8f143bc235d8e174442af936cc40ff327c84a
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.Collections.Generic;
18 using Castle.Components.Binder;
19 using NUnit.Framework;
21 [TestFixture]
22 public class GenericBindingTestCase
24 [Test]
25 public void CanBindToGenericListInstance()
27 int expectedValue = 12;
29 List<int> myList = new List<int>();
30 myList.Add(expectedValue);
32 DataBinder binder = new DataBinder();
33 CompositeNode paramsNode = GetParamsNode(expectedValue);
35 binder.BindObjectInstance(myList, "myList", paramsNode);
36 Assert.AreEqual(expectedValue, myList[0]);
39 [Test]
40 public void CanBindToGenericList()
42 int expectedValue = 32;
43 DataBinder binder = new DataBinder();
44 CompositeNode paramsNode = GetParamsNode(expectedValue);
45 List<int> myList = (List<int>) binder.BindObject(typeof(List<int>), "myList", paramsNode);
47 Assert.AreEqual(expectedValue, myList[0]);
50 private static CompositeNode GetParamsNode(int expectedValue)
52 CompositeNode paramsNode = new CompositeNode("root");
53 IndexedNode listNode = new IndexedNode("myList");
54 paramsNode.AddChildNode(listNode);
55 listNode.AddChildNode(new LeafNode(typeof(int), "", expectedValue));
56 return paramsNode;