Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ContainerTest.cs « System.ComponentModel « Test « System « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 78e0f1533202f19fd387ffec94ae10cafe3be028 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//
// System.ComponentModel.Container test cases
//
// Authors:
// 	Gonzalo Paniagua Javier (gonzalo@ximian.com)
//  Ivan N. Zlatev (contact i-nZ.net)

// Copyright (c) 2006 Novell, Inc. (http://www.novell.com)
// Copyright (c) 2006 Ivan N. Zlatev
//

using NUnit.Framework;
using System;
using System.ComponentModel;
using System.ComponentModel.Design;

namespace MonoTests.System.ComponentModel
{
	class TestService {
	}
	
	class TestContainer : Container {
		ServiceContainer _services = new ServiceContainer();
		
		public TestContainer() {
			_services.AddService( typeof(TestService), new TestService() );
		}
		
		protected override object GetService( Type serviceType ) {
			return _services.GetService( serviceType );
		}

#if NET_2_0
		public void Remove_WithoutUnsiting (IComponent component)
		{
			base.RemoveWithoutUnsiting (component);
		}
#endif
		
		public bool Contains (IComponent component)
		{
			bool found = false;
			
			foreach (IComponent c in Components) {
				if (component.Equals (c)) {
					found = true;
					break;
				}
			}
			return found;
		}
	}
	
	class TestComponent : Component {
		public override ISite Site {
			get {
				return base.Site;
			}
			set {
				base.Site = value;
				if (value != null) {
					Assert.IsNotNull (value.GetService (typeof (ISite)));
					Assert.IsNotNull (value.GetService (typeof (TestService)));
				}
			}
		}
	}

	[TestFixture]
	public class ContainerTest
	{
		
		private TestContainer _container;
		
		[SetUp]
		public void Init ()
		{
			_container = new TestContainer ();
		}

		
		[Test]
		public void AddRemove ()
		{
			TestComponent component = new TestComponent ();
			
			_container.Add (component);
			Assert.IsNotNull (component.Site, "#1");
			Assert.IsTrue (_container.Contains (component), "#2");
			
			_container.Remove (component);
			Assert.IsNull (component.Site, "#3");
			Assert.IsFalse (_container.Contains (component), "#4");
			
#if NET_2_0
			_container.Add (component);
			_container.Remove_WithoutUnsiting (component);
			Assert.IsNotNull (component.Site, "#5");
			Assert.IsFalse (_container.Contains (component), "#6");
#endif
		}

		[Test]
		public void GetService1 ()
		{
			_container.Add (new TestComponent ());
		}

#if NET_2_0
		[Test]
		[ExpectedException (typeof (ArgumentException))]
		public void ValidateName ()
		{
			TestContainer container = new TestContainer ();
			TestComponent c1 = new TestComponent ();
			container.Add (c1, "dup");
			TestComponent c2 = new TestComponent ();
			container.Add (c2, "dup");
		}
#endif
	}
}