2 // MessageEncoderTest.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2006 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;
35 using NUnit.Framework;
37 using TextElement = System.ServiceModel.Channels.TextMessageEncodingBindingElement;
38 using BinaryElement = System.ServiceModel.Channels.BinaryMessageEncodingBindingElement;
39 using MtomElement = System.ServiceModel.Channels.MtomMessageEncodingBindingElement;
41 namespace MonoTests.System.ServiceModel.Channels
44 public class MessageEncoderTest
46 class MyEncodingBindingElement : MessageEncodingBindingElement
48 public override BindingElement Clone ()
50 throw new Exception ();
53 public override T GetProperty<T> (BindingContext ctx)
55 throw new Exception ();
58 public override MessageEncoderFactory CreateMessageEncoderFactory ()
60 throw new Exception ();
63 public override MessageVersion MessageVersion {
64 get { throw new Exception (); }
65 set { throw new Exception (); }
70 public void Properties ()
72 MessageEncoder t = new TextElement ().CreateMessageEncoderFactory ().Encoder;
73 MessageEncoder b = new BinaryElement ().CreateMessageEncoderFactory ().Encoder;
74 MessageEncoder m = new MtomElement ().CreateMessageEncoderFactory ().Encoder;
76 // TextMessageEncodingBindingElement.WriteEncoding
77 // default value is UTF8.
78 ServiceAssert.AssertMessageEncoder (
79 // Those curly double quotations are smelly, very implementation specific.
80 "application/soap+xml; charset=utf-8", "application/soap+xml",
81 MessageVersion.Default, t, "Text");
82 ServiceAssert.AssertMessageEncoder (
83 "application/soap+msbin1", "application/soap+msbin1",
84 MessageVersion.Default, b, "Binary");
85 ServiceAssert.AssertMessageEncoder (
86 "multipart/related; type=\"application/xop+xml\"", "multipart/related",
87 MessageVersion.Default, m, "Mtom");
89 MessageEncoder t2 = new TextElement (
90 MessageVersion.Soap11WSAddressing10,
92 .CreateMessageEncoderFactory ().Encoder;
94 ServiceAssert.AssertMessageEncoder (
95 // Those curly double quotations are smelly, very implementation specific.
96 "text/xml; charset=utf-8", "text/xml",
97 MessageVersion.Soap11WSAddressing10, t2, "Text2");
101 [ExpectedException (typeof (ProtocolException))]
102 public void MessageVersionMismatch ()
104 Message msg = Message.CreateMessage (
105 // ... while BasicHttpBinding expects Soap11.
106 MessageVersion.Soap11WSAddressing10,
107 "http://tempuri.org/IFoo/Echo", "TEST");
108 MessageEncoderFactory f = new TextMessageEncodingBindingElement (MessageVersion.Soap11, Encoding.UTF8).CreateMessageEncoderFactory ();
109 f.Encoder.WriteMessage (msg, new MemoryStream ());
113 public void CreateSessionEncoder ()
115 Assert.AreEqual ("application/soap+xml", new TextMessageEncodingBindingElement ().CreateMessageEncoderFactory ().CreateSessionEncoder ().MediaType, "#1");
116 Assert.AreEqual ("application/soap+msbinsession1", new BinaryMessageEncodingBindingElement ().CreateMessageEncoderFactory ().CreateSessionEncoder ().MediaType, "#2"); // different from application/soap+msbin1
117 Assert.AreEqual ("multipart/related", new MtomMessageEncodingBindingElement ().CreateMessageEncoderFactory ().CreateSessionEncoder ().MediaType, "#3");