2 // ChannelFactoryTest.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;
30 using System.ServiceModel;
31 using System.ServiceModel.Channels;
32 using System.ServiceModel.Description;
33 using NUnit.Framework;
35 namespace MonoTests.System.ServiceModel
38 public class ChannelFactoryTest
40 class SimpleChannelFactory
43 public SimpleChannelFactory ()
48 protected override TimeSpan DefaultCloseTimeout {
49 get { return TimeSpan.FromMinutes (1); }
52 protected override TimeSpan DefaultOpenTimeout {
53 get { return TimeSpan.FromMinutes (1); }
56 protected override ServiceEndpoint CreateDescription ()
58 return new ServiceEndpoint (ContractDescription.GetContract (typeof(ICtorUseCase2)));
61 public void InitEndpoint (Binding b, EndpointAddress addr)
63 base.InitializeEndpoint (b, addr);
66 public void InitEndpoint (string configName, EndpointAddress addr)
68 base.InitializeEndpoint (configName, addr);
71 public void ApplyConfig (string configName)
73 base.ApplyConfiguration (configName);
78 public void InitializeEndpointTest1 ()
80 SimpleChannelFactory factory = new SimpleChannelFactory ();
81 Assert.AreEqual (null, factory.Endpoint, "#01");
82 Binding b = new WSHttpBinding ();
83 factory.InitEndpoint (b, null);
84 Assert.AreEqual (b, factory.Endpoint.Binding, "#02");
85 Assert.AreEqual (null, factory.Endpoint.Address, "#03");
86 Assert.AreEqual (typeof (ICtorUseCase2), factory.Endpoint.Contract.ContractType, "#04");
90 [Ignore ("fails under .NET; I never bothered to fix the test")]
91 public void InitializeEndpointTest2 ()
93 SimpleChannelFactory factory = new SimpleChannelFactory ();
94 Assert.AreEqual (null, factory.Endpoint, "#01");
95 factory.InitEndpoint ("CtorUseCase2_1", null);
96 Assert.AreEqual (typeof (BasicHttpBinding), factory.Endpoint.Binding.GetType (), "#02");
97 Assert.AreEqual (new EndpointAddress ("http://test2_1"), factory.Endpoint.Address, "#03");
98 Assert.AreEqual (typeof (ICtorUseCase2), factory.Endpoint.Contract.ContractType, "#04");
102 [Ignore ("fails under .NET; I never bothered to fix the test")]
103 public void InitializeEndpointTest3 ()
105 SimpleChannelFactory factory = new SimpleChannelFactory ();
106 Assert.AreEqual (null, factory.Endpoint, "#01");
107 factory.InitEndpoint ("CtorUseCase2_1", null);
108 Binding b = new WSHttpBinding ();
109 factory.InitEndpoint (b, null);
110 Assert.AreEqual (b, factory.Endpoint.Binding, "#02");
111 Assert.AreEqual (null, factory.Endpoint.Address, "#03");
115 [Ignore ("fails under .NET; I never bothered to fix the test")]
116 public void ApplyConfigurationTest1 ()
118 SimpleChannelFactory factory = new SimpleChannelFactory ();
119 Binding b = new WSHttpBinding ();
120 factory.InitEndpoint (b, null);
121 factory.ApplyConfig ("CtorUseCase2_1");
122 Assert.AreEqual (new EndpointAddress ("http://test2_1"), factory.Endpoint.Address, "#03");
123 Assert.AreEqual (b, factory.Endpoint.Binding, "#02");
127 [Ignore ("fails under .NET; I never bothered to fix the test")]
128 public void ApplyConfigurationTest2 ()
130 SimpleChannelFactory factory = new SimpleChannelFactory ();
131 Binding b = new WSHttpBinding ();
132 factory.InitEndpoint (b, new EndpointAddress ("http://test"));
133 factory.ApplyConfig ("CtorUseCase2_2");
134 Assert.AreEqual (new EndpointAddress ("http://test"), factory.Endpoint.Address, "#03");
135 Assert.IsNotNull (factory.Endpoint.Behaviors.Find <CallbackDebugBehavior> (), "#04");
136 Assert.AreEqual (true, factory.Endpoint.Behaviors.Find <CallbackDebugBehavior> ().IncludeExceptionDetailInFaults, "#04");
137 factory.ApplyConfig ("CtorUseCase2_3");
138 Assert.IsNotNull (factory.Endpoint.Behaviors.Find <CallbackDebugBehavior> (), "#04");
139 Assert.AreEqual (false, factory.Endpoint.Behaviors.Find <CallbackDebugBehavior> ().IncludeExceptionDetailInFaults, "#04");
143 public void DescriptionProperties ()
145 Binding b = new BasicHttpBinding ();
146 ChannelFactory<IFoo> f = new ChannelFactory<IFoo> (b);
148 // FIXME: it's not working now (though this test is silly to me.)
149 //Assert.IsNull (f.Description.ChannelType, "ChannelType");
151 // FIXME: it's not working now
152 //Assert.AreEqual (1, f.Endpoint.Behaviors.Count, "Behaviors.Count");
153 //ClientCredentials cred = f.Endpoint.Behaviors [0] as ClientCredentials;
154 //Assert.IsNotNull (cred, "Behaviors contains ClientCredentials");
156 Assert.IsNotNull (f.Endpoint, "Endpoint");
157 Assert.AreEqual (b, f.Endpoint.Binding, "Endpoint.Binding");
158 Assert.IsNull (f.Endpoint.Address, "Endpoint.Address");
159 // You can examine this silly test on .NET.
160 // Funky, ContractDescription.GetContract(
161 // typeof (IRequestChannel)) also fails to raise an
163 //Assert.AreEqual ("IRequestChannel", f.Description.Endpoint.Contract.Name, "Endpoint.Contract");
166 public class MyChannelFactory<TChannel>
167 : ChannelFactory<TChannel>
169 public MyChannelFactory (Type type)
176 public interface IFoo
179 string Echo (string msg);
182 public class Foo : IFoo
184 public string Echo (string msg)
191 [ExpectedException (typeof (InvalidOperationException))]
192 public void ArgumentTypeNotInterface ()
194 new MyChannelFactory<IFoo> (typeof (Foo));