ContainerTest.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //
  2. // System.ComponentModel.Container test cases
  3. //
  4. // Authors:
  5. // Gonzalo Paniagua Javier ([email protected])
  6. //
  7. // Copyright (c) 2006 Novell, Inc. (http://www.novell.com)
  8. //
  9. using NUnit.Framework;
  10. using System;
  11. using System.ComponentModel;
  12. using System.ComponentModel.Design;
  13. namespace MonoTests.System.ComponentModel
  14. {
  15. class TestService {
  16. }
  17. class TestContainer : Container {
  18. ServiceContainer _services = new ServiceContainer();
  19. public TestContainer() {
  20. _services.AddService( typeof(TestService), new TestService() );
  21. }
  22. protected override object GetService( Type serviceType ) {
  23. return _services.GetService( serviceType );
  24. }
  25. }
  26. class TestComponent : Component {
  27. public override ISite Site {
  28. get {
  29. return base.Site;
  30. }
  31. set {
  32. base.Site = value;
  33. if (value != null) {
  34. Assert.IsNotNull (value.GetService (typeof (ISite)));
  35. Assert.IsNotNull (value.GetService (typeof (TestService)));
  36. }
  37. }
  38. }
  39. }
  40. [TestFixture]
  41. public class ContainerTest {
  42. [Test]
  43. public void GetService1 ()
  44. {
  45. TestContainer container = new TestContainer ();
  46. container.Add (new TestComponent ());
  47. }
  48. }
  49. }