2 // System.ComponentModel.Container test cases
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 // Ivan N. Zlatev (contact i-nZ.net)
8 // Copyright (c) 2006 Novell, Inc. (http://www.novell.com)
9 // Copyright (c) 2006 Ivan N. Zlatev
12 using NUnit.Framework;
14 using System.ComponentModel;
15 using System.ComponentModel.Design;
17 namespace MonoTests.System.ComponentModel
22 class TestContainer : Container {
23 ServiceContainer _services = new ServiceContainer();
25 public TestContainer() {
26 _services.AddService( typeof(TestService), new TestService() );
29 protected override object GetService( Type serviceType ) {
30 return _services.GetService( serviceType );
34 public void Remove_WithoutUnsiting (IComponent component)
36 base.RemoveWithoutUnsiting (component);
40 public bool Contains (IComponent component)
44 foreach (IComponent c in Components) {
45 if (component.Equals (c)) {
54 class TestComponent : Component {
55 public override ISite Site {
62 Assert.IsNotNull (value.GetService (typeof (ISite)));
63 Assert.IsNotNull (value.GetService (typeof (TestService)));
70 public class ContainerTest
73 private TestContainer _container;
78 _container = new TestContainer ();
83 public void AddRemove ()
85 TestComponent component = new TestComponent ();
87 _container.Add (component);
88 Assert.IsNotNull (component.Site, "#1");
89 Assert.IsTrue (_container.Contains (component), "#2");
91 _container.Remove (component);
92 Assert.IsNull (component.Site, "#3");
93 Assert.IsFalse (_container.Contains (component), "#4");
96 _container.Add (component);
97 _container.Remove_WithoutUnsiting (component);
98 Assert.IsNotNull (component.Site, "#5");
99 Assert.IsFalse (_container.Contains (component), "#6");
104 public void GetService1 ()
106 _container.Add (new TestComponent ());
111 [ExpectedException (typeof (ArgumentException))]
112 public void ValidateName ()
114 TestContainer container = new TestContainer ();
115 TestComponent c1 = new TestComponent ();
116 container.Add (c1, "dup");
117 TestComponent c2 = new TestComponent ();
118 container.Add (c2, "dup");