ChannelDispatcherTest.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using NUnit.Framework;
  6. using System.ServiceModel;
  7. using System.ServiceModel.Channels;
  8. using System.ServiceModel.Dispatcher;
  9. namespace MonoTests.System.ServiceModel.Dispatcher
  10. {
  11. [TestFixture]
  12. public class ChannelDispatcherTest
  13. {
  14. [Test]
  15. public void Collection_Add_Remove () {
  16. Console.WriteLine ("STart test Collection_Add_Remove");
  17. ServiceHost h = new ServiceHost (typeof (TestContract), new Uri ("http://localhost:8080"));
  18. h.AddServiceEndpoint (typeof (TestContract).FullName, new BasicHttpBinding (), "address");
  19. MyChannelDispatcher d = new MyChannelDispatcher (new MyChannelListener ());
  20. h.ChannelDispatchers.Add (d);
  21. Assert.IsTrue (d.Attached, "#1");
  22. h.ChannelDispatchers.Remove (d);
  23. Assert.IsFalse (d.Attached, "#2");
  24. h.ChannelDispatchers.Insert (0, d);
  25. Assert.IsTrue (d.Attached, "#3");
  26. h.ChannelDispatchers.Add (new MyChannelDispatcher (new MyChannelListener ()));
  27. h.ChannelDispatchers.Clear ();
  28. Assert.IsFalse (d.Attached, "#4");
  29. }
  30. [Test]
  31. [Category("NotWorking")]
  32. [Ignore ("fails under .NET; I never bothered to fix the test")]
  33. public void EndpointDispatcherAddTest () {
  34. ServiceHost h = new ServiceHost (typeof (TestContract), new Uri ("http://localhost:8080"));
  35. h.AddServiceEndpoint (typeof (TestContract).FullName, new BasicHttpBinding (), "address");
  36. MyChannelDispatcher d = new MyChannelDispatcher (new MyChannelListener ());
  37. d.Endpoints.Add (new EndpointDispatcher (new EndpointAddress (""), "", ""));
  38. }
  39. [ServiceContract]
  40. public class TestContract
  41. {
  42. [OperationContract]
  43. public void Process (string input) {
  44. }
  45. }
  46. class MyChannelDispatcher : ChannelDispatcher
  47. {
  48. public bool Attached = false;
  49. public MyChannelDispatcher (IChannelListener l) : base (l) { }
  50. protected override void Attach (ServiceHostBase host) {
  51. base.Attach (host);
  52. Attached = true;
  53. }
  54. protected override void Detach (ServiceHostBase host) {
  55. base.Detach (host);
  56. Attached = false;
  57. }
  58. }
  59. class MyChannelListener : IChannelListener
  60. {
  61. #region IChannelListener Members
  62. public IAsyncResult BeginWaitForChannel (TimeSpan timeout, AsyncCallback callback, object state) {
  63. throw new NotImplementedException ();
  64. }
  65. public bool EndWaitForChannel (IAsyncResult result) {
  66. throw new NotImplementedException ();
  67. }
  68. public T GetProperty<T> () where T : class {
  69. throw new NotImplementedException ();
  70. }
  71. public Uri Uri {
  72. get { throw new NotImplementedException (); }
  73. }
  74. public bool WaitForChannel (TimeSpan timeout) {
  75. throw new NotImplementedException ();
  76. }
  77. #endregion
  78. #region ICommunicationObject Members
  79. public void Abort () {
  80. throw new NotImplementedException ();
  81. }
  82. public IAsyncResult BeginClose (TimeSpan timeout, AsyncCallback callback, object state) {
  83. throw new NotImplementedException ();
  84. }
  85. public IAsyncResult BeginClose (AsyncCallback callback, object state) {
  86. throw new NotImplementedException ();
  87. }
  88. public IAsyncResult BeginOpen (TimeSpan timeout, AsyncCallback callback, object state) {
  89. throw new NotImplementedException ();
  90. }
  91. public IAsyncResult BeginOpen (AsyncCallback callback, object state) {
  92. throw new NotImplementedException ();
  93. }
  94. public void Close (TimeSpan timeout) {
  95. throw new NotImplementedException ();
  96. }
  97. public void Close () {
  98. throw new NotImplementedException ();
  99. }
  100. public event EventHandler Closed;
  101. public event EventHandler Closing;
  102. public void EndClose (IAsyncResult result) {
  103. throw new NotImplementedException ();
  104. }
  105. public void EndOpen (IAsyncResult result) {
  106. throw new NotImplementedException ();
  107. }
  108. public event EventHandler Faulted;
  109. public void Open (TimeSpan timeout) {
  110. throw new NotImplementedException ();
  111. }
  112. public void Open () {
  113. throw new NotImplementedException ();
  114. }
  115. public event EventHandler Opened;
  116. public event EventHandler Opening;
  117. public CommunicationState State {
  118. get { throw new NotImplementedException (); }
  119. }
  120. #endregion
  121. }
  122. }
  123. }