ChannelDispatcherTest.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. public void EndpointDispatcherAddTest () {
  33. ServiceHost h = new ServiceHost (typeof (TestContract), new Uri ("http://localhost:8080"));
  34. h.AddServiceEndpoint (typeof (TestContract).FullName, new BasicHttpBinding (), "address");
  35. MyChannelDispatcher d = new MyChannelDispatcher (new MyChannelListener ());
  36. d.Endpoints.Add (new EndpointDispatcher (new EndpointAddress (""), "", ""));
  37. }
  38. [ServiceContract]
  39. public class TestContract
  40. {
  41. [OperationContract]
  42. public void Process (string input) {
  43. }
  44. }
  45. class MyChannelDispatcher : ChannelDispatcher
  46. {
  47. public bool Attached = false;
  48. public MyChannelDispatcher (IChannelListener l) : base (l) { }
  49. protected override void Attach (ServiceHostBase host) {
  50. base.Attach (host);
  51. Attached = true;
  52. }
  53. protected override void Detach (ServiceHostBase host) {
  54. base.Detach (host);
  55. Attached = false;
  56. }
  57. }
  58. class MyChannelListener : IChannelListener
  59. {
  60. #region IChannelListener Members
  61. public IAsyncResult BeginWaitForChannel (TimeSpan timeout, AsyncCallback callback, object state) {
  62. throw new NotImplementedException ();
  63. }
  64. public bool EndWaitForChannel (IAsyncResult result) {
  65. throw new NotImplementedException ();
  66. }
  67. public T GetProperty<T> () where T : class {
  68. throw new NotImplementedException ();
  69. }
  70. public Uri Uri {
  71. get { throw new NotImplementedException (); }
  72. }
  73. public bool WaitForChannel (TimeSpan timeout) {
  74. throw new NotImplementedException ();
  75. }
  76. #endregion
  77. #region ICommunicationObject Members
  78. public void Abort () {
  79. throw new NotImplementedException ();
  80. }
  81. public IAsyncResult BeginClose (TimeSpan timeout, AsyncCallback callback, object state) {
  82. throw new NotImplementedException ();
  83. }
  84. public IAsyncResult BeginClose (AsyncCallback callback, object state) {
  85. throw new NotImplementedException ();
  86. }
  87. public IAsyncResult BeginOpen (TimeSpan timeout, AsyncCallback callback, object state) {
  88. throw new NotImplementedException ();
  89. }
  90. public IAsyncResult BeginOpen (AsyncCallback callback, object state) {
  91. throw new NotImplementedException ();
  92. }
  93. public void Close (TimeSpan timeout) {
  94. throw new NotImplementedException ();
  95. }
  96. public void Close () {
  97. throw new NotImplementedException ();
  98. }
  99. public event EventHandler Closed;
  100. public event EventHandler Closing;
  101. public void EndClose (IAsyncResult result) {
  102. throw new NotImplementedException ();
  103. }
  104. public void EndOpen (IAsyncResult result) {
  105. throw new NotImplementedException ();
  106. }
  107. public event EventHandler Faulted;
  108. public void Open (TimeSpan timeout) {
  109. throw new NotImplementedException ();
  110. }
  111. public void Open () {
  112. throw new NotImplementedException ();
  113. }
  114. public event EventHandler Opened;
  115. public event EventHandler Opening;
  116. public CommunicationState State {
  117. get { throw new NotImplementedException (); }
  118. }
  119. #endregion
  120. }
  121. }
  122. }