2 // Tests for System.Web.UI.WebControls.ValidatedControlConverterTest.cs
5 // Peter Dennis Bartok (pbartok@novell.com)
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using NUnit.Framework;
33 using System.Collections;
34 using System.ComponentModel;
37 using System.Globalization;
39 using ComponentSpace = System.ComponentModel;
41 using System.Web.UI.WebControls;
43 namespace MonoTests.System.Web.UI.WebControls
46 public class ValidatedControlConverterTest {
47 public class ControlContainer : IContainer {
48 ComponentCollection col;
50 public ControlContainer(ICollection collection) {
51 Control[] controls = new Control[collection.Count];
55 foreach(Control c in collection) {
59 col = new ComponentCollection(controls);
62 public ComponentCollection Components {
66 public void Remove(IComponent component) { }
67 public void Add(IComponent component, string name) { }
68 void ComponentSpace.IContainer.Add(IComponent component) { }
69 public void Dispose() { }
72 public class ControlTypeDescriptorContext : ITypeDescriptorContext {
75 public ControlTypeDescriptorContext (ICollection collection) {
76 cc = new ControlContainer(collection);
80 public IContainer Container {
86 public void OnComponentChanged() { }
87 public bool OnComponentChanging() { return false; }
88 public object Instance { get { return null; } }
89 public PropertyDescriptor PropertyDescriptor { get { return null; } }
90 public object GetService(Type serviceType) { return null; }
93 public class NamingContainer : WebControl, INamingContainer {
98 public void Basic () {
101 ValidatedControlConverter conv;
102 TypeConverter.StandardValuesCollection values;
103 NamingContainer container;
107 ControlTypeDescriptorContext context;
109 container = new NamingContainer ();
110 ctl1 = new TextBox ();
111 ctl2 = new TextBox ();
112 ddl = new DropDownList();
114 // Button has no ValidationProperty and will not show in the list
117 container.Controls.Add (ctl1);
118 container.Controls.Add (ctl2);
119 container.Controls.Add (btn);
120 container.Controls.Add (ddl);
122 container.ID = "naming";
128 context = new ControlTypeDescriptorContext(container.Controls);
129 conv = new ValidatedControlConverter();
131 values = conv.GetStandardValues(context);
132 Assert.AreEqual(3, values.Count, "B1");
134 result = new string[values.Count];
136 foreach (string s in values) {
140 Assert.AreEqual(new string[] { "blahid", "ddlid", "fooid"}, result, "B2"); // Alphabetical?
141 Assert.AreEqual(false, conv.GetStandardValuesExclusive(null), "B3");
142 Assert.AreEqual(true, conv.GetStandardValuesSupported(null), "B4");
143 Assert.AreEqual(null, conv.GetStandardValues(null), "B5");