2 // EndpointBehaviorElementTest.cs
5 // Igor Zelmanovich <igorz@mainsoft.com>
7 // Copyright (C) 2008 Mainsoft, Inc. http://www.mainsoft.com
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
30 using System.Collections.Generic;
32 using NUnit.Framework;
33 using System.ServiceModel.Configuration;
34 using System.Configuration;
35 using System.ServiceModel.Description;
36 using System.Security.Cryptography.X509Certificates;
37 using System.ServiceModel.Security;
38 using System.Security.Principal;
40 namespace MonoTests.System.ServiceModel.Configuration
43 public class EndpointBehaviorElementTest
45 EndpointBehaviorElement OpenConfig () {
46 ServiceModelSectionGroup config = (ServiceModelSectionGroup) ConfigurationManager.OpenExeConfiguration ("Test/config/endpointBehaviors").GetSectionGroup ("system.serviceModel");
47 return config.Behaviors.EndpointBehaviors [0];
51 public void CallbackDebugElement () {
52 EndpointBehaviorElement behavior = OpenConfig ();
53 CallbackDebugElement callbackDebug = (CallbackDebugElement) behavior [typeof (CallbackDebugElement)];
55 if (callbackDebug == null)
56 Assert.Fail ("CallbackDebugElement is not exist in collection.");
58 Assert.AreEqual (typeof (CallbackDebugBehavior), callbackDebug.BehaviorType, "RoleProviderName");
59 Assert.AreEqual ("callbackDebug", callbackDebug.ConfigurationElementName, "RoleProviderName");
60 Assert.AreEqual (true, callbackDebug.IncludeExceptionDetailInFaults, "IncludeExceptionDetailInFaults");
64 public void CallbackDebugElement_defaults () {
65 CallbackDebugElement element = new CallbackDebugElement ();
67 Assert.AreEqual (typeof (CallbackDebugBehavior), element.BehaviorType, "element");
68 Assert.AreEqual ("callbackDebug", element.ConfigurationElementName, "ConfigurationElementName");
69 Assert.AreEqual (false, element.IncludeExceptionDetailInFaults, "IncludeExceptionDetailInFaults");
73 public void CallbackTimeoutsElement () {
74 EndpointBehaviorElement behavior = OpenConfig ();
75 CallbackTimeoutsElement element = (CallbackTimeoutsElement) behavior [typeof (CallbackTimeoutsElement)];
78 Assert.Fail ("CallbackTimeoutsElement is not exist in collection.");
80 Assert.AreEqual ("System.ServiceModel.Description.CallbackTimeoutsBehavior", element.BehaviorType.FullName, "BehaviorType");
81 Assert.AreEqual ("callbackTimeouts", element.ConfigurationElementName, "ConfigurationElementName");
82 Assert.AreEqual (new TimeSpan (0, 2, 30), element.TransactionTimeout, "TransactionTimeout");
86 public void CallbackTimeoutsElement_defaults () {
87 CallbackTimeoutsElement element = new CallbackTimeoutsElement ();
89 Assert.AreEqual ("System.ServiceModel.Description.CallbackTimeoutsBehavior", element.BehaviorType.FullName, "BehaviorType");
90 Assert.AreEqual ("callbackTimeouts", element.ConfigurationElementName, "ConfigurationElementName");
91 Assert.AreEqual (new TimeSpan (0, 0, 0), element.TransactionTimeout, "TransactionTimeout");
95 public void ClientViaElement () {
96 EndpointBehaviorElement behavior = OpenConfig ();
97 ClientViaElement element = (ClientViaElement) behavior [typeof (ClientViaElement)];
100 Assert.Fail ("ClientViaElement is not exist in collection.");
102 Assert.AreEqual (typeof (ClientViaBehavior), element.BehaviorType, "BehaviorType");
103 Assert.AreEqual ("clientVia", element.ConfigurationElementName, "ConfigurationElementName");
105 Assert.AreEqual ("http://via.uri", element.ViaUri.OriginalString, "ViaUri");
109 public void ClientViaElement_defaults () {
110 ClientViaElement element = new ClientViaElement ();
112 Assert.AreEqual (typeof (ClientViaBehavior), element.BehaviorType, "BehaviorType");
113 Assert.AreEqual ("clientVia", element.ConfigurationElementName, "ConfigurationElementName");
115 Assert.AreEqual (null, element.ViaUri, "ViaUri");
119 public void DataContractSerializerElement () {
120 EndpointBehaviorElement behavior = OpenConfig ();
121 DataContractSerializerElement element = (DataContractSerializerElement) behavior [typeof (DataContractSerializerElement)];
124 Assert.Fail ("DataContractSerializerElement is not exist in collection.");
126 Assert.AreEqual ("System.ServiceModel.Dispatcher.DataContractSerializerServiceBehavior", element.BehaviorType.FullName, "BehaviorType");
127 Assert.AreEqual ("dataContractSerializer", element.ConfigurationElementName, "ConfigurationElementName");
129 Assert.AreEqual (true, element.IgnoreExtensionDataObject, "IgnoreExtensionDataObject");
130 Assert.AreEqual (32768, element.MaxItemsInObjectGraph, "MaxItemsInObjectGraph");
134 public void DataContractSerializerElement_defaults () {
135 DataContractSerializerElement element = new DataContractSerializerElement ();
137 Assert.AreEqual ("System.ServiceModel.Dispatcher.DataContractSerializerServiceBehavior", element.BehaviorType.FullName, "BehaviorType");
138 Assert.AreEqual ("dataContractSerializer", element.ConfigurationElementName, "ConfigurationElementName");
140 Assert.AreEqual (false, element.IgnoreExtensionDataObject, "IgnoreExtensionDataObject");
141 Assert.AreEqual (65536, element.MaxItemsInObjectGraph, "MaxItemsInObjectGraph");
145 public void SynchronousReceiveElement () {
146 EndpointBehaviorElement behavior = OpenConfig ();
147 SynchronousReceiveElement element = (SynchronousReceiveElement) behavior [typeof (SynchronousReceiveElement)];
150 Assert.Fail ("SynchronousReceiveElement is not exist in collection.");
152 Assert.AreEqual (typeof (SynchronousReceiveBehavior), element.BehaviorType, "BehaviorType");
153 Assert.AreEqual ("synchronousReceive", element.ConfigurationElementName, "ConfigurationElementName");
157 public void SynchronousReceiveElement_defaults () {
158 SynchronousReceiveElement element = new SynchronousReceiveElement ();
160 Assert.AreEqual (typeof (SynchronousReceiveBehavior), element.BehaviorType, "BehaviorType");
161 Assert.AreEqual ("synchronousReceive", element.ConfigurationElementName, "ConfigurationElementName");
165 public void TransactedBatchingElement () {
166 EndpointBehaviorElement behavior = OpenConfig ();
167 TransactedBatchingElement element = (TransactedBatchingElement) behavior [typeof (TransactedBatchingElement)];
170 Assert.Fail ("TransactedBatchingElement is not exist in collection.");
172 Assert.AreEqual (typeof (TransactedBatchingBehavior), element.BehaviorType, "BehaviorType");
173 Assert.AreEqual ("transactedBatching", element.ConfigurationElementName, "ConfigurationElementName");
175 Assert.AreEqual (16, element.MaxBatchSize, "MaxBatchSize");
179 public void TransactedBatchingElement_defaults () {
180 TransactedBatchingElement element = new TransactedBatchingElement ();
182 Assert.AreEqual (typeof (TransactedBatchingBehavior), element.BehaviorType, "BehaviorType");
183 Assert.AreEqual ("transactedBatching", element.ConfigurationElementName, "ConfigurationElementName");
185 Assert.AreEqual (0, element.MaxBatchSize, "MaxBatchSize");
189 public void ClientCredentialsElement () {
190 EndpointBehaviorElement behavior = OpenConfig ();
191 ClientCredentialsElement element = (ClientCredentialsElement) behavior [typeof (ClientCredentialsElement)];
194 Assert.Fail ("ClientCredentialsElement is not exist in collection.");
196 Assert.AreEqual (typeof (ClientCredentials), element.BehaviorType, "BehaviorType");
197 Assert.AreEqual ("clientCredentials", element.ConfigurationElementName, "ConfigurationElementName");
199 Assert.AreEqual (false, element.SupportInteractive, "SupportInteractive");
200 Assert.AreEqual ("ClientCredentialType", element.Type, "Type");
202 Assert.AreEqual ("findValue", element.ClientCertificate.FindValue, "ClientCertificate.FindValue");
203 Assert.AreEqual (StoreLocation.LocalMachine, element.ClientCertificate.StoreLocation, "ClientCertificate.StoreLocation");
204 Assert.AreEqual (StoreName.Root, element.ClientCertificate.StoreName, "ClientCertificate.StoreName");
205 Assert.AreEqual (X509FindType.FindByExtension, element.ClientCertificate.X509FindType, "ClientCertificate.X509FindType");
207 Assert.AreEqual ("findValue", element.ServiceCertificate.DefaultCertificate.FindValue, "ServiceCertificate.DefaultCertificate.FindValue");
208 Assert.AreEqual (StoreLocation.LocalMachine, element.ServiceCertificate.DefaultCertificate.StoreLocation, "ServiceCertificate.DefaultCertificate.StoreLocation");
209 Assert.AreEqual (StoreName.Root, element.ServiceCertificate.DefaultCertificate.StoreName, "ServiceCertificate.DefaultCertificate.StoreName");
210 Assert.AreEqual (X509FindType.FindByExtension, element.ServiceCertificate.DefaultCertificate.X509FindType, "ServiceCertificate.DefaultCertificate.X509FindType");
212 Assert.AreEqual ("CustomCertificateValidatorType", element.ServiceCertificate.Authentication.CustomCertificateValidatorType, "ServiceCertificate.Authentication.CustomCertificateValidatorType");
213 Assert.AreEqual (X509CertificateValidationMode.None, element.ServiceCertificate.Authentication.CertificateValidationMode, "ServiceCertificate.Authentication.CertificateValidationMode");
214 Assert.AreEqual (X509RevocationMode.Offline, element.ServiceCertificate.Authentication.RevocationMode, "ServiceCertificate.Authentication.RevocationMode");
215 Assert.AreEqual (StoreLocation.LocalMachine, element.ServiceCertificate.Authentication.TrustedStoreLocation, "ServiceCertificate.Authentication.TrustedStoreLocation");
217 Assert.AreEqual (false, element.Windows.AllowNtlm, "Windows.AllowNtlm");
218 Assert.AreEqual (TokenImpersonationLevel.None, element.Windows.AllowedImpersonationLevel, "Windows.AllowedImpersonationLevel");
220 Assert.AreEqual (false, element.IssuedToken.CacheIssuedTokens, "IssuedToken.CacheIssuedTokens");
221 Assert.AreEqual (SecurityKeyEntropyMode.ClientEntropy, element.IssuedToken.DefaultKeyEntropyMode, "IssuedToken.DefaultKeyEntropyMode");
222 Assert.AreEqual (30, element.IssuedToken.IssuedTokenRenewalThresholdPercentage, "IssuedToken.IssuedTokenRenewalThresholdPercentage");
224 Assert.AreEqual (TokenImpersonationLevel.None, element.HttpDigest.ImpersonationLevel, "HttpDigest.ImpersonationLevel");
228 public void ClientCredentialsElement_defaults () {
229 ClientCredentialsElement element = new ClientCredentialsElement ();
231 Assert.AreEqual (typeof (ClientCredentials), element.BehaviorType, "BehaviorType");
232 Assert.AreEqual ("clientCredentials", element.ConfigurationElementName, "ConfigurationElementName");
234 Assert.AreEqual (true, element.SupportInteractive, "SupportInteractive");
235 Assert.AreEqual (String.Empty, element.Type, "Type");
237 Assert.AreEqual (String.Empty, element.ClientCertificate.FindValue, "ClientCertificate.FindValue");
238 Assert.AreEqual (StoreLocation.CurrentUser, element.ClientCertificate.StoreLocation, "ClientCertificate.StoreLocation");
239 Assert.AreEqual (StoreName.My, element.ClientCertificate.StoreName, "ClientCertificate.StoreName");
240 Assert.AreEqual (X509FindType.FindBySubjectDistinguishedName, element.ClientCertificate.X509FindType, "ClientCertificate.X509FindType");
242 Assert.AreEqual (String.Empty, element.ServiceCertificate.DefaultCertificate.FindValue, "ServiceCertificate.DefaultCertificate.FindValue");
243 Assert.AreEqual (StoreLocation.CurrentUser, element.ServiceCertificate.DefaultCertificate.StoreLocation, "ServiceCertificate.DefaultCertificate.StoreLocation");
244 Assert.AreEqual (StoreName.My, element.ServiceCertificate.DefaultCertificate.StoreName, "ServiceCertificate.DefaultCertificate.StoreName");
245 Assert.AreEqual (X509FindType.FindBySubjectDistinguishedName, element.ServiceCertificate.DefaultCertificate.X509FindType, "ServiceCertificate.DefaultCertificate.X509FindType");
247 Assert.AreEqual (String.Empty, element.ServiceCertificate.Authentication.CustomCertificateValidatorType, "ServiceCertificate.Authentication.CustomCertificateValidatorType");
248 Assert.AreEqual (X509CertificateValidationMode.ChainTrust, element.ServiceCertificate.Authentication.CertificateValidationMode, "ServiceCertificate.Authentication.CertificateValidationMode");
249 Assert.AreEqual (X509RevocationMode.Online, element.ServiceCertificate.Authentication.RevocationMode, "ServiceCertificate.Authentication.RevocationMode");
250 Assert.AreEqual (StoreLocation.CurrentUser, element.ServiceCertificate.Authentication.TrustedStoreLocation, "ServiceCertificate.Authentication.TrustedStoreLocation");
252 Assert.AreEqual (true, element.Windows.AllowNtlm, "Windows.AllowNtlm");
253 Assert.AreEqual (TokenImpersonationLevel.Identification, element.Windows.AllowedImpersonationLevel, "Windows.AllowedImpersonationLevel");
255 Assert.AreEqual (true, element.IssuedToken.CacheIssuedTokens, "IssuedToken.CacheIssuedTokens");
256 Assert.AreEqual (SecurityKeyEntropyMode.CombinedEntropy, element.IssuedToken.DefaultKeyEntropyMode, "IssuedToken.DefaultKeyEntropyMode");
257 Assert.AreEqual (60, element.IssuedToken.IssuedTokenRenewalThresholdPercentage, "IssuedToken.IssuedTokenRenewalThresholdPercentage");
259 Assert.AreEqual (TokenImpersonationLevel.Identification, element.HttpDigest.ImpersonationLevel, "HttpDigest.ImpersonationLevel");