Little code cleanup. Since WCF creates TransparentProxy that implements IDisposable...
[castle.git] / Facilities / Wcf / Castle.Facilities.WcfIntegration.Tests / ServiceHostFixture.cs
blob27f03bd874c29df21443c75423345efcf6a1c765
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.Facilities.WcfIntegration.Tests
17 using System;
18 using System.ServiceModel;
19 using Castle.MicroKernel.Registration;
20 using Castle.Windsor;
21 using Castle.Facilities.WcfIntegration.Demo;
22 using NUnit.Framework;
24 [TestFixture]
25 public class ServiceHostFixture
27 [Test]
28 public void CanCreateServiceHost()
30 WindsorServiceHost host = new WindsorServiceHost(
31 new WindsorContainer().Kernel, typeof (Operations));
32 Assert.IsNotNull(host);
35 [Test]
36 public void CanCreateServiceHostAndOpenHost()
38 using (new WindsorContainer()
39 .AddFacility("wcf_facility", new WcfFacility())
40 .Register(Component.For<IOperations>().ImplementedBy<Operations>()
41 .CustomDependencies(new
43 number = 42,
44 serviceModel = new WcfServiceModel()
45 .AddEndpoints(
46 WcfEndpoint.BoundTo(new NetTcpBinding())
47 .At("net.tcp://localhost/Operations")
52 IOperations client = ChannelFactory<IOperations>.CreateChannel(
53 new NetTcpBinding(), new EndpointAddress("net.tcp://localhost/Operations"));
54 Assert.AreEqual(42, client.GetValueFromConstructor());
58 [Test]
59 public void CanCreateServiceHostAndOpenHostFromConfiguration()
61 using (new WindsorContainer()
62 .AddFacility("wcf_facility", new WcfFacility())
63 .Register(Component.For<UsingWindsor>()
64 .CustomDependencies(new
66 number = 42,
67 serviceModel = new WcfServiceModel()
71 IAmUsingWindsor client = ChannelFactory<IAmUsingWindsor>.CreateChannel(
72 new BasicHttpBinding(), new EndpointAddress("http://localhost:27198/UsingWindsor.svc"));
73 Assert.AreEqual(42, client.GetValueFromWindsorConfig());
77 [Test]
78 public void CanCreateServiceHostAndOpenHostWithMultipleEndpoints()
80 using (new WindsorContainer()
81 .AddFacility("wcf_facility", new WcfFacility())
82 .Register(Component.For<Operations>()
83 .CustomDependencies(new
85 number = 42,
86 serviceModel = new WcfServiceModel()
87 .AddEndpoints(
88 WcfEndpoint.ForContract<IOperations>()
89 .BoundTo(new NetTcpBinding())
90 .At("net.tcp://localhost/Operations"),
91 WcfEndpoint.ForContract<IOperationsEx>()
92 .BoundTo(new BasicHttpBinding())
93 .At("http://localhost:27198/UsingWindsor.svc")
99 IOperations client = ChannelFactory<IOperations>.CreateChannel(
100 new NetTcpBinding(), new EndpointAddress("net.tcp://localhost/Operations"));
101 Assert.AreEqual(42, client.GetValueFromConstructor());
103 IOperationsEx clientEx = ChannelFactory<IOperationsEx>.CreateChannel(
104 new BasicHttpBinding(), new EndpointAddress("http://localhost:27198/UsingWindsor.svc"));
105 clientEx.Backup();
109 [Test]
110 public void CanCreateServiceHostAndOpenHostWithRelativeEndpoints()
112 using (new WindsorContainer()
113 .AddFacility("wcf_facility", new WcfFacility())
114 .Register(Component.For<Operations>()
115 .CustomDependencies(new
117 number = 42,
118 serviceModel = new WcfServiceModel()
119 .AddBaseAddresses(
120 "net.tcp://localhost/Operations",
121 "http://localhost:27198/UsingWindsor.svc")
122 .AddEndpoints(
123 WcfEndpoint.ForContract<IOperations>()
124 .BoundTo(new NetTcpBinding()),
125 WcfEndpoint.ForContract<IOperationsEx>()
126 .BoundTo(new BasicHttpBinding())
127 .At("Extended")
132 IOperations client = ChannelFactory<IOperations>.CreateChannel(
133 new NetTcpBinding(), new EndpointAddress("net.tcp://localhost/Operations"));
134 Assert.AreEqual(42, client.GetValueFromConstructor());
136 IOperationsEx clientEx = ChannelFactory<IOperationsEx>.CreateChannel(
137 new BasicHttpBinding(), new EndpointAddress("http://localhost:27198/UsingWindsor.svc/Extended"));
138 clientEx.Backup();
142 [Test]
143 public void CanCreateServiceHostAndOpenHostWithListenAddress()
145 using (new WindsorContainer()
146 .AddFacility("wcf_facility", new WcfFacility())
147 .Register(Component.For<IOperations>().ImplementedBy<Operations>()
148 .CustomDependencies(new
150 number = 42,
151 serviceModel = new WcfServiceModel()
152 .AddEndpoints(
153 WcfEndpoint.BoundTo(new NetTcpBinding())
154 .At("urn:castle:operations")
155 .Via("net.tcp://localhost/Operations")
160 IOperations client = ChannelFactory<IOperations>.CreateChannel(
161 new NetTcpBinding(), new EndpointAddress("urn:castle:operations"),
162 new Uri("net.tcp://localhost/Operations"));
163 Assert.AreEqual(42, client.GetValueFromConstructor());