1 //
2 // OperationDescriptionTest.cs
3 //
4 // Author:
5 //	Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2006 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.Collections.ObjectModel;
31 using System.ServiceModel;
32 using System.ServiceModel.Channels;
33 using System.ServiceModel.Description;
34 using System.ServiceModel.Dispatcher;
35 using NUnit.Framework;
36 
37 namespace MonoTests.System.ServiceModel.Description
38 {
39 	[TestFixture]
40 	public class OperationDescriptionTest
41 	{
42 		[Test]
Messages()43 		public void Messages ()
44 		{
45 			ContractDescription cd =
46 				ContractDescription.GetContract (typeof (IFoo));
47 			OperationDescription od = cd.Operations [0];
48 			Assert.IsNull (od.Messages.Find ("Echo"), "#1");
49 			MessageDescription md = od.Messages.Find ("http://tempuri.org/IFoo/Echo");
50 			Assert.IsNotNull (md, "#2");
51 
52 			Assert.AreEqual ("http://tempuri.org/IFoo/Echo", md.Action, "#3");
53 			Assert.AreEqual (MessageDirection.Input, md.Direction, "#4");
54 			Assert.IsFalse (md.HasProtectionLevel, "#5");
55 			Assert.IsNotNull (md.Headers, "#6");
56 			Assert.AreEqual (0, md.Headers.Count, "#7");
57 			Assert.IsNull (md.MessageType, "#8");
58 			Assert.IsNotNull (md.Properties, "#9");
59 			Assert.AreEqual (0, md.Properties.Count, "#10");
60 
61 			MessageBodyDescription mb = md.Body;
62 			Assert.IsNotNull (mb, "#11");
63 			Assert.AreEqual ("Echo", mb.WrapperName, "#12");
64 			Assert.AreEqual ("http://tempuri.org/", mb.WrapperNamespace, "#13");
65 			Assert.IsNotNull (mb.Parts, "#14");
66 			Assert.AreEqual (0, mb.Parts.Count, "#15");
67 			Assert.IsNull (mb.ReturnValue, "#16"); // void Echo()
68 		}
69 
70 		[Test]
MessagesNameSpace()71 		public void MessagesNameSpace ()
72 		{
73 			ContractDescription cd =
74 				ContractDescription.GetContract (typeof (IFoo2));
75 			OperationDescription od = cd.Operations [0];
76 			Assert.IsNull (od.Messages.Find ("Echo"), "#1");
77 			MessageDescription md = od.Messages.Find ("http://MonoTests.System.ServiceModel.Description/IFoo2/Echo");
78 			Assert.IsNotNull (md, "#2");
79 
80 			Assert.AreEqual ("http://MonoTests.System.ServiceModel.Description/IFoo2/Echo", md.Action, "#3");
81 			Assert.AreEqual (MessageDirection.Input, md.Direction, "#4");
82 			Assert.IsFalse (md.HasProtectionLevel, "#5");
83 			Assert.IsNotNull (md.Headers, "#6");
84 			Assert.AreEqual (0, md.Headers.Count, "#7");
85 			Assert.IsNull (md.MessageType, "#8");
86 			Assert.IsNotNull (md.Properties, "#9");
87 			Assert.AreEqual (0, md.Properties.Count, "#10");
88 
89 			MessageBodyDescription mb = md.Body;
90 			Assert.IsNotNull (mb, "#11");
91 			Assert.AreEqual ("Echo", mb.WrapperName, "#12");
92 			Assert.AreEqual ("http://MonoTests.System.ServiceModel.Description", mb.WrapperNamespace, "#13");
93 			Assert.IsNotNull (mb.Parts, "#14");
94 			Assert.AreEqual (0, mb.Parts.Count, "#15");
95 			Assert.IsNull (mb.ReturnValue, "#16"); // void Echo()
96 		}
97 
98 		[Test]
Parts()99 		public void Parts ()
100 		{
101 			ContractDescription cd =
102 				ContractDescription.GetContract (typeof (IFoo3));
103 
104 			MessagePartDescriptionCollection parts =
105 				cd.Operations [0].Messages [0].Body.Parts;
106 
107 			Assert.AreEqual (1, parts.Count, "#1");
108 			MessagePartDescription part = parts [0];
109 			Assert.AreEqual ("intValue", part.Name, "#2");
110 			Assert.AreEqual ("http://tempuri.org/", part.Namespace, "#3");
111 			Assert.AreEqual (typeof (int), part.Type, "#4");
112 			Assert.AreEqual (0, part.Index, "#5");
113 			Assert.AreEqual (false, part.Multiple, "#5");
114 		}
115 
116 		[Test]
PartsNamespace()117 		public void PartsNamespace ()
118 		{
119 			ContractDescription cd =
120 				ContractDescription.GetContract (typeof (IFoo4));
121 
122 			MessagePartDescriptionCollection parts =
123 				cd.Operations [0].Messages [0].Body.Parts;
124 
125 			Assert.AreEqual (1, parts.Count, "#1");
126 			MessagePartDescription part = parts [0];
127 			Assert.AreEqual ("intValue", part.Name, "#2");
128 			Assert.AreEqual ("http://MonoTests.System.ServiceModel.Description", part.Namespace, "#3");
129 			Assert.AreEqual (typeof (int), part.Type, "#4");
130 			Assert.AreEqual (0, part.Index, "#5");
131 			Assert.AreEqual (false, part.Multiple, "#5");
132 		}
133 
134 		[ServiceContract]
135 		public interface IFoo
136 		{
137 			[OperationContract]
Echo()138 			void Echo ();
139 		}
140 
141 		[ServiceContract(Namespace="http://MonoTests.System.ServiceModel.Description")]
142 		public interface IFoo2
143 		{
144 			[OperationContract]
Echo()145 			void Echo ();
146 		}
147 
148 		[ServiceContract]
149 		public interface IFoo3
150 		{
151 			[OperationContract]
Echo(int intValue)152 			int Echo (int intValue);
153 		}
154 
155 		[ServiceContract (Namespace = "http://MonoTests.System.ServiceModel.Description")]
156 		public interface IFoo4
157 		{
158 			[OperationContract]
Echo(int intValue)159 			int Echo (int intValue);
160 		}
161 	}
162 }
163