EndpointDispatcherTest.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //
  2. // EndpointDispatcherTest.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 2005-2006 Novell, Inc. http://www.novell.com
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System;
  29. using System.Collections.Generic;
  30. using System.Collections.ObjectModel;
  31. using System.ServiceModel.Channels;
  32. using System.ServiceModel;
  33. using System.ServiceModel.Description;
  34. using System.ServiceModel.Dispatcher;
  35. using NUnit.Framework;
  36. using SMMessage = System.ServiceModel.Channels.Message;
  37. namespace MonoTests.System.ServiceModel.Dispatcher
  38. {
  39. [TestFixture]
  40. public class EndpointDispatcherTest
  41. {
  42. [Test]
  43. public void Ctor ()
  44. {
  45. EndpointDispatcher d = new EndpointDispatcher (
  46. new EndpointAddress ("localhost:8080"),
  47. "test", "urn:foo");
  48. // properties at the Created state.
  49. Assert.IsTrue (d.AddressFilter is EndpointAddressMessageFilter, "#1");
  50. Assert.IsNull (d.ChannelDispatcher, "#2");
  51. Assert.IsNotNull (d.ContractFilter, "#3");
  52. Assert.AreEqual ("test", d.ContractName, "#4");
  53. Assert.AreEqual ("urn:foo", d.ContractNamespace, "#5");
  54. Assert.IsNotNull (d.DispatchRuntime, "#6");
  55. Assert.AreEqual (
  56. new EndpointAddress ("localhost:8080"),
  57. d.EndpointAddress, "#7");
  58. Assert.AreEqual (0, d.FilterPriority, "#8");
  59. Assert.IsNull (d.DispatchRuntime.OperationSelector, "#2-1");
  60. Assert.AreEqual (0, d.DispatchRuntime.Operations.Count, "#2-2");
  61. }
  62. [Test]
  63. public void MatchTest () {
  64. EndpointDispatcher d = new EndpointDispatcher (
  65. new EndpointAddress ("http://localhost:8000"), "test", "http://MonoTests.Tests");
  66. Message mess = Message.CreateMessage (MessageVersion.Default, "action1", (object)null);
  67. mess.Headers.To = new Uri ("http://localhost:8000");
  68. Assert.IsTrue (d.AddressFilter.Match (mess), "#1");
  69. mess.Headers.To = new Uri ("http://localhost:8001");
  70. Assert.IsFalse (d.AddressFilter.Match (mess), "#2");
  71. mess.Headers.Action = "Fail";
  72. //MatchAllMessageFilter
  73. Assert.IsTrue (d.ContractFilter.Match (mess), "#3");
  74. d.ContractFilter = new ActionMessageFilter ("action1");
  75. Assert.IsFalse (d.ContractFilter.Match (mess), "#4");
  76. mess.Headers.Action = "action1";
  77. Assert.IsTrue (d.ContractFilter.Match (mess), "#5");
  78. }
  79. [Test]
  80. public void ActionMessageFilterTest () {
  81. ServiceHost h = new ServiceHost (typeof (SpecificAction), new Uri ("http://localhost:8000"));
  82. EndpointDispatcher ed = new EndpointDispatcher (new EndpointAddress ("http://localhost:8000/address"),
  83. typeof (SpecificAction).FullName,
  84. typeof (SpecificAction).Namespace);
  85. Assert.IsTrue (ed.ContractFilter is MatchAllMessageFilter, "#1");
  86. }
  87. [Test]
  88. public void DispatchRuntimeProperty () {
  89. ServiceHost h = new ServiceHost (typeof (SpecificAction), new Uri ("http://localhost:8000"));
  90. EndpointDispatcher ed = new EndpointDispatcher (new EndpointAddress ("http://localhost:8000/address"),
  91. typeof (SpecificAction).FullName,
  92. typeof (SpecificAction).Namespace);
  93. Assert.IsNotNull (ed.DispatchRuntime, "#1");
  94. }
  95. [ServiceContract]
  96. class SpecificAction
  97. {
  98. [OperationContract (Action = "Specific", ReplyAction = "*")]
  99. public SMMessage Get (SMMessage req) {
  100. return null;
  101. }
  102. }
  103. }
  104. }