| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013 |
- //
- // ContractDescriptionTest.cs
- //
- // Author:
- // Atsushi Enomoto <[email protected]>
- //
- // Copyright (C) 2005 Novell, Inc. http://www.novell.com
- // Copyright (C) 2011 Xamarin, Inc. http://xamarin.com
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- using System;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Net.Security;
- using System.Reflection;
- using System.ServiceModel;
- using System.ServiceModel.Channels;
- using System.ServiceModel.Description;
- using System.ServiceModel.Dispatcher;
- using NUnit.Framework;
- namespace MonoTests.System.ServiceModel.Description
- {
- [TestFixture]
- public class ContractDescriptionTest
- {
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- public void GetNonContract ()
- {
- ContractDescription cd = ContractDescription.GetContract (
- typeof (object));
- }
- [Test]
- public void GetContract ()
- {
- InternalTestGetContract (
- ContractDescription.GetContract (typeof (IFoo)));
- }
- [Test]
- public void GetContractParamRenamed ()
- {
- ContractDescription cd = ContractDescription.GetContract (typeof (IFooMsgParams));
- Assert.AreEqual (1, cd.Operations.Count, "Operation count");
- // Operation #1
- OperationDescription od = cd.Operations [0];
- ServiceAssert.AssertOperationDescription (
- "MyFoo", null, null,
- typeof (IFooMsgParams).GetMethod ("Foo"),
- true, false, false,
- od, "MyFoo");
- // Operation #1 -> Message #1
- MessageDescription md = od.Messages [0];
- ServiceAssert.AssertMessageAndBodyDescription (
- "http://tempuri.org/IFooMsgParams/MyFoo",
- MessageDirection.Input,
- null, "MyFoo", "http://tempuri.org/", false,
- md, "MyFoo");
- ServiceAssert.AssertMessagePartDescription (
- "MyParam", "http://tempuri.org/", 0, false,
- ProtectionLevel.None, typeof (string), md.Body.Parts [0], "MyFoo.msg");
- md = od.Messages [1];
- ServiceAssert.AssertMessageAndBodyDescription (
- "http://tempuri.org/IFooMsgParams/MyFooResponse",
- MessageDirection.Output,
- null, "MyFooResponse",
- "http://tempuri.org/", true,
- md, "MyFoo");
- ServiceAssert.AssertMessagePartDescription (
- "MyResult", "http://tempuri.org/", 0, false,
- ProtectionLevel.None, typeof (string), md.Body.ReturnValue, "MyResult ReturnValue");
- }
- [Test]
- public void GetContractConfigName ()
- {
- ContractDescription cd = ContractDescription.GetContract (typeof (ICtorUseCase2));
- Assert.AreEqual("CtorUseCase2", cd.ConfigurationName);
- Assert.AreEqual("ICtorUseCase2", cd.Name);
- cd = ContractDescription.GetContract (typeof (ICtorUseCase1));
- Assert.AreEqual("MonoTests.System.ServiceModel.ICtorUseCase1", cd.ConfigurationName);
- Assert.AreEqual("ICtorUseCase1", cd.Name);
- }
- [Test]
- public void GetContract2 ()
- {
- InternalTestGetContract (
- ContractDescription.GetContract (typeof (Foo)));
- }
- public void InternalTestGetContract (ContractDescription cd)
- {
- ServiceAssert.AssertContractDescription (
- "IFoo", "http://tempuri.org/", SessionMode.Allowed, typeof (IFoo), null,
- cd, "contract");
- Assert.AreEqual (2, cd.Operations.Count, "Operation count");
- // Operation #1
- OperationDescription od = cd.Operations [0];
- ServiceAssert.AssertOperationDescription (
- "HeyDude", null, null,
- typeof (IFoo).GetMethod ("HeyDude"),
- true, false, false,
- od, "HeyDude");
- // Operation #1 -> Message #1
- MessageDescription md = od.Messages [0];
- ServiceAssert.AssertMessageAndBodyDescription (
- "http://tempuri.org/IFoo/HeyDude",
- MessageDirection.Input,
- null, "HeyDude", "http://tempuri.org/", false,
- md, "HeyDude");
- ServiceAssert.AssertMessagePartDescription (
- "msg", "http://tempuri.org/", 0, false,
- ProtectionLevel.None, typeof (string), md.Body.Parts [0], "HeyDude.msg");
- ServiceAssert.AssertMessagePartDescription (
- "msg2", "http://tempuri.org/", 1, false,
- ProtectionLevel.None, typeof (string), md.Body.Parts [1], "HeyDude.msg");
- // Operation #1 -> Message #2
- md = od.Messages [1];
- ServiceAssert.AssertMessageAndBodyDescription (
- "http://tempuri.org/IFoo/HeyDudeResponse",
- MessageDirection.Output,
- null, "HeyDudeResponse",
- "http://tempuri.org/", true,
- md, "HeyDude");
- ServiceAssert.AssertMessagePartDescription (
- "HeyDudeResult", "http://tempuri.org/", 0, false,
- ProtectionLevel.None, typeof (string), md.Body.ReturnValue, "HeyDudeResponse ReturnValue");
- // Operation #2
- od = cd.Operations [1];
- ServiceAssert.AssertOperationDescription (
- "HeyHey", null, null,
- typeof (IFoo).GetMethod ("HeyHey"),
- true, false, false,
- od, "HeyHey");
- // Operation #2 -> Message #1
- md = od.Messages [0];
- ServiceAssert.AssertMessageAndBodyDescription (
- "http://tempuri.org/IFoo/HeyHey",
- MessageDirection.Input,
- null, "HeyHey", "http://tempuri.org/", false,
- md, "HeyHey");
- ServiceAssert.AssertMessagePartDescription (
- "ref1", "http://tempuri.org/", 0, false,
- ProtectionLevel.None, typeof (string), md.Body.Parts [0], "HeyHey.ref1");
- // Operation #2 -> Message #2
- md = od.Messages [1];
- ServiceAssert.AssertMessageAndBodyDescription (
- "http://tempuri.org/IFoo/HeyHeyResponse",
- MessageDirection.Output,
- null, "HeyHeyResponse",
- "http://tempuri.org/", true,
- md, "HeyHey");
- ServiceAssert.AssertMessagePartDescription (
- "HeyHeyResult", "http://tempuri.org/", 0, false,
- ProtectionLevel.None, typeof (void), md.Body.ReturnValue, "HeyHeyResponse ReturnValue");
- ServiceAssert.AssertMessagePartDescription (
- "out1", "http://tempuri.org/", 0, false,
- ProtectionLevel.None, typeof (string), md.Body.Parts [0], "HeyHey.out1");
- ServiceAssert.AssertMessagePartDescription (
- "ref1", "http://tempuri.org/", 1, false,
- ProtectionLevel.None, typeof (string), md.Body.Parts [1], "HeyHey.ref1");
- }
- [Test]
- public void GetContractInherit ()
- {
- ContractDescription.GetContract (typeof (Foo));
- }
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- public void GetMultipleServiceContract ()
- {
- ContractDescription.GetContract (typeof (FooBar));
- }
- [Test]
- // [ExpectedException (typeof (InvalidOperationException))]
- public void GetContractNoOperation ()
- {
- ContractDescription.GetContract (typeof (INoOperation));
- }
- [Test]
- [Category ("NotWorking")]
- public void GetContractMessageParameter ()
- {
- ContractDescription cd = ContractDescription.GetContract (typeof (IMessageParameter));
- ServiceAssert.AssertContractDescription (
- "IMessageParameter", "http://tempuri.org/",
- SessionMode.Allowed, typeof (IMessageParameter), null,
- cd, "contract");
- OperationDescription od = cd.Operations [0];
- ServiceAssert.AssertOperationDescription (
- "ReturnMessage", null, null,
- typeof (IMessageParameter).GetMethod ("ReturnMessage"),
- true, false, false,
- od, "operation");
- MessageDescription md = od.Messages [0];
- ServiceAssert.AssertMessageAndBodyDescription (
- "http://tempuri.org/IMessageParameter/ReturnMessage",
- MessageDirection.Input,
- // Body.WrapperName is null
- null, null, null, false,
- md, "ReturnMessage");
- ServiceAssert.AssertMessagePartDescription (
- "arg", "http://tempuri.org/", 0, false,
- ProtectionLevel.None, typeof (Message), md.Body.Parts [0], "ReturnMessage input");
- }
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- public void GetContractInvalidAsync ()
- {
- ContractDescription.GetContract (typeof (IInvalidAsync));
- }
- [Test]
- // IMetadataExchange contains async patterns.
- public void GetContractIMetadataExchange ()
- {
- ContractDescription cd = ContractDescription.GetContract (typeof (IMetadataExchange));
- OperationDescription od = cd.Operations [0];
- Assert.AreEqual (2, od.Messages.Count, "premise: message count");
- foreach (MessageDescription md in od.Messages) {
- if (md.Direction == MessageDirection.Input) {
- Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2004/09/transfer/Get", md.Action, "#1-1");
- Assert.AreEqual (1, md.Body.Parts.Count, "#1-2");
- Assert.IsNull (md.Body.ReturnValue, "#1-3");
- Assert.AreEqual (typeof (Message), md.Body.Parts [0].Type, "#1-4");
- } else {
- Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2004/09/transfer/GetResponse", md.Action, "#2-1");
- Assert.AreEqual (0, md.Body.Parts.Count, "#2-2");
- Assert.IsNotNull (md.Body.ReturnValue, "#2-3");
- Assert.AreEqual (typeof (Message), md.Body.ReturnValue.Type, "#2-4");
- }
- }
- }
- [Test]
- // enable it if we want to become a compatibility kid. It has
- // no ServiceContract, thus it should not be accepted. But
- // there is an abuse of ChannelFactory<IRequestChannel> in
- // MSDN documentations and probably examples.
- [Category ("NotWorking")]
- public void GetContractIRequestChannel ()
- {
- ContractDescription cd = ContractDescription.GetContract (typeof (IRequestChannel));
- Assert.AreEqual (typeof (IRequestChannel), cd.ContractType, "#_1");
- Assert.AreEqual ("IRequestChannel", cd.Name, "#_2");
- Assert.AreEqual ("http://schemas.microsoft.com/2005/07/ServiceModel", cd.Namespace, "#_3");
- Assert.AreEqual (false, cd.HasProtectionLevel, "#_4");
- Assert.AreEqual (SessionMode.NotAllowed, cd.SessionMode, "#_5");
- Assert.AreEqual (0, cd.Behaviors.Count, "#_6");
- Assert.AreEqual (1, cd.Operations.Count, "#_7");
- OperationDescription od = cd.Operations [0];
- Assert.IsNull (od.SyncMethod, "#_8");
- Assert.IsNull (od.BeginMethod, "#_9");
- Assert.IsNull (od.EndMethod, "#_10");
- Assert.AreEqual (false, od.IsOneWay, "#_11");
- Assert.AreEqual (false, od.HasProtectionLevel, "#_12");
- Assert.AreEqual ("Request", od.Name, "#_13");
- Assert.AreEqual (true, od.IsInitiating, "#_14");
- Assert.AreEqual (0, od.Behaviors.Count, "#_15");
- Assert.AreEqual (2, od.Messages.Count, "#_16");
- foreach (MessageDescription md in od.Messages) {
- if (md.Direction == MessageDirection.Output) {
- Assert.AreEqual ("*", md.Action, "#_17");
- Assert.AreEqual (false, md.HasProtectionLevel, "#_18");
- Assert.AreEqual (0, md.Headers.Count, "#_19");
- Assert.AreEqual (0, md.Properties.Count, "#_20");
- Assert.IsNull (md.MessageType, "#_21");
- MessageBodyDescription mb = md.Body;
- Assert.AreEqual (null, mb.WrapperName, "#_22");
- Assert.AreEqual (null, mb.WrapperNamespace, "#_23");
- Assert.IsNull (mb.ReturnValue, "#_24");
- Assert.AreEqual (0, mb.Parts.Count, "#_25");
- } else {
- Assert.AreEqual ("*", md.Action, "#_17_");
- Assert.AreEqual (false, md.HasProtectionLevel, "#_18_");
- Assert.AreEqual (0, md.Headers.Count, "#_19_");
- Assert.AreEqual (0, md.Properties.Count, "#_20_");
- Assert.IsNull (md.MessageType, "#_21_");
- MessageBodyDescription mb = md.Body;
- Assert.AreEqual (null, mb.WrapperName, "#_22_");
- Assert.AreEqual (null, mb.WrapperNamespace, "#_23_");
- Assert.IsNull (mb.ReturnValue, "#_24_");
- Assert.AreEqual (0, mb.Parts.Count, "#_25_");
- }
- }
- }
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- public void WrongAsyncEndContract ()
- {
- ContractDescription.GetContract (typeof (IWrongAsyncEndContract));
- }
- [Test]
- public void AsyncContract1 ()
- {
- ContractDescription cd =
- ContractDescription.GetContract (typeof (IAsyncContract1));
- Assert.AreEqual (1, cd.Operations.Count);
- OperationDescription od = cd.Operations [0];
- Assert.AreEqual ("Sum", od.Name, "#1");
- Assert.IsNotNull (od.BeginMethod, "#2");
- Assert.IsNotNull (od.EndMethod, "#3");
- }
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- public void DuplicateOperationNames ()
- {
- ContractDescription.GetContract (typeof (IDuplicateOperationNames));
- }
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- public void AsyncMethodNameDoesNotStartWithBegin ()
- {
- ContractDescription.GetContract (typeof (IAsyncMethodNameDoesNotStartWithBegin));
- }
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- public void AsyncNameDoesNotStartWithBeginButExplicitName ()
- {
- // it is still invalid ...
- ContractDescription.GetContract (typeof (IAsyncNameDoesNotStartWithBeginButExplicitName));
- }
- [Test]
- public void MessageBodyMemberIsNotInferred ()
- {
- ContractDescription cd = ContractDescription.GetContract (typeof (MessageBodyMemberIsNotInferredService));
- OperationDescription od = cd.Operations [0];
- MessageDescription md = od.Messages [0];
- Assert.AreEqual (0, md.Body.Parts.Count);
- }
- [Test]
- public void TestContractFromObject () {
- ContractDescription cd = ContractDescription.GetContract (typeof (Foo));
- ServiceAssert.AssertContractDescription (typeof (IFoo).Name, "http://tempuri.org/", SessionMode.Allowed, typeof (IFoo), null, cd, "#1");
- Assert.AreEqual (cd.Operations.Count, 2);
- OperationBehaviorAttribute op = cd.Operations.Find ("HeyHey").Behaviors.Find<OperationBehaviorAttribute> ();
- Assert.IsNotNull (op);
- Assert.AreEqual (
- op.ReleaseInstanceMode,
- ReleaseInstanceMode.None, "#2");
- cd = ContractDescription.GetContract (typeof (IFoo), typeof (Foo));
- ServiceAssert.AssertContractDescription (typeof (IFoo).Name, "http://tempuri.org/", SessionMode.Allowed, typeof (IFoo), null, cd, "#3");
- Assert.AreEqual (cd.Operations.Count, 2, "#4");
- Assert.AreEqual (
- cd.Operations.Find ("HeyHey").Behaviors.Find<OperationBehaviorAttribute> ().ReleaseInstanceMode,
- ReleaseInstanceMode.AfterCall, "#5");
- }
- [Test]
- public void GetDerivedContract ()
- {
- var cd = ContractDescription.GetContract (typeof (IFoo3));
- Assert.AreEqual (typeof (IFoo3), cd.ContractType, "#1");
- Assert.AreEqual (3, cd.Operations.Count, "#2");
- cd = ContractDescription.GetContract (typeof (Foo3));
- Assert.AreEqual (typeof (IFoo3), cd.ContractType, "#3");
- Assert.AreEqual (3, cd.Operations.Count, "#4");
- }
-
- [Test]
- public void MultipleContractsInTypeHierarchy ()
- {
- ContractDescription.GetContract (typeof (DuplicateCheckClassWrapper.ServiceInterface));
- var host = new ServiceHost (typeof (DuplicateCheckClassWrapper.DummyService)); // fine in MS, fails in Mono with "A contract cannot have two operations that have the identical names and different set of parameters"
- }
- [Test]
- public void GetInheritedContracts ()
- {
- var cd = ContractDescription.GetContract (typeof (IService));
- var ccd = cd.GetInheritedContracts ();
- Assert.AreEqual (1, ccd.Count, "#1");
- Assert.AreEqual (typeof (IServiceBase), ccd [0].ContractType, "#2");
- }
- [Test]
- public void InheritedContractAndNamespaces ()
- {
- var cd = ContractDescription.GetContract (typeof (IService));
- Assert.IsTrue (cd.Operations.Any (od => od.Messages.Any (md => md.Action == "http://tempuri.org/IServiceBase/Say")), "#1"); // inherited
- Assert.IsTrue (cd.Operations.Any (od => od.SyncMethod == typeof (IService).GetMethod ("Join") && od.Messages.Any (md => md.Action == "http://tempuri.org/IService/Join")), "#2"); // self
- Assert.IsTrue (cd.Operations.Any (od => od.SyncMethod == typeof (IService2).GetMethod ("Join") && od.Messages.Any (md => md.Action == "http://tempuri.org/IService/Join")), "#3"); // callback
- }
-
- [Test]
- public void AsyncContractWithSymmetricCallbackContract ()
- {
- var cd = ContractDescription.GetContract (typeof(IAsyncContractWithSymmetricCallbackContract));
- Assert.AreEqual (2, cd.Operations.Count, "#1");
- Assert.AreSame (typeof (IAsyncContractWithSymmetricCallbackContract), cd.ContractType, "#2");
- Assert.AreSame (typeof (IAsyncContractWithSymmetricCallbackContract), cd.CallbackContractType, "#3");
- }
-
- [Test]
- public void InheritingDuplexContract ()
- {
- var cd = ContractDescription.GetContract (typeof (IDerivedDuplexContract));
- Assert.AreEqual (4, cd.Operations.Count, "#1");
- Assert.AreSame (typeof (IDerivedDuplexContract), cd.ContractType, "#2");
- Assert.AreSame (typeof (IDerivedDuplexCallback), cd.CallbackContractType, "#3");
- Assert.IsTrue (cd.Operations.Any (od => od.SyncMethod == typeof (IBaseDuplexCallback).GetMethod ("CallbackMethod")), "#4");
- Assert.IsTrue (cd.Operations.Any (od => od.SyncMethod == typeof (IDerivedDuplexCallback).GetMethod ("CallbackSomething")), "#5");
- Assert.IsTrue (cd.Operations.Any (od => od.SyncMethod == typeof (IBaseDuplexContract).GetMethod ("ContractMethod")), "#6");
- Assert.IsTrue (cd.Operations.Any (od => od.SyncMethod == typeof (IDerivedDuplexContract).GetMethod ("Something")), "#7");
- }
-
- [Test]
- public void SymmetricInheritingContract ()
- {
- var cd = ContractDescription.GetContract (typeof(ISymmetricInheritance));
- Assert.AreEqual (4, cd.Operations.Count, "#1");
- Assert.AreSame (typeof (ISymmetricInheritance), cd.ContractType, "#2");
- Assert.AreSame (typeof (ISymmetricInheritance), cd.CallbackContractType, "#3");
- Assert.AreEqual (2, cd.Operations.Count(od => od.SyncMethod == typeof (IAsyncContractWithSymmetricCallbackContract).GetMethod ("Foo")), "#4");
- Assert.AreEqual (2, cd.Operations.Count(od => od.SyncMethod == typeof (ISymmetricInheritance).GetMethod ("Bar")), "#5");
- }
-
- [Test]
- public void DeepContractHierarchyTest ()
- {
- var cd = ContractDescription.GetContract (typeof(IDeepContractHierarchy));
- Assert.AreEqual (6, cd.Operations.Count, "#1");
- Assert.AreSame (typeof (IDeepContractHierarchy), cd.ContractType, "#2");
- Assert.AreSame (typeof (IDeepContractHierarchy), cd.CallbackContractType, "#3");
- }
- [Test]
- public void MessageContractAttributes ()
- {
- var cd = ContractDescription.GetContract (typeof (IFoo2));
- var od = cd.Operations.First (o => o.Name == "Nanoda");
- var md = od.Messages.First (m => m.Direction == MessageDirection.Input);
- Assert.AreEqual (typeof (OregoMessage), md.MessageType, "message type");
- Assert.AreEqual ("http://tempuri.org/IFoo2/Nanoda", md.Action, "action");
- Assert.AreEqual (1, md.Headers.Count, "headers");
- Assert.AreEqual (3, md.Body.Parts.Count, "body parts");
- Assert.AreEqual (0, md.Properties.Count, "properties");
- }
- // .NET complains: The operation Nanoda2 either has a parameter or a return type that is attributed with MessageContractAttribute. In order to represent the request message using a Message Contract, the operation must have a single parameter attributed with MessageContractAttribute. In order to represent the response message using a Message Contract, the operation's return value must be a type that is attributed with MessageContractAttribute and the operation may not have any out or ref parameters.
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- public void MessageContractAttributes2 ()
- {
- ContractDescription.GetContract (typeof (IFoo2_2));
- }
- [Test]
- public void MessageContractAttributes3 ()
- {
- ContractDescription.GetContract (typeof (IFoo2_3));
- }
- [Test]
- public void MessageContractAttributes4 ()
- {
- ContractDescription.GetContract (typeof (IFoo2_4));
- }
- [Test]
- public void MessageContractAttributes5 ()
- {
- ContractDescription.GetContract (typeof (IFoo2_5));
- }
- [Test]
- public void MessageContractAttributes6 ()
- {
- ContractDescription.GetContract (typeof (IFoo2_6));
- }
- [Test]
- public void XmlSerializedOperation ()
- {
- var cd = ContractDescription.GetContract (typeof (XmlSerializedService));
- var od = cd.Operations.First ();
- var xb = od.Behaviors.Find<XmlSerializerOperationBehavior> ();
- Assert.IsNotNull (xb, "#1");
- }
- [Test]
- public void MessageParameterDescriptionInUse ()
- {
- // bug #41
- var cd = ContractDescription.GetContract (typeof (Dealerinfo.wsvDealerinfo.WSVDealerInfoServices));
- foreach (var od in cd.Operations)
- foreach (var md in od.Messages)
- if (md.Action == "*") // return
- Assert.IsNotNull (md.Body.ReturnValue, od.Name);
- }
- [Test]
- public void BugX206Contract ()
- {
- var cd = ContractDescription.GetContract (typeof (BugX206Service));
- bool examined = false;
- foreach (var md in cd.Operations.First ().Messages) {
- if (md.Direction == MessageDirection.Input)
- continue;
- var pd = md.Body.ReturnValue;
- Assert.IsNotNull (pd, "#1");
- Assert.AreEqual ("DoWorkResult", pd.Name, "#2");
- Assert.IsNull (pd.MemberInfo, "#3");
- Assert.AreEqual (typeof (void), pd.Type, "#4");
- examined = true;
- }
- Assert.IsTrue (examined, "end");
- }
- // It is for testing attribute search in interfaces.
- public class Foo : IFoo
- {
- public string HeyDude (string msg, string msg2)
- {
- return null;
- }
- [OperationBehavior (ReleaseInstanceMode = ReleaseInstanceMode.AfterCall)]
- public void HeyHey (out string out1, ref string ref1)
- {
- out1 = null;
- }
- }
- // It inherits both IFoo and IBar, thus cannot be a contract.
- public class FooBar : IFoo, IBar
- {
- public string HeyDude (string msg, string msg2)
- {
- return null;
- }
-
- public void HeyHey (out string out1, ref string ref1)
- {
- out1 = null;
- }
- public void OpenBar () {}
- }
- [ServiceContract]
- public interface IFoo
- {
- [OperationContract]
- string HeyDude (string msg, string msg2);
- [OperationContract]
- void HeyHey (out string out1, ref string ref1);
- }
- [ServiceContract]
- public interface IFoo2
- {
- // FIXME: it does not pass yet
- [OperationContract]
- OregoMessage Nanoda (OregoMessage msg);
- // FIXME: it does not pass yet
- [OperationContract]
- Mona NewMona (Mona source);
- }
- [ServiceContract]
- public interface IFoo2_2
- {
- [OperationContract] // wrong operation contract, must have only one parameter with MessageContractAttribute
- OregoMessage Nanoda2 (OregoMessage msg1, OregoMessage msg2);
- }
- [ServiceContract]
- public interface IFoo2_3
- {
- [OperationContract]
- string Nanoda2 (OregoMessage msg1);
- }
- [ServiceContract]
- public interface IFoo2_4
- {
- [OperationContract]
- OregoMessage Nanoda2 (string s, string s2);
- }
- [ServiceContract]
- public interface IFoo2_5
- {
- [OperationContract]
- Message Nanoda2 (OregoMessage msg1);
- }
- [ServiceContract]
- public interface IFoo2_6
- {
- [OperationContract]
- OregoMessage Nanoda2 (Message msg1);
- }
- [ServiceContract]
- public interface IFoo3 : IFoo
- {
- [OperationContract]
- string HeyMan (string msg, string msg2);
- }
- public class Foo3 : Foo, IFoo3
- {
- public string HeyMan (string msg, string msg2)
- {
- return msg + msg2;
- }
- }
- [ServiceContract]
- public interface IBar
- {
- [OperationContract]
- void OpenBar ();
- }
- [MessageContract]
- public class OregoMessage
- {
- [MessageHeader]
- public string Head;
- [MessageBodyMember]
- public string Neutral;
- [MessageBodyMember]
- public Assembly Huh;
- [MessageBodyMember] // it should be ignored ...
- public string Setter { set { } }
- public string NonMember;
- }
- public class Mona
- {
- public string OmaeMona;
- public string OreMona;
- }
- [ServiceContract]
- public interface INoOperation
- {
- }
- [ServiceContract]
- public interface IMessageParameter
- {
- [OperationContract]
- Message ReturnMessage (Message arg);
- }
- [ServiceContract]
- public interface IInvalidAsync
- {
- [OperationContract]
- Message ReturnMessage (Message arg);
- [OperationContract (AsyncPattern = true)]
- IAsyncResult BeginReturnMessage (Message arg, AsyncCallback callback, object state);
- // and no EndReturnMessage().
- }
- [ServiceContract]
- public interface IWrongAsyncEndContract
- {
- [OperationContract]
- int Sum (int a, int b);
- [OperationContract (AsyncPattern = true)]
- IAsyncResult BeginSum (int a, int b, AsyncCallback cb, object state);
- // this OperationContractAttribute is not allowed.
- [OperationContract (AsyncPattern = true)]
- int EndSum (IAsyncResult result);
- }
- [ServiceContract]
- public interface IAsyncContract1
- {
- [OperationContract]
- int Sum (int a, int b);
- [OperationContract (AsyncPattern = true)]
- IAsyncResult BeginSum (int a, int b, AsyncCallback cb, object state);
- int EndSum (IAsyncResult result);
- }
- [ServiceContract]
- public interface IAsyncMethodNameDoesNotStartWithBegin
- {
- [OperationContract]
- int Sum (int a, int b);
- [OperationContract (AsyncPattern = true)]
- IAsyncResult StartSum (int a, int b, AsyncCallback cb, object state);
- int EndSum (IAsyncResult result);
- }
- [ServiceContract]
- public interface IAsyncNameDoesNotStartWithBeginButExplicitName
- {
- [OperationContract]
- int Sum (int a, int b);
- [OperationContract (Name = "Sum", AsyncPattern = true)]
- IAsyncResult StartSum (int a, int b, AsyncCallback cb, object state);
- int EndSum (IAsyncResult result);
- }
- [ServiceContract]
- public interface IDuplicateOperationNames
- {
- [OperationContract]
- string Echo (string s);
- [OperationContract]
- string Echo (string s1, string s2);
- }
- [ServiceContract]
- public interface IFooMsgParams
- {
- [OperationContract (Name = "MyFoo")]
- [return: MessageParameter (Name = "MyResult")]
- string Foo ([MessageParameter (Name = "MyParam")] string param);
- }
- [ServiceContract]
- public class MessageBodyMemberIsNotInferredService
- {
- [OperationContract]
- public void Echo (MessageBodyMemberIsNotInferredContract msg)
- {
- }
- }
- [MessageContract]
- public class MessageBodyMemberIsNotInferredContract
- {
- string foo = "foo";
- public string Foo {
- get { return foo; }
- set { foo = value; }
- }
- }
- public class DuplicateCheckClassWrapper
- {
- [ServiceContract]
- internal interface ServiceInterface : Foo
- {
- }
- [ServiceContract]
- internal interface Foo : Bar
- {
- [OperationContract] void Foo();
- }
- [ServiceContract]
- internal interface Bar
- {
- [OperationContract] void FooBar();
- }
- internal class DummyService : ServiceInterface
- {
- public void FooBar() { }
- public void Foo() { }
- }
- }
- [ServiceContract]
- public interface IServiceBase
- {
- [OperationContract (IsOneWay = true)]
- void Say (string word);
- }
- [ServiceContract (CallbackContract = typeof (IService2))]
- public interface IService : IServiceBase
- {
- [OperationContract]
- void Join ();
- }
- [ServiceContract]
- public interface IServiceBase2
- {
- [OperationContract (IsOneWay = true)]
- void Say (string word);
- }
- [ServiceContract]
- public interface IService2 : IServiceBase2
- {
- [OperationContract]
- void Join ();
- }
-
- [ServiceContract (CallbackContract = typeof (IAsyncContractWithSymmetricCallbackContract))]
- public interface IAsyncContractWithSymmetricCallbackContract
- {
- [OperationContract]
- void Foo();
- [OperationContract (AsyncPattern = true)]
- IAsyncResult BeginFoo (AsyncCallback callback, object asyncState);
- void EndFoo (IAsyncResult result);
- }
-
- [ServiceContract (CallbackContract = typeof (ISymmetricInheritance))]
- public interface ISymmetricInheritance : IAsyncContractWithSymmetricCallbackContract
- {
- [OperationContract]
- void Bar ();
- [OperationContract (AsyncPattern = true)]
- IAsyncResult BeginBar (AsyncCallback callback, object asyncState);
- void EndBar (IAsyncResult result);
- }
-
- [ServiceContract (CallbackContract = typeof (IDeepContractHierarchy))]
- public interface IDeepContractHierarchy : ISymmetricInheritance
- {
- [OperationContract]
- void Foobar();
- }
-
- public interface IBaseDuplexCallback
- {
- [OperationContract]
- void CallbackMethod ();
- }
-
- [ServiceContract (CallbackContract = typeof (IBaseDuplexCallback))]
- public interface IBaseDuplexContract
- {
- [OperationContract]
- void ContractMethod ();
- }
-
- public interface IDerivedDuplexCallback : IBaseDuplexCallback
- {
- [OperationContract]
- void CallbackSomething ();
- }
-
- [ServiceContract (CallbackContract = typeof(IDerivedDuplexCallback))]
- public interface IDerivedDuplexContract : IBaseDuplexContract
- {
- [OperationContract]
- void Something ();
- }
- [ServiceContract]
- public interface XmlSerializedService
- {
- [OperationContract]
- [XmlSerializerFormat]
- string Echo (string input);
- }
- [ServiceContract]
- public interface BugX206Service
- {
- [OperationContract]
- BugX206Response DoWork ();
- }
- [MessageContract (IsWrapped = true)]
- public partial class BugX206Response
- {
- }
- [Test]
- public void TestInterfaceInheritance ()
- {
- var cd = ContractDescription.GetContract (typeof (InterfaceInheritance));
- var inherited = cd.GetInheritedContracts ();
- Assert.AreEqual (1, inherited.Count, "#1");
- }
- public class MyWebGetAttribute : Attribute, IOperationBehavior
- {
- void IOperationBehavior.AddBindingParameters (OperationDescription operation, BindingParameterCollection parameters)
- {
- ;
- }
-
- void IOperationBehavior.ApplyClientBehavior (OperationDescription operation, ClientOperation client)
- {
- ;
- }
-
- void IOperationBehavior.ApplyDispatchBehavior (OperationDescription operation, DispatchOperation service)
- {
- ;
- }
-
- void IOperationBehavior.Validate (OperationDescription operation)
- {
- ;
- }
- }
- [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
- public class InterfaceInheritance : IInterfaceInheritance
- {
- public string Get ()
- {
- throw new NotImplementedException ();
- }
-
- public string Test ()
- {
- throw new NotImplementedException ();
- }
- }
-
- [ServiceContract]
- public interface IInterfaceInheritance: IBaseInterface
- {
- [OperationContract]
- [MyWebGet]
- string Test ();
- }
-
- [ServiceContract]
- public interface IBaseInterface
- {
- [OperationContract]
- [MyWebGet]
- string Get ();
- }
- }
- }
|