2 // TextMessageEncodingBindingElementTest.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2005 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.
29 using System.Collections.ObjectModel;
31 using System.ServiceModel;
32 using System.ServiceModel.Channels;
33 using System.ServiceModel.Description;
36 using NUnit.Framework;
38 using Element = System.ServiceModel.Channels.TextMessageEncodingBindingElement;
40 namespace MonoTests.System.ServiceModel.Channels
43 public class TextMessageEncodingBindingElementTest
46 public void DefaultValues ()
48 Element el = new Element ();
49 Assert.AreEqual (64, el.MaxReadPoolSize, "#1");
50 Assert.AreEqual (16, el.MaxWritePoolSize, "#2");
51 Assert.AreEqual (MessageVersion.Default, el.MessageVersion, "#3");
52 // FIXME: test ReaderQuotas
54 Assert.AreEqual (Encoding.UTF8, el.WriteEncoding, "#4");
58 [ExpectedException (typeof (ArgumentNullException))]
59 public void BuildChannelListenerNullArg ()
61 new Element ().BuildChannelListener<IReplyChannel> (null);
65 public void CanBuildChannelFactory ()
67 CustomBinding cb = new CustomBinding (
68 new HttpTransportBindingElement ());
69 BindingContext ctx = new BindingContext (
70 cb, new BindingParameterCollection ());
71 Element el = new Element ();
72 Assert.IsTrue (el.CanBuildChannelFactory<IRequestChannel> (ctx), "#1");
73 Assert.IsFalse (el.CanBuildChannelFactory<IRequestSessionChannel> (ctx), "#2");
77 public void BuildChannelFactory ()
79 CustomBinding cb = new CustomBinding (
80 new HttpTransportBindingElement ());
81 BindingContext ctx = new BindingContext (
82 cb, new BindingParameterCollection ());
83 Element el = new Element ();
84 IChannelFactory<IRequestChannel> cf =
85 el.BuildChannelFactory<IRequestChannel> (ctx);
89 [ExpectedException (typeof (InvalidOperationException))]
90 public void BuildChannelListenerEmptyCustomBinding ()
92 CustomBinding cb = new CustomBinding ();
93 BindingContext ctx = new BindingContext (
94 cb, new BindingParameterCollection ());
95 new Element ().BuildChannelListener<IReplyChannel> (ctx);
99 public void BuildChannelListenerWithTransport ()
101 CustomBinding cb = new CustomBinding (
102 new HttpTransportBindingElement ());
103 BindingContext ctx = new BindingContext (
104 cb, new BindingParameterCollection (),
105 new Uri ("http://localhost:8080"), String.Empty, ListenUriMode.Unique);
106 new Element ().BuildChannelListener<IReplyChannel> (ctx);
110 public void MessageEncoderIsContentTypeSupported ()
112 var enc = new TextMessageEncodingBindingElement ().CreateMessageEncoderFactory ().Encoder;
113 Assert.IsFalse (enc.IsContentTypeSupported ("application/xml"), "#1");
114 Assert.IsFalse (enc.IsContentTypeSupported ("text/xml"), "#2");
115 Assert.IsTrue (enc.IsContentTypeSupported ("application/soap+xml"), "#3");
119 [ExpectedException (typeof (ArgumentNullException))]
120 public void ReadNullStream ()
122 var enc = new TextMessageEncodingBindingElement ().CreateMessageEncoderFactory ().Encoder;
123 enc.ReadMessage (null, 10, "text/xml");
127 [ExpectedException (typeof (ArgumentNullException))]
128 public void ReadNullBufferManager ()
130 var enc = new TextMessageEncodingBindingElement ().CreateMessageEncoderFactory ().Encoder;
131 enc.ReadMessage (new ArraySegment<byte> (new byte [0]), null, "text/xml");
135 [ExpectedException (typeof (XmlException))] // (document is expected)
136 public void ReadEmptyBuffer ()
138 var enc = new TextMessageEncodingBindingElement ().CreateMessageEncoderFactory ().Encoder;
139 enc.ReadMessage (new ArraySegment<byte> (new byte [0]), BufferManager.CreateBufferManager (1000, 1000), "text/xml");
143 public void ActionContentTypeParameter ()
145 var enc = new TextMessageEncodingBindingElement ().CreateMessageEncoderFactory ().Encoder;
146 var msg = Message.CreateMessage (MessageVersion.Soap12, "urn:foo");
147 var ms = new MemoryStream ();
148 using (var xw = XmlWriter.Create (ms))
149 msg.WriteMessage (xw);
151 msg = enc.ReadMessage (ms, 0x1000, "application/soap+xml; action=urn:bar");
152 Assert.AreEqual ("urn:bar", msg.Headers.Action, "#1");