2 // ClientBase_InteractiveChannelInitializerTest.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.Net.Sockets;
32 using System.Reflection;
33 using System.ServiceModel;
34 using System.ServiceModel.Channels;
35 using System.ServiceModel.Description;
36 using System.ServiceModel.Dispatcher;
38 using NUnit.Framework;
40 using MonoTests.Helpers;
42 namespace MonoTests.System.ServiceModel
45 // FIXME: it does not contain testcase for successful initialization yet
46 // (MyChannelInitializer implementation hangs on .NET)
47 public class ClientBase_InteractiveChannelInitializerTest
50 [ExpectedException (typeof (InvalidOperationException))]
51 public void NotAllowedInitializationUI ()
53 var f = new FooProxy (new BasicHttpBinding (), new EndpointAddress ("http://localhost:" + NetworkHelpers.FindFreePort ()));
54 f.Endpoint.Contract.Behaviors.Add (new MyContractBehavior ());
55 f.InnerChannel.AllowInitializationUI = false;
56 f.DisplayInitializationUI ();
60 [ExpectedException (typeof (InvalidOperationException))]
61 public void OpenBeforeDisplayInitializationUI ()
63 var f = new FooProxy (new BasicHttpBinding (), new EndpointAddress ("http://localhost:" + NetworkHelpers.FindFreePort ()));
64 f.Endpoint.Contract.Behaviors.Add (new MyContractBehavior ());
68 public class MyContractBehavior2 : MyContractBehavior
72 public class MyContractBehavior : IContractBehavior
74 public void AddBindingParameters (ContractDescription contractDescription, ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
78 public void ApplyClientBehavior (ContractDescription contractDescription, ServiceEndpoint endpoint, ClientRuntime clientRuntime)
80 clientRuntime.InteractiveChannelInitializers.Add (new MyChannelInitializer ());
83 public void ApplyDispatchBehavior (ContractDescription contractDescription, ServiceEndpoint endpoint, DispatchRuntime dispatchRuntime)
87 public void Validate (ContractDescription contractDescription, ServiceEndpoint endpoint)
92 public class MyChannelInitializer : IInteractiveChannelInitializer
94 delegate void DoWork ();
99 public MyChannelInitializer ()
104 public IAsyncResult BeginDisplayInitializationUI (IClientChannel channel, AsyncCallback callback, object state)
106 Console.WriteLine ("Begin");
107 d = new DoWork (DisplayInitializationUI);
108 return d.BeginInvoke (null, null);
111 public void EndDisplayInitializationUI (IAsyncResult result)
113 Console.WriteLine ("End");
114 d.EndInvoke (result);
117 public void DisplayInitializationUI ()
119 Console.WriteLine ("Core: " + number);
123 public class FooProxy : ClientBase<IFoo>, IFoo
125 public FooProxy (Binding binding, EndpointAddress address)
126 : base (binding, address)
130 public string Echo (string msg)
132 return Channel.Echo (msg);
137 public interface IFoo
140 string Echo (string input);
143 public class FooService : IFoo
145 public string Echo (string input)