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