ScopedMessagePartSpecificationTest.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //
  2. // ScopedMessagePartSpecificationTest.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.Generic;
  30. using System.Collections.ObjectModel;
  31. using System.ServiceModel;
  32. using System.ServiceModel.Channels;
  33. using System.ServiceModel.Security;
  34. using System.Xml;
  35. using NUnit.Framework;
  36. namespace MonoTests.System.ServiceModel
  37. {
  38. [TestFixture]
  39. public class ScopedMessagePartSpecificationTest
  40. {
  41. [Test]
  42. public void DefaultValues ()
  43. {
  44. ScopedMessagePartSpecification s =
  45. new ScopedMessagePartSpecification ();
  46. Assert.IsNotNull (s.ChannelParts, "#1");
  47. Assert.AreEqual (0, s.Actions.Count, "#2");
  48. }
  49. [Test]
  50. [ExpectedException (typeof (ArgumentNullException))]
  51. public void AddPartsNull ()
  52. {
  53. ScopedMessagePartSpecification s =
  54. new ScopedMessagePartSpecification ();
  55. s.AddParts (null);
  56. }
  57. [Test]
  58. [ExpectedException (typeof (ArgumentNullException))]
  59. public void AddPartsNull2 ()
  60. {
  61. ScopedMessagePartSpecification s =
  62. new ScopedMessagePartSpecification ();
  63. s.AddParts (null, "urn:foo");
  64. }
  65. [Test]
  66. [ExpectedException (typeof (ArgumentNullException))]
  67. public void AddPartsNull3 ()
  68. {
  69. ScopedMessagePartSpecification s =
  70. new ScopedMessagePartSpecification ();
  71. s.AddParts (new MessagePartSpecification (), null);
  72. }
  73. [Test]
  74. public void AddParts ()
  75. {
  76. ScopedMessagePartSpecification s =
  77. new ScopedMessagePartSpecification ();
  78. Assert.IsFalse (s.ChannelParts.IsBodyIncluded, "#1");
  79. s.AddParts (new MessagePartSpecification (true));
  80. Assert.AreEqual (0, s.Actions.Count, "#2");
  81. Assert.IsTrue (s.ChannelParts.IsBodyIncluded, "#3");
  82. XmlQualifiedName foo = new XmlQualifiedName ("foo");
  83. XmlQualifiedName bar = new XmlQualifiedName ("bar");
  84. s.AddParts (new MessagePartSpecification (new XmlQualifiedName [] {foo}), "urn:foo");
  85. Assert.AreEqual (1, s.Actions.Count, "#4");
  86. MessagePartSpecification m;
  87. s.TryGetParts ("urn:foo", out m);
  88. Assert.IsNotNull (m, "#5");
  89. Assert.AreEqual (1, m.HeaderTypes.Count, "#6");
  90. s.AddParts (new MessagePartSpecification (true, new XmlQualifiedName [] {bar}), "urn:foo");
  91. Assert.AreEqual (1, s.Actions.Count, "#7");
  92. s.TryGetParts ("urn:foo", out m);
  93. Assert.IsNotNull (m, "#8");
  94. //List<XmlQualifiedName> l = new List<XmlQualifiedName> (m.HeaderTypes);
  95. Assert.AreEqual (2, m.HeaderTypes.Count, "#9");
  96. Assert.IsTrue (m.IsBodyIncluded, "#10");
  97. }
  98. [Test]
  99. [ExpectedException (typeof (InvalidOperationException))]
  100. public void AddToReadOnlyCollection ()
  101. {
  102. ScopedMessagePartSpecification s =
  103. new ScopedMessagePartSpecification ();
  104. s.MakeReadOnly ();
  105. Assert.AreEqual (true, s.IsReadOnly, "#1");
  106. s.AddParts (new MessagePartSpecification (), "urn:myaction");
  107. }
  108. [Test]
  109. public void TryGetParts ()
  110. {
  111. ScopedMessagePartSpecification s =
  112. new ScopedMessagePartSpecification ();
  113. MessagePartSpecification ret;
  114. Assert.IsFalse (s.TryGetParts ("urn:myaction", out ret));
  115. Assert.IsFalse (s.TryGetParts ("urn:myaction", true, out ret));
  116. Assert.IsFalse (s.TryGetParts ("urn:myaction", false, out ret));
  117. s.AddParts (new MessagePartSpecification (), "urn:myaction");
  118. Assert.IsTrue (s.TryGetParts ("urn:myaction", out ret));
  119. Assert.IsTrue (s.TryGetParts ("urn:myaction", true, out ret));
  120. Assert.IsTrue (s.TryGetParts ("urn:myaction", false, out ret));
  121. }
  122. }
  123. }