MsmqBindingElementBaseTest.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //
  2. // MsmqBindingElementBaseTest.cs
  3. //
  4. // Author:
  5. // Carlos Alberto Cortez <[email protected]>
  6. //
  7. // Copyright (C) 2010 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.Net.Security;
  30. using System.ServiceModel;
  31. using System.ServiceModel.Channels;
  32. using System.ServiceModel.Description;
  33. using System.Xml;
  34. using NUnit.Framework;
  35. namespace MonoTests.System.ServiceModel.Channels
  36. {
  37. [TestFixture]
  38. public class MsmqBindingElementBaseTest
  39. {
  40. [Test]
  41. public void ExportPolicyDefault ()
  42. {
  43. MsmqBindingElementBase binding_element = new MsmqTransportBindingElement ();
  44. IPolicyExportExtension export_extension = binding_element as IPolicyExportExtension;
  45. PolicyConversionContext conversion_context = new CustomPolicyConversionContext ();
  46. export_extension.ExportPolicy (new WsdlExporter (), conversion_context);
  47. PolicyAssertionCollection binding_assertions = conversion_context.GetBindingAssertions ();
  48. BindingElementCollection binding_elements = conversion_context.BindingElements;
  49. Assert.AreEqual (4, binding_assertions.Count, "#A0");
  50. Assert.AreEqual (0, binding_elements.Count, "#A1");
  51. // wsaw:UsingAddressing
  52. XmlNode using_addressing_node = FindAssertion (binding_assertions, "wsaw:UsingAddressing");
  53. Assert.AreEqual (true, using_addressing_node != null, "#B0");
  54. Assert.AreEqual ("UsingAddressing", using_addressing_node.LocalName, "#B1");
  55. Assert.AreEqual ("http://www.w3.org/2006/05/addressing/wsdl", using_addressing_node.NamespaceURI, "#B2");
  56. Assert.AreEqual (String.Empty, using_addressing_node.InnerText, "#B3");
  57. Assert.AreEqual (0, using_addressing_node.Attributes.Count, "#B4");
  58. Assert.AreEqual (0, using_addressing_node.ChildNodes.Count, "#B5");
  59. // msb:BinaryEncoding
  60. XmlNode binary_encoding_node = FindAssertion (binding_assertions, "msb:BinaryEncoding");
  61. Assert.AreEqual (true, binary_encoding_node != null, "#C0");
  62. Assert.AreEqual ("BinaryEncoding", binary_encoding_node.LocalName, "#C1");
  63. Assert.AreEqual ("http://schemas.microsoft.com/ws/06/2004/mspolicy/netbinary1", binary_encoding_node.NamespaceURI, "#C2");
  64. Assert.AreEqual (String.Empty, binary_encoding_node.InnerText, "#C3");
  65. Assert.AreEqual (0, binary_encoding_node.Attributes.Count, "#C4");
  66. Assert.AreEqual (0, binary_encoding_node.ChildNodes.Count, "#C5");
  67. // msmq:Authenticated
  68. XmlNode authenticated_node = FindAssertion (binding_assertions, "msmq:Authenticated");
  69. Assert.AreEqual (true, authenticated_node != null, "#D0");
  70. Assert.AreEqual ("Authenticated", authenticated_node.LocalName, "#D1");
  71. Assert.AreEqual ("http://schemas.microsoft.com/ws/06/2004/mspolicy/msmq", authenticated_node.NamespaceURI, "#D2");
  72. Assert.AreEqual (String.Empty, authenticated_node.InnerText, "#D3");
  73. Assert.AreEqual (0, authenticated_node.Attributes.Count, "#D4");
  74. Assert.AreEqual (0, authenticated_node.ChildNodes.Count, "#D5");
  75. // msmq:WindowsDomain
  76. XmlNode domain_node = FindAssertion (binding_assertions, "msmq:WindowsDomain");
  77. Assert.AreEqual (true, domain_node != null, "#E0");
  78. Assert.AreEqual ("WindowsDomain", domain_node.LocalName, "#E1");
  79. Assert.AreEqual ("http://schemas.microsoft.com/ws/06/2004/mspolicy/msmq", domain_node.NamespaceURI, "#E2");
  80. Assert.AreEqual (String.Empty, domain_node.InnerText, "#E3");
  81. Assert.AreEqual (0, domain_node.Attributes.Count, "#E4");
  82. Assert.AreEqual (0, domain_node.ChildNodes.Count, "#E5");
  83. }
  84. [Test]
  85. public void ExportPolicy ()
  86. {
  87. MsmqBindingElementBase binding_element = new MsmqTransportBindingElement ();
  88. binding_element.CustomDeadLetterQueue = new Uri ("msmq://custom");
  89. binding_element.DeadLetterQueue = DeadLetterQueue.Custom;
  90. binding_element.Durable = !binding_element.Durable; // Volatile
  91. binding_element.ExactlyOnce = !binding_element.ExactlyOnce; // BestEffort
  92. binding_element.ManualAddressing = !binding_element.ManualAddressing;
  93. binding_element.MaxBufferPoolSize = binding_element.MaxBufferPoolSize / 2;
  94. binding_element.MaxReceivedMessageSize = binding_element.MaxReceivedMessageSize / 2;
  95. binding_element.MaxRetryCycles = binding_element.MaxRetryCycles / 2;
  96. binding_element.ReceiveRetryCount = 10;
  97. binding_element.ReceiveErrorHandling = ReceiveErrorHandling.Reject;
  98. binding_element.RetryCycleDelay = TimeSpan.FromSeconds (5);
  99. binding_element.TimeToLive = TimeSpan.FromSeconds (60);
  100. binding_element.UseMsmqTracing = !binding_element.UseMsmqTracing;
  101. binding_element.UseSourceJournal = !binding_element.UseSourceJournal;
  102. // This ones haven't been implemented yet, so comment them for now.
  103. //binding_element.ReceiveContextEnabled = !binding_element.ReceiveContextEnabled;
  104. //binding_element.ValidityDuration = TimeSpan.FromSeconds (30);
  105. binding_element.MsmqTransportSecurity.MsmqAuthenticationMode = MsmqAuthenticationMode.Certificate;
  106. binding_element.MsmqTransportSecurity.MsmqEncryptionAlgorithm = MsmqEncryptionAlgorithm.Aes;
  107. binding_element.MsmqTransportSecurity.MsmqProtectionLevel = ProtectionLevel.EncryptAndSign;
  108. binding_element.MsmqTransportSecurity.MsmqSecureHashAlgorithm = MsmqSecureHashAlgorithm.Sha256;
  109. IPolicyExportExtension export_extension = binding_element as IPolicyExportExtension;
  110. PolicyConversionContext conversion_context = new CustomPolicyConversionContext ();
  111. export_extension.ExportPolicy (new WsdlExporter (), conversion_context);
  112. PolicyAssertionCollection binding_assertions = conversion_context.GetBindingAssertions ();
  113. BindingElementCollection binding_elements = conversion_context.BindingElements;
  114. Assert.AreEqual (5, binding_assertions.Count, "#A0");
  115. Assert.AreEqual (0, binding_elements.Count, "#A1");
  116. // msmq:MsmqVolatile
  117. XmlNode volatile_node = FindAssertion (binding_assertions, "msmq:MsmqVolatile");
  118. Assert.AreEqual (true, volatile_node != null, "#B0");
  119. Assert.AreEqual ("MsmqVolatile", volatile_node.LocalName, "#B1");
  120. Assert.AreEqual ("http://schemas.microsoft.com/ws/06/2004/mspolicy/msmq", volatile_node.NamespaceURI, "#B2");
  121. Assert.AreEqual (String.Empty, volatile_node.InnerText, "#B3");
  122. Assert.AreEqual (0, volatile_node.Attributes.Count, "#B4");
  123. Assert.AreEqual (0, volatile_node.ChildNodes.Count, "#B5");
  124. // msmq:MsmqBestEffort
  125. XmlNode best_effort_node = FindAssertion (binding_assertions, "msmq:MsmqBestEffort");
  126. Assert.AreEqual (true, best_effort_node != null, "#C0");
  127. Assert.AreEqual ("MsmqBestEffort", best_effort_node.LocalName, "#C1");
  128. Assert.AreEqual ("http://schemas.microsoft.com/ws/06/2004/mspolicy/msmq", best_effort_node.NamespaceURI, "#C2");
  129. Assert.AreEqual (String.Empty, best_effort_node.InnerText, "#C3");
  130. Assert.AreEqual (0, best_effort_node.Attributes.Count, "#C4");
  131. Assert.AreEqual (0, best_effort_node.ChildNodes.Count, "#C5");
  132. // Setting MsmqTransportSecurity.MsmqAuthenticationMode to a value other than WindowsDomain
  133. // causes the removal of the WindowsDomain policy.
  134. XmlNode domain_node = FindAssertion (binding_assertions, "msmq:WindowsDomain");
  135. Assert.AreEqual (true, domain_node == null, "#D0");
  136. }
  137. XmlNode FindAssertion (PolicyAssertionCollection assertionCollection, string name)
  138. {
  139. foreach (XmlNode node in assertionCollection)
  140. if (node.Name == name)
  141. return node;
  142. return null;
  143. }
  144. }
  145. }