OperationDescriptionTest.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //
  2. // OperationDescriptionTest.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 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.ObjectModel;
  30. using System.ServiceModel;
  31. using System.ServiceModel.Channels;
  32. using System.ServiceModel.Description;
  33. using System.ServiceModel.Dispatcher;
  34. using NUnit.Framework;
  35. namespace MonoTests.System.ServiceModel.Description
  36. {
  37. [TestFixture]
  38. public class OperationDescriptionTest
  39. {
  40. [Test]
  41. public void Messages ()
  42. {
  43. ContractDescription cd =
  44. ContractDescription.GetContract (typeof (IFoo));
  45. OperationDescription od = cd.Operations [0];
  46. Assert.IsNull (od.Messages.Find ("Echo"), "#1");
  47. MessageDescription md = od.Messages.Find ("http://tempuri.org/IFoo/Echo");
  48. Assert.IsNotNull (md, "#2");
  49. Assert.AreEqual ("http://tempuri.org/IFoo/Echo", md.Action, "#3");
  50. Assert.AreEqual (MessageDirection.Input, md.Direction, "#4");
  51. Assert.IsFalse (md.HasProtectionLevel, "#5");
  52. Assert.IsNotNull (md.Headers, "#6");
  53. Assert.AreEqual (0, md.Headers.Count, "#7");
  54. Assert.IsNull (md.MessageType, "#8");
  55. Assert.IsNotNull (md.Properties, "#9");
  56. Assert.AreEqual (0, md.Properties.Count, "#10");
  57. MessageBodyDescription mb = md.Body;
  58. Assert.IsNotNull (mb, "#11");
  59. Assert.AreEqual ("Echo", mb.WrapperName, "#12");
  60. Assert.AreEqual ("http://tempuri.org/", mb.WrapperNamespace, "#13");
  61. Assert.IsNotNull (mb.Parts, "#14");
  62. Assert.AreEqual (0, mb.Parts.Count, "#15");
  63. Assert.IsNull (mb.ReturnValue, "#16"); // void Echo()
  64. }
  65. [Test]
  66. public void MessagesNameSpace ()
  67. {
  68. ContractDescription cd =
  69. ContractDescription.GetContract (typeof (IFoo2));
  70. OperationDescription od = cd.Operations [0];
  71. Assert.IsNull (od.Messages.Find ("Echo"), "#1");
  72. MessageDescription md = od.Messages.Find ("http://MonoTests.System.ServiceModel.Description/IFoo2/Echo");
  73. Assert.IsNotNull (md, "#2");
  74. Assert.AreEqual ("http://MonoTests.System.ServiceModel.Description/IFoo2/Echo", md.Action, "#3");
  75. Assert.AreEqual (MessageDirection.Input, md.Direction, "#4");
  76. Assert.IsFalse (md.HasProtectionLevel, "#5");
  77. Assert.IsNotNull (md.Headers, "#6");
  78. Assert.AreEqual (0, md.Headers.Count, "#7");
  79. Assert.IsNull (md.MessageType, "#8");
  80. Assert.IsNotNull (md.Properties, "#9");
  81. Assert.AreEqual (0, md.Properties.Count, "#10");
  82. MessageBodyDescription mb = md.Body;
  83. Assert.IsNotNull (mb, "#11");
  84. Assert.AreEqual ("Echo", mb.WrapperName, "#12");
  85. Assert.AreEqual ("http://MonoTests.System.ServiceModel.Description", mb.WrapperNamespace, "#13");
  86. Assert.IsNotNull (mb.Parts, "#14");
  87. Assert.AreEqual (0, mb.Parts.Count, "#15");
  88. Assert.IsNull (mb.ReturnValue, "#16"); // void Echo()
  89. }
  90. [Test]
  91. public void Parts ()
  92. {
  93. ContractDescription cd =
  94. ContractDescription.GetContract (typeof (IFoo3));
  95. MessagePartDescriptionCollection parts =
  96. cd.Operations [0].Messages [0].Body.Parts;
  97. Assert.AreEqual (1, parts.Count, "#1");
  98. MessagePartDescription part = parts [0];
  99. Assert.AreEqual ("intValue", part.Name, "#2");
  100. Assert.AreEqual ("http://tempuri.org/", part.Namespace, "#3");
  101. Assert.AreEqual (typeof (int), part.Type, "#4");
  102. Assert.AreEqual (0, part.Index, "#5");
  103. Assert.AreEqual (false, part.Multiple, "#5");
  104. }
  105. [Test]
  106. public void PartsNamespace ()
  107. {
  108. ContractDescription cd =
  109. ContractDescription.GetContract (typeof (IFoo4));
  110. MessagePartDescriptionCollection parts =
  111. cd.Operations [0].Messages [0].Body.Parts;
  112. Assert.AreEqual (1, parts.Count, "#1");
  113. MessagePartDescription part = parts [0];
  114. Assert.AreEqual ("intValue", part.Name, "#2");
  115. Assert.AreEqual ("http://MonoTests.System.ServiceModel.Description", part.Namespace, "#3");
  116. Assert.AreEqual (typeof (int), part.Type, "#4");
  117. Assert.AreEqual (0, part.Index, "#5");
  118. Assert.AreEqual (false, part.Multiple, "#5");
  119. }
  120. [ServiceContract]
  121. public interface IFoo
  122. {
  123. [OperationContract]
  124. void Echo ();
  125. }
  126. [ServiceContract(Namespace="http://MonoTests.System.ServiceModel.Description")]
  127. public interface IFoo2
  128. {
  129. [OperationContract]
  130. void Echo ();
  131. }
  132. [ServiceContract]
  133. public interface IFoo3
  134. {
  135. [OperationContract]
  136. int Echo (int intValue);
  137. }
  138. [ServiceContract (Namespace = "http://MonoTests.System.ServiceModel.Description")]
  139. public interface IFoo4
  140. {
  141. [OperationContract]
  142. int Echo (int intValue);
  143. }
  144. }
  145. }