Added CascadingAdapter to be able to chain data sources. Very useful in web situations.
[castle.git] / Components / DictionaryAdapter / Castle.Components.DictionaryAdapter.Tests / AdaptingNameValueCollectionsTestCase.cs
blob162e5f92092b79a69124e44c94ff6ec970123585
1 // Copyright 2004-2007 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.
16 namespace Castle.Components.DictionaryAdapter.Tests
18 using NUnit.Framework;
19 using System.Collections.Specialized;
21 [TestFixture]
22 public class AdaptingNameValueCollectionsTestCase
24 private NameValueCollection nameValueCollection;
25 private DictionaryAdapterFactory factory;
27 [SetUp]
28 public void SetUp()
30 nameValueCollection = new NameValueCollection();
31 factory = new DictionaryAdapterFactory();
34 [Test]
35 public void Factory_ForNameValueCollection_CreatesTheAdapter()
37 IFurniture furniture = factory.GetAdapter<IFurniture>(nameValueCollection);
38 Assert.IsNotNull(furniture);
41 [Test]
42 public void Adapter_OnNameValueCollection_CanGetProperties()
44 string typeName = "Chair";
45 nameValueCollection["TypeName"] = typeName;
46 IFurniture furniture = factory.GetAdapter<IFurniture>(nameValueCollection);
47 Assert.AreEqual(typeName, furniture.TypeName);
50 [Test]
51 public void Adapter_OnNameValueCollection_CanSetProperties()
53 string typeName = "Chair";
54 IFurniture furniture = factory.GetAdapter<IFurniture>(nameValueCollection);
55 furniture.TypeName = typeName;
56 Assert.AreEqual(typeName, nameValueCollection["TypeName"]);
59 [Test]
60 public void Adapter_OnNameValueCollectionWithPropertyBinder_CanGetProperties()
62 int legs = 2;
63 nameValueCollection["Legs"] = legs.ToString();
64 IFurniture furniture = factory.GetAdapter<IFurniture>(nameValueCollection);
65 Assert.AreEqual(legs, furniture.Legs);
68 [Test]
69 public void Adapter_OnNameValueCollectionWithPropertyBinder_CanSetProperties()
71 int legs = 2;
72 IFurniture furniture = factory.GetAdapter<IFurniture>(nameValueCollection);
73 furniture.Legs = legs;
74 Assert.AreEqual(legs.ToString(), nameValueCollection["Legs"]);
78 public interface IFurniture
80 string TypeName { get; set; }
82 [DictionaryAdapterPropertyBinder(typeof(DictionaryAdapterStringToNullableIntBinder))]
83 int? Legs { get; set;}