1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
;
22 public class AdaptingNameValueCollectionsTestCase
24 private NameValueCollection nameValueCollection
;
25 private DictionaryAdapterFactory factory
;
30 nameValueCollection
= new NameValueCollection();
31 factory
= new DictionaryAdapterFactory();
35 public void Factory_ForNameValueCollection_CreatesTheAdapter()
37 IFurniture furniture
= factory
.GetAdapter
<IFurniture
>(nameValueCollection
);
38 Assert
.IsNotNull(furniture
);
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
);
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"]);
60 public void Adapter_OnNameValueCollectionWithPropertyBinder_CanGetProperties()
63 nameValueCollection
["Legs"] = legs
.ToString();
64 IFurniture furniture
= factory
.GetAdapter
<IFurniture
>(nameValueCollection
);
65 Assert
.AreEqual(legs
, furniture
.Legs
);
69 public void Adapter_OnNameValueCollectionWithPropertyBinder_CanSetProperties()
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;}