2 // ConnectionOrientedTransportBindingElementTest.cs
5 // Carlos Alberto Cortez <calberto.cortez@gmail.com>
7 // Copyright (C) 2010 Novell, Inc. http://www.novell.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.ServiceModel;
31 using System.ServiceModel.Channels;
32 using System.ServiceModel.Description;
34 using NUnit.Framework;
36 namespace MonoTests.System.ServiceModel.Channels
39 public class ConnectionOrientedTransportBindingElementTest
42 // We use NamedPipeTransportBindingElement to access the impl of ExportPolicy
45 public void ExportPolicyDefault ()
47 ConnectionOrientedTransportBindingElement binding_element = new NamedPipeTransportBindingElement ();
48 IPolicyExportExtension export_extension = binding_element as IPolicyExportExtension;
49 PolicyConversionContext conversion_context = new CustomPolicyConversionContext ();
50 export_extension.ExportPolicy (new WsdlExporter (), conversion_context);
52 PolicyAssertionCollection binding_assertions = conversion_context.GetBindingAssertions ();
53 BindingElementCollection binding_elements = conversion_context.BindingElements;
54 Assert.AreEqual (2, binding_assertions.Count, "#A0");
55 Assert.AreEqual (0, binding_elements.Count, "#A1");
57 // wsaw:UsingAddressing
58 XmlNode using_addressing_node = FindAssertion (binding_assertions, "wsaw:UsingAddressing");
59 Assert.AreEqual (true, using_addressing_node != null, "#B0");
60 Assert.AreEqual ("UsingAddressing", using_addressing_node.LocalName, "#B1");
61 Assert.AreEqual ("http://www.w3.org/2006/05/addressing/wsdl", using_addressing_node.NamespaceURI, "#B2");
62 Assert.AreEqual (String.Empty, using_addressing_node.InnerText, "#B3");
63 Assert.AreEqual (0, using_addressing_node.Attributes.Count, "#B4");
64 Assert.AreEqual (0, using_addressing_node.ChildNodes.Count, "#B5");
67 XmlNode binary_encoding_node = FindAssertion (binding_assertions, "msb:BinaryEncoding");
68 Assert.AreEqual (true, binary_encoding_node != null, "#C0");
69 Assert.AreEqual ("BinaryEncoding", binary_encoding_node.LocalName, "#C1");
70 Assert.AreEqual ("http://schemas.microsoft.com/ws/06/2004/mspolicy/netbinary1", binary_encoding_node.NamespaceURI, "#C2");
71 Assert.AreEqual (String.Empty, binary_encoding_node.InnerText, "#C3");
72 Assert.AreEqual (0, binary_encoding_node.Attributes.Count, "#C4");
73 Assert.AreEqual (0, binary_encoding_node.ChildNodes.Count, "#C5");
80 public void ExportPolicy ()
82 ConnectionOrientedTransportBindingElement binding_element = new NamedPipeTransportBindingElement ();
83 binding_element.ChannelInitializationTimeout = TimeSpan.FromSeconds (3);
84 binding_element.ConnectionBufferSize = binding_element.ConnectionBufferSize / 2;
85 binding_element.HostNameComparisonMode = HostNameComparisonMode.WeakWildcard;
86 binding_element.ManualAddressing = !binding_element.ManualAddressing;
87 binding_element.MaxBufferSize = binding_element.MaxBufferSize / 2;
88 binding_element.MaxBufferPoolSize = binding_element.MaxBufferPoolSize / 2;
89 binding_element.MaxOutputDelay = TimeSpan.FromSeconds (3);
90 binding_element.MaxPendingAccepts = 3;
91 binding_element.MaxPendingConnections = 15;
92 binding_element.MaxReceivedMessageSize = binding_element.MaxReceivedMessageSize / 2;
93 binding_element.TransferMode = TransferMode.Streamed; // Causes an assertion with Streamed* values
95 IPolicyExportExtension export_extension = binding_element as IPolicyExportExtension;
96 PolicyConversionContext conversion_context = new CustomPolicyConversionContext ();
97 export_extension.ExportPolicy (new WsdlExporter (), conversion_context);
99 PolicyAssertionCollection binding_assertions = conversion_context.GetBindingAssertions ();
100 BindingElementCollection binding_elements = conversion_context.BindingElements;
101 Assert.AreEqual (3, binding_assertions.Count, "#A0");
102 Assert.AreEqual (0, binding_elements.Count, "#A1");
105 XmlNode streamed_node = FindAssertion (binding_assertions, "msf:Streamed");
106 Assert.AreEqual (true, streamed_node != null, "#B0");
107 Assert.AreEqual ("Streamed", streamed_node.LocalName, "#B1");
108 Assert.AreEqual ("http://schemas.microsoft.com/ws/2006/05/framing/policy", streamed_node.NamespaceURI, "#B2");
109 Assert.AreEqual (String.Empty, streamed_node.InnerText, "#B3");
110 Assert.AreEqual (0, streamed_node.Attributes.Count, "#B4");
111 Assert.AreEqual (0, streamed_node.ChildNodes.Count, "#B5");
114 // For some reason PolicyAssertionCollection.Find is not working as expected,
115 // so do the lookup manually.
116 XmlNode FindAssertion (PolicyAssertionCollection assertionCollection, string name)
118 foreach (XmlNode node in assertionCollection)
119 if (node.Name == name)