Add Newtonsoft.Json to the references of TestSiteBrail
[castle.git] / Components / Binder / Castle.Components.Binder.Tests / TreeBuilderRegressionTestCase.cs
blob595ef590daaec9d6f26fa2ff8d64a5dd944f45ed
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.Collections.Specialized;
19 using NUnit.Framework;
21 [TestFixture]
22 public class TreeBuilderRegressionTestCase
24 [Test]
25 public void NoValidEntries()
27 NameValueCollection args = new NameValueCollection();
29 args.Add("customername", "x");
30 args.Add("customerage", "x");
31 args.Add("customerall", "x");
33 TreeBuilder builder = new TreeBuilder();
35 CompositeNode root = builder.BuildSourceNode(args);
36 Assert.IsNull(root.GetChildNode("customer"));
39 [Test]
40 public void OneLevelNode()
42 NameValueCollection args = new NameValueCollection();
44 args.Add("customer.name", "hammett");
45 args.Add("customer.age", "26");
46 args.Add("customer.all", "yada yada yada");
48 TreeBuilder builder = new TreeBuilder();
50 CompositeNode root = builder.BuildSourceNode(args);
52 CompositeNode node = (CompositeNode) root.GetChildNode("customer");
54 Assert.IsNotNull(node);
56 Assert.AreEqual("hammett", ((LeafNode)node.GetChildNode("name")).Value);
57 Assert.AreEqual("26", ((LeafNode)node.GetChildNode("age")).Value);
58 Assert.AreEqual("yada yada yada", ((LeafNode)node.GetChildNode("all")).Value);
61 [Test]
62 public void TwoLevels()
64 NameValueCollection args = new NameValueCollection();
66 args.Add("customer.name", "hammett");
67 args.Add("customer.age", "26");
68 args.Add("customer.location.code", "pt-br");
69 args.Add("customer.location.country", "55");
71 TreeBuilder builder = new TreeBuilder();
73 CompositeNode root = builder.BuildSourceNode(args);
74 Assert.IsNotNull(root);
76 CompositeNode node = (CompositeNode) root.GetChildNode("customer");
77 Assert.IsNotNull(root);
79 CompositeNode locationNode = (CompositeNode) node.GetChildNode("location");
80 Assert.IsNotNull(locationNode);
82 Assert.AreEqual("pt-br", ((LeafNode)locationNode.GetChildNode("code")).Value);
83 Assert.AreEqual("55", ((LeafNode)locationNode.GetChildNode("country")).Value);
86 [Test]
87 public void IndexedContent()
89 NameValueCollection args = new NameValueCollection();
91 args.Add("customer[0].name", "hammett");
92 args.Add("customer[0].age", "26");
93 args.Add("customer[0].all", "yada yada yada");
94 args.Add("customer[10].name", "frasier");
95 args.Add("customer[10].age", "50");
96 args.Add("customer[10].all", "yada");
98 TreeBuilder builder = new TreeBuilder();
100 CompositeNode root = builder.BuildSourceNode(args);
102 IndexedNode node = (IndexedNode) root.GetChildNode("customer");
104 Assert.IsNotNull(node);
105 Assert.AreEqual(2, node.ChildrenCount);
107 CompositeNode cnode = (CompositeNode) node.GetChildNode("0");
109 Assert.AreEqual("hammett", ((LeafNode) cnode.GetChildNode("name")).Value);
110 Assert.AreEqual("26", ((LeafNode) cnode.GetChildNode("age")).Value);
111 Assert.AreEqual("yada yada yada", ((LeafNode) cnode.GetChildNode("all")).Value);
113 cnode = (CompositeNode) node.GetChildNode("10");
115 Assert.AreEqual("frasier", ((LeafNode) cnode.GetChildNode("name")).Value);
116 Assert.AreEqual("50", ((LeafNode) cnode.GetChildNode("age")).Value);
117 Assert.AreEqual("yada", ((LeafNode) cnode.GetChildNode("all")).Value);