Merged into single file, added assertions
[mono.git] / mcs / class / System.ServiceModel / Test / System.ServiceModel.Channels / ConnectionOrientedTransportBindingElementTest.cs
1 //
2 // ConnectionOrientedTransportBindingElementTest.cs
3 //
4 // Author:
5 //      Carlos Alberto Cortez <calberto.cortez@gmail.com>
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
29 using System;
30 using System.ServiceModel;
31 using System.ServiceModel.Channels;
32 using System.ServiceModel.Description;
33 using System.Xml;
34 using NUnit.Framework;
35
36 namespace MonoTests.System.ServiceModel.Channels
37 {
38         [TestFixture]
39         public class ConnectionOrientedTransportBindingElementTest
40         {
41                 //
42                 // We use NamedPipeTransportBindingElement to access the impl of ExportPolicy
43                 //
44                 [Test]
45                 public void ExportPolicyDefault ()
46                 {
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);
51
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");
56
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");
65
66                         // msb:BinaryEncoding
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");
74                 }
75
76                 // 
77                 // Non-default values
78                 //
79                 [Test]
80                 public void ExportPolicy ()
81                 {
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
94
95                         IPolicyExportExtension export_extension = binding_element as IPolicyExportExtension;
96                         PolicyConversionContext conversion_context = new CustomPolicyConversionContext ();
97                         export_extension.ExportPolicy (new WsdlExporter (), conversion_context);
98
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");
103
104                         // msf:Streamed
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");
112                 }
113
114                 // For some reason PolicyAssertionCollection.Find is not working as expected,
115                 // so do the lookup manually.
116                 XmlNode FindAssertion (PolicyAssertionCollection assertionCollection, string name)
117                 {
118                         foreach (XmlNode node in assertionCollection)
119                                 if (node.Name == name)
120                                         return node;
121
122                         return null;
123                 }
124         }
125 }
126