| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- //
- // ChannelFactoryTest.cs
- //
- // Author:
- // Atsushi Enomoto <[email protected]>
- //
- // Copyright (C) 2006 Novell, Inc. http://www.novell.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.ServiceModel;
- using System.ServiceModel.Channels;
- using System.ServiceModel.Description;
- using NUnit.Framework;
- namespace MonoTests.System.ServiceModel
- {
- [TestFixture]
- public class ChannelFactoryTest
- {
- class SimpleChannelFactory
- : ChannelFactory
- {
- public SimpleChannelFactory ()
- : base ()
- {
- }
- protected override TimeSpan DefaultCloseTimeout {
- get { return TimeSpan.FromMinutes (1); }
- }
- protected override TimeSpan DefaultOpenTimeout {
- get { return TimeSpan.FromMinutes (1); }
- }
- protected override ServiceEndpoint CreateDescription ()
- {
- return new ServiceEndpoint (ContractDescription.GetContract (typeof(ICtorUseCase2)));
- }
- public void InitEndpoint (Binding b, EndpointAddress addr)
- {
- base.InitializeEndpoint (b, addr);
- }
- public void InitEndpoint (string configName, EndpointAddress addr)
- {
- base.InitializeEndpoint (configName, addr);
- }
- public void ApplyConfig (string configName)
- {
- base.ApplyConfiguration (configName);
- }
- }
- [Test]
- public void InitializeEndpointTest1 ()
- {
- SimpleChannelFactory factory = new SimpleChannelFactory ();
- Assert.AreEqual (null, factory.Endpoint, "#01");
- Binding b = new WSHttpBinding ();
- factory.InitEndpoint (b, null);
- Assert.AreEqual (b, factory.Endpoint.Binding, "#02");
- Assert.AreEqual (null, factory.Endpoint.Address, "#03");
- Assert.AreEqual (typeof (ICtorUseCase2), factory.Endpoint.Contract.ContractType, "#04");
- }
- [Test]
- [Ignore ("fails under .NET; I never bothered to fix the test")]
- public void InitializeEndpointTest2 ()
- {
- SimpleChannelFactory factory = new SimpleChannelFactory ();
- Assert.AreEqual (null, factory.Endpoint, "#01");
- factory.InitEndpoint ("CtorUseCase2_1", null);
- Assert.AreEqual (typeof (BasicHttpBinding), factory.Endpoint.Binding.GetType (), "#02");
- Assert.AreEqual (new EndpointAddress ("http://test2_1"), factory.Endpoint.Address, "#03");
- Assert.AreEqual (typeof (ICtorUseCase2), factory.Endpoint.Contract.ContractType, "#04");
- }
- [Test]
- [Ignore ("fails under .NET; I never bothered to fix the test")]
- public void InitializeEndpointTest3 ()
- {
- SimpleChannelFactory factory = new SimpleChannelFactory ();
- Assert.AreEqual (null, factory.Endpoint, "#01");
- factory.InitEndpoint ("CtorUseCase2_1", null);
- Binding b = new WSHttpBinding ();
- factory.InitEndpoint (b, null);
- Assert.AreEqual (b, factory.Endpoint.Binding, "#02");
- Assert.AreEqual (null, factory.Endpoint.Address, "#03");
- }
- [Test]
- [Ignore ("fails under .NET; I never bothered to fix the test")]
- public void ApplyConfigurationTest1 ()
- {
- SimpleChannelFactory factory = new SimpleChannelFactory ();
- Binding b = new WSHttpBinding ();
- factory.InitEndpoint (b, null);
- factory.ApplyConfig ("CtorUseCase2_1");
- Assert.AreEqual (new EndpointAddress ("http://test2_1"), factory.Endpoint.Address, "#03");
- Assert.AreEqual (b, factory.Endpoint.Binding, "#02");
- }
- [Test]
- [Ignore ("fails under .NET; I never bothered to fix the test")]
- public void ApplyConfigurationTest2 ()
- {
- SimpleChannelFactory factory = new SimpleChannelFactory ();
- Binding b = new WSHttpBinding ();
- factory.InitEndpoint (b, new EndpointAddress ("http://test"));
- factory.ApplyConfig ("CtorUseCase2_2");
- Assert.AreEqual (new EndpointAddress ("http://test"), factory.Endpoint.Address, "#03");
- Assert.IsNotNull (factory.Endpoint.Behaviors.Find <CallbackDebugBehavior> (), "#04");
- Assert.AreEqual (true, factory.Endpoint.Behaviors.Find <CallbackDebugBehavior> ().IncludeExceptionDetailInFaults, "#04");
- factory.ApplyConfig ("CtorUseCase2_3");
- Assert.IsNotNull (factory.Endpoint.Behaviors.Find <CallbackDebugBehavior> (), "#04");
- Assert.AreEqual (false, factory.Endpoint.Behaviors.Find <CallbackDebugBehavior> ().IncludeExceptionDetailInFaults, "#04");
- }
- [Test]
- public void DescriptionProperties ()
- {
- Binding b = new BasicHttpBinding ();
- ChannelFactory<IFoo> f = new ChannelFactory<IFoo> (b);
- // FIXME: it's not working now (though this test is silly to me.)
- //Assert.IsNull (f.Description.ChannelType, "ChannelType");
- // FIXME: it's not working now
- //Assert.AreEqual (1, f.Endpoint.Behaviors.Count, "Behaviors.Count");
- //ClientCredentials cred = f.Endpoint.Behaviors [0] as ClientCredentials;
- //Assert.IsNotNull (cred, "Behaviors contains ClientCredentials");
- Assert.IsNotNull (f.Endpoint, "Endpoint");
- Assert.AreEqual (b, f.Endpoint.Binding, "Endpoint.Binding");
- Assert.IsNull (f.Endpoint.Address, "Endpoint.Address");
- // You can examine this silly test on .NET.
- // Funky, ContractDescription.GetContract(
- // typeof (IRequestChannel)) also fails to raise an
- // error.
- //Assert.AreEqual ("IRequestChannel", f.Description.Endpoint.Contract.Name, "Endpoint.Contract");
- }
- public class MyChannelFactory<TChannel>
- : ChannelFactory<TChannel>
- {
- public MyChannelFactory (Type type)
- : base (type)
- {
- }
- }
- [ServiceContract]
- public interface IFoo
- {
- [OperationContract]
- string Echo (string msg);
- }
- public class Foo : IFoo
- {
- public string Echo (string msg)
- {
- return msg;
- }
- }
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- public void ArgumentTypeNotInterface ()
- {
- new MyChannelFactory<IFoo> (typeof (Foo));
- }
- }
- }
|