EndpointBehaviorElementTest.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. //
  2. // EndpointBehaviorElementTest.cs
  3. //
  4. // Author:
  5. // Igor Zelmanovich <[email protected]>
  6. //
  7. // Copyright (C) 2008 Mainsoft, Inc. http://www.mainsoft.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.Text;
  31. using NUnit.Framework;
  32. using System.ServiceModel.Configuration;
  33. using System.Configuration;
  34. using System.ServiceModel.Description;
  35. using System.Security.Cryptography.X509Certificates;
  36. using System.ServiceModel.Security;
  37. using System.Security.Principal;
  38. namespace MonoTests.System.ServiceModel.Configuration
  39. {
  40. [TestFixture]
  41. public class EndpointBehaviorElementTest
  42. {
  43. EndpointBehaviorElement OpenConfig () {
  44. ServiceModelSectionGroup config = (ServiceModelSectionGroup) ConfigurationManager.OpenExeConfiguration ("Test/config/endpointBehaviors").GetSectionGroup ("system.serviceModel");
  45. return config.Behaviors.EndpointBehaviors [0];
  46. }
  47. [Test]
  48. public void CallbackDebugElement () {
  49. EndpointBehaviorElement behavior = OpenConfig ();
  50. CallbackDebugElement callbackDebug = (CallbackDebugElement) behavior [typeof (CallbackDebugElement)];
  51. if (callbackDebug == null)
  52. Assert.Fail ("CallbackDebugElement is not exist in collection.");
  53. Assert.AreEqual (typeof (CallbackDebugBehavior), callbackDebug.BehaviorType, "RoleProviderName");
  54. Assert.AreEqual ("callbackDebug", callbackDebug.ConfigurationElementName, "RoleProviderName");
  55. Assert.AreEqual (true, callbackDebug.IncludeExceptionDetailInFaults, "IncludeExceptionDetailInFaults");
  56. }
  57. [Test]
  58. public void CallbackDebugElement_defaults () {
  59. CallbackDebugElement element = new CallbackDebugElement ();
  60. Assert.AreEqual (typeof (CallbackDebugBehavior), element.BehaviorType, "element");
  61. Assert.AreEqual ("callbackDebug", element.ConfigurationElementName, "ConfigurationElementName");
  62. Assert.AreEqual (false, element.IncludeExceptionDetailInFaults, "IncludeExceptionDetailInFaults");
  63. }
  64. [Test]
  65. public void CallbackTimeoutsElement () {
  66. EndpointBehaviorElement behavior = OpenConfig ();
  67. CallbackTimeoutsElement element = (CallbackTimeoutsElement) behavior [typeof (CallbackTimeoutsElement)];
  68. if (element == null)
  69. Assert.Fail ("CallbackTimeoutsElement is not exist in collection.");
  70. Assert.AreEqual ("System.ServiceModel.Description.CallbackTimeoutsBehavior", element.BehaviorType.FullName, "BehaviorType");
  71. Assert.AreEqual ("callbackTimeouts", element.ConfigurationElementName, "ConfigurationElementName");
  72. Assert.AreEqual (new TimeSpan (0, 2, 30), element.TransactionTimeout, "TransactionTimeout");
  73. }
  74. [Test]
  75. public void CallbackTimeoutsElement_defaults () {
  76. CallbackTimeoutsElement element = new CallbackTimeoutsElement ();
  77. Assert.AreEqual ("System.ServiceModel.Description.CallbackTimeoutsBehavior", element.BehaviorType.FullName, "BehaviorType");
  78. Assert.AreEqual ("callbackTimeouts", element.ConfigurationElementName, "ConfigurationElementName");
  79. Assert.AreEqual (new TimeSpan (0, 0, 0), element.TransactionTimeout, "TransactionTimeout");
  80. }
  81. [Test]
  82. public void ClientViaElement () {
  83. EndpointBehaviorElement behavior = OpenConfig ();
  84. ClientViaElement element = (ClientViaElement) behavior [typeof (ClientViaElement)];
  85. if (element == null)
  86. Assert.Fail ("ClientViaElement is not exist in collection.");
  87. Assert.AreEqual (typeof (ClientViaBehavior), element.BehaviorType, "BehaviorType");
  88. Assert.AreEqual ("clientVia", element.ConfigurationElementName, "ConfigurationElementName");
  89. Assert.AreEqual ("http://via.uri", element.ViaUri.OriginalString, "ViaUri");
  90. }
  91. [Test]
  92. public void ClientViaElement_defaults () {
  93. ClientViaElement element = new ClientViaElement ();
  94. Assert.AreEqual (typeof (ClientViaBehavior), element.BehaviorType, "BehaviorType");
  95. Assert.AreEqual ("clientVia", element.ConfigurationElementName, "ConfigurationElementName");
  96. Assert.AreEqual (null, element.ViaUri, "ViaUri");
  97. }
  98. [Test]
  99. public void DataContractSerializerElement () {
  100. EndpointBehaviorElement behavior = OpenConfig ();
  101. DataContractSerializerElement element = (DataContractSerializerElement) behavior [typeof (DataContractSerializerElement)];
  102. if (element == null)
  103. Assert.Fail ("DataContractSerializerElement is not exist in collection.");
  104. Assert.AreEqual ("System.ServiceModel.Dispatcher.DataContractSerializerServiceBehavior", element.BehaviorType.FullName, "BehaviorType");
  105. Assert.AreEqual ("dataContractSerializer", element.ConfigurationElementName, "ConfigurationElementName");
  106. Assert.AreEqual (true, element.IgnoreExtensionDataObject, "IgnoreExtensionDataObject");
  107. Assert.AreEqual (32768, element.MaxItemsInObjectGraph, "MaxItemsInObjectGraph");
  108. }
  109. [Test]
  110. public void DataContractSerializerElement_defaults () {
  111. DataContractSerializerElement element = new DataContractSerializerElement ();
  112. Assert.AreEqual ("System.ServiceModel.Dispatcher.DataContractSerializerServiceBehavior", element.BehaviorType.FullName, "BehaviorType");
  113. Assert.AreEqual ("dataContractSerializer", element.ConfigurationElementName, "ConfigurationElementName");
  114. Assert.AreEqual (false, element.IgnoreExtensionDataObject, "IgnoreExtensionDataObject");
  115. Assert.AreEqual (65536, element.MaxItemsInObjectGraph, "MaxItemsInObjectGraph");
  116. }
  117. [Test]
  118. public void SynchronousReceiveElement () {
  119. EndpointBehaviorElement behavior = OpenConfig ();
  120. SynchronousReceiveElement element = (SynchronousReceiveElement) behavior [typeof (SynchronousReceiveElement)];
  121. if (element == null)
  122. Assert.Fail ("SynchronousReceiveElement is not exist in collection.");
  123. Assert.AreEqual (typeof (SynchronousReceiveBehavior), element.BehaviorType, "BehaviorType");
  124. Assert.AreEqual ("synchronousReceive", element.ConfigurationElementName, "ConfigurationElementName");
  125. }
  126. [Test]
  127. public void SynchronousReceiveElement_defaults () {
  128. SynchronousReceiveElement element = new SynchronousReceiveElement ();
  129. Assert.AreEqual (typeof (SynchronousReceiveBehavior), element.BehaviorType, "BehaviorType");
  130. Assert.AreEqual ("synchronousReceive", element.ConfigurationElementName, "ConfigurationElementName");
  131. }
  132. [Test]
  133. public void TransactedBatchingElement () {
  134. EndpointBehaviorElement behavior = OpenConfig ();
  135. TransactedBatchingElement element = (TransactedBatchingElement) behavior [typeof (TransactedBatchingElement)];
  136. if (element == null)
  137. Assert.Fail ("TransactedBatchingElement is not exist in collection.");
  138. Assert.AreEqual (typeof (TransactedBatchingBehavior), element.BehaviorType, "BehaviorType");
  139. Assert.AreEqual ("transactedBatching", element.ConfigurationElementName, "ConfigurationElementName");
  140. Assert.AreEqual (16, element.MaxBatchSize, "MaxBatchSize");
  141. }
  142. [Test]
  143. public void TransactedBatchingElement_defaults () {
  144. TransactedBatchingElement element = new TransactedBatchingElement ();
  145. Assert.AreEqual (typeof (TransactedBatchingBehavior), element.BehaviorType, "BehaviorType");
  146. Assert.AreEqual ("transactedBatching", element.ConfigurationElementName, "ConfigurationElementName");
  147. Assert.AreEqual (0, element.MaxBatchSize, "MaxBatchSize");
  148. }
  149. [Test]
  150. public void ClientCredentialsElement () {
  151. EndpointBehaviorElement behavior = OpenConfig ();
  152. ClientCredentialsElement element = (ClientCredentialsElement) behavior [typeof (ClientCredentialsElement)];
  153. if (element == null)
  154. Assert.Fail ("ClientCredentialsElement is not exist in collection.");
  155. Assert.AreEqual (typeof (ClientCredentials), element.BehaviorType, "BehaviorType");
  156. Assert.AreEqual ("clientCredentials", element.ConfigurationElementName, "ConfigurationElementName");
  157. Assert.AreEqual (false, element.SupportInteractive, "SupportInteractive");
  158. Assert.AreEqual ("ClientCredentialType", element.Type, "Type");
  159. Assert.AreEqual ("findValue", element.ClientCertificate.FindValue, "ClientCertificate.FindValue");
  160. Assert.AreEqual (StoreLocation.LocalMachine, element.ClientCertificate.StoreLocation, "ClientCertificate.StoreLocation");
  161. Assert.AreEqual (StoreName.Root, element.ClientCertificate.StoreName, "ClientCertificate.StoreName");
  162. Assert.AreEqual (X509FindType.FindByExtension, element.ClientCertificate.X509FindType, "ClientCertificate.X509FindType");
  163. Assert.AreEqual ("findValue", element.ServiceCertificate.DefaultCertificate.FindValue, "ServiceCertificate.DefaultCertificate.FindValue");
  164. Assert.AreEqual (StoreLocation.LocalMachine, element.ServiceCertificate.DefaultCertificate.StoreLocation, "ServiceCertificate.DefaultCertificate.StoreLocation");
  165. Assert.AreEqual (StoreName.Root, element.ServiceCertificate.DefaultCertificate.StoreName, "ServiceCertificate.DefaultCertificate.StoreName");
  166. Assert.AreEqual (X509FindType.FindByExtension, element.ServiceCertificate.DefaultCertificate.X509FindType, "ServiceCertificate.DefaultCertificate.X509FindType");
  167. Assert.AreEqual ("CustomCertificateValidatorType", element.ServiceCertificate.Authentication.CustomCertificateValidatorType, "ServiceCertificate.Authentication.CustomCertificateValidatorType");
  168. Assert.AreEqual (X509CertificateValidationMode.None, element.ServiceCertificate.Authentication.CertificateValidationMode, "ServiceCertificate.Authentication.CertificateValidationMode");
  169. Assert.AreEqual (X509RevocationMode.Offline, element.ServiceCertificate.Authentication.RevocationMode, "ServiceCertificate.Authentication.RevocationMode");
  170. Assert.AreEqual (StoreLocation.LocalMachine, element.ServiceCertificate.Authentication.TrustedStoreLocation, "ServiceCertificate.Authentication.TrustedStoreLocation");
  171. Assert.AreEqual (false, element.Windows.AllowNtlm, "Windows.AllowNtlm");
  172. Assert.AreEqual (TokenImpersonationLevel.None, element.Windows.AllowedImpersonationLevel, "Windows.AllowedImpersonationLevel");
  173. Assert.AreEqual (false, element.IssuedToken.CacheIssuedTokens, "IssuedToken.CacheIssuedTokens");
  174. Assert.AreEqual (SecurityKeyEntropyMode.ClientEntropy, element.IssuedToken.DefaultKeyEntropyMode, "IssuedToken.DefaultKeyEntropyMode");
  175. Assert.AreEqual (30, element.IssuedToken.IssuedTokenRenewalThresholdPercentage, "IssuedToken.IssuedTokenRenewalThresholdPercentage");
  176. Assert.AreEqual (TokenImpersonationLevel.None, element.HttpDigest.ImpersonationLevel, "HttpDigest.ImpersonationLevel");
  177. }
  178. [Test]
  179. public void ClientCredentialsElement_defaults () {
  180. ClientCredentialsElement element = new ClientCredentialsElement ();
  181. Assert.AreEqual (typeof (ClientCredentials), element.BehaviorType, "BehaviorType");
  182. Assert.AreEqual ("clientCredentials", element.ConfigurationElementName, "ConfigurationElementName");
  183. Assert.AreEqual (true, element.SupportInteractive, "SupportInteractive");
  184. Assert.AreEqual (String.Empty, element.Type, "Type");
  185. Assert.AreEqual (String.Empty, element.ClientCertificate.FindValue, "ClientCertificate.FindValue");
  186. Assert.AreEqual (StoreLocation.CurrentUser, element.ClientCertificate.StoreLocation, "ClientCertificate.StoreLocation");
  187. Assert.AreEqual (StoreName.My, element.ClientCertificate.StoreName, "ClientCertificate.StoreName");
  188. Assert.AreEqual (X509FindType.FindBySubjectDistinguishedName, element.ClientCertificate.X509FindType, "ClientCertificate.X509FindType");
  189. Assert.AreEqual (String.Empty, element.ServiceCertificate.DefaultCertificate.FindValue, "ServiceCertificate.DefaultCertificate.FindValue");
  190. Assert.AreEqual (StoreLocation.CurrentUser, element.ServiceCertificate.DefaultCertificate.StoreLocation, "ServiceCertificate.DefaultCertificate.StoreLocation");
  191. Assert.AreEqual (StoreName.My, element.ServiceCertificate.DefaultCertificate.StoreName, "ServiceCertificate.DefaultCertificate.StoreName");
  192. Assert.AreEqual (X509FindType.FindBySubjectDistinguishedName, element.ServiceCertificate.DefaultCertificate.X509FindType, "ServiceCertificate.DefaultCertificate.X509FindType");
  193. Assert.AreEqual (String.Empty, element.ServiceCertificate.Authentication.CustomCertificateValidatorType, "ServiceCertificate.Authentication.CustomCertificateValidatorType");
  194. Assert.AreEqual (X509CertificateValidationMode.ChainTrust, element.ServiceCertificate.Authentication.CertificateValidationMode, "ServiceCertificate.Authentication.CertificateValidationMode");
  195. Assert.AreEqual (X509RevocationMode.Online, element.ServiceCertificate.Authentication.RevocationMode, "ServiceCertificate.Authentication.RevocationMode");
  196. Assert.AreEqual (StoreLocation.CurrentUser, element.ServiceCertificate.Authentication.TrustedStoreLocation, "ServiceCertificate.Authentication.TrustedStoreLocation");
  197. Assert.AreEqual (true, element.Windows.AllowNtlm, "Windows.AllowNtlm");
  198. Assert.AreEqual (TokenImpersonationLevel.Identification, element.Windows.AllowedImpersonationLevel, "Windows.AllowedImpersonationLevel");
  199. Assert.AreEqual (true, element.IssuedToken.CacheIssuedTokens, "IssuedToken.CacheIssuedTokens");
  200. Assert.AreEqual (SecurityKeyEntropyMode.CombinedEntropy, element.IssuedToken.DefaultKeyEntropyMode, "IssuedToken.DefaultKeyEntropyMode");
  201. Assert.AreEqual (60, element.IssuedToken.IssuedTokenRenewalThresholdPercentage, "IssuedToken.IssuedTokenRenewalThresholdPercentage");
  202. Assert.AreEqual (TokenImpersonationLevel.Identification, element.HttpDigest.ImpersonationLevel, "HttpDigest.ImpersonationLevel");
  203. }
  204. }
  205. }