Removed WindsorServiceHost and pushed responsibility into the ServiceHostBuilder...
[castle.git] / Facilities / Wcf / Castle.Facilities.WcfIntegration.Tests / ServiceHostFixture.cs
blob74b2878b3a96fccb468633fe8569cf92a5f9b9be
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.Collections.Generic;
19 using System.ServiceModel;
20 using Castle.MicroKernel.Registration;
21 using Castle.Windsor;
22 using Castle.Windsor.Installer;
23 using Castle.Facilities.WcfIntegration.Demo;
24 using NUnit.Framework;
26 #if DOTNET35
28 [TestFixture]
29 public class ServiceHostFixture
31 [Test]
32 public void CanCreateServiceHostAndOpenHost()
34 using (new WindsorContainer()
35 .AddFacility("wcf_facility", new WcfFacility())
36 .Register(Component.For<IOperations>().ImplementedBy<Operations>()
37 .CustomDependencies(new
39 number = 42,
40 serviceModel = new WcfServiceModel()
41 .AddEndpoints(
42 WcfEndpoint.BoundTo(new NetTcpBinding())
43 .At("net.tcp://localhost/Operations")
48 IOperations client = ChannelFactory<IOperations>.CreateChannel(
49 new NetTcpBinding(), new EndpointAddress("net.tcp://localhost/Operations"));
50 Assert.AreEqual(42, client.GetValueFromConstructor());
54 [Test]
55 public void CanCreateServiceHostAndOpenHostFromConfiguration()
57 using (new WindsorContainer()
58 .AddFacility("wcf_facility", new WcfFacility())
59 .Register(Component.For<UsingWindsor>()
60 .CustomDependencies(new
62 number = 42,
63 serviceModel = new WcfServiceModel()
67 IAmUsingWindsor client = ChannelFactory<IAmUsingWindsor>.CreateChannel(
68 new BasicHttpBinding(), new EndpointAddress("http://localhost:27198/UsingWindsor.svc"));
69 Assert.AreEqual(42, client.GetValueFromWindsorConfig());
73 [Test]
74 public void CanCreateServiceHostAndOpenHostWithMultipleEndpoints()
76 using (new WindsorContainer()
77 .AddFacility("wcf_facility", new WcfFacility())
78 .Register(Component.For<Operations>()
79 .CustomDependencies(new
81 number = 42,
82 serviceModel = new WcfServiceModel()
83 .AddEndpoints(
84 WcfEndpoint.ForContract<IOperations>()
85 .BoundTo(new NetTcpBinding())
86 .At("net.tcp://localhost/Operations"),
87 WcfEndpoint.ForContract<IOperationsEx>()
88 .BoundTo(new BasicHttpBinding())
89 .At("http://localhost:27198/UsingWindsor.svc")
95 IOperations client = ChannelFactory<IOperations>.CreateChannel(
96 new NetTcpBinding(), new EndpointAddress("net.tcp://localhost/Operations"));
97 Assert.AreEqual(42, client.GetValueFromConstructor());
99 IOperationsEx clientEx = ChannelFactory<IOperationsEx>.CreateChannel(
100 new BasicHttpBinding(), new EndpointAddress("http://localhost:27198/UsingWindsor.svc"));
101 clientEx.Backup(new Dictionary<string, object>());
105 [Test]
106 public void CanCreateServiceHostAndOpenHostWithRelativeEndpoints()
108 using (new WindsorContainer()
109 .AddFacility("wcf_facility", new WcfFacility())
110 .Register(Component.For<Operations>()
111 .CustomDependencies(new
113 number = 42,
114 serviceModel = new WcfServiceModel()
115 .AddBaseAddresses(
116 "net.tcp://localhost/Operations",
117 "http://localhost:27198/UsingWindsor.svc")
118 .AddEndpoints(
119 WcfEndpoint.ForContract<IOperations>()
120 .BoundTo(new NetTcpBinding()),
121 WcfEndpoint.ForContract<IOperationsEx>()
122 .BoundTo(new BasicHttpBinding())
123 .At("Extended")
128 IOperations client = ChannelFactory<IOperations>.CreateChannel(
129 new NetTcpBinding(), new EndpointAddress("net.tcp://localhost/Operations"));
130 Assert.AreEqual(42, client.GetValueFromConstructor());
132 IOperationsEx clientEx = ChannelFactory<IOperationsEx>.CreateChannel(
133 new BasicHttpBinding(), new EndpointAddress("http://localhost:27198/UsingWindsor.svc/Extended"));
134 clientEx.Backup(new Dictionary<string, object>());
138 [Test]
139 public void CanCreateServiceHostAndOpenHostWithListenAddress()
141 using (new WindsorContainer()
142 .AddFacility("wcf_facility", new WcfFacility())
143 .Register(Component.For<IOperations>().ImplementedBy<Operations>()
144 .CustomDependencies(new
146 number = 42,
147 serviceModel = new WcfServiceModel()
148 .AddEndpoints(
149 WcfEndpoint.BoundTo(new NetTcpBinding())
150 .At("urn:castle:operations")
151 .Via("net.tcp://localhost/Operations")
156 IOperations client = ChannelFactory<IOperations>.CreateChannel(
157 new NetTcpBinding(), new EndpointAddress("urn:castle:operations"),
158 new Uri("net.tcp://localhost/Operations"));
159 Assert.AreEqual(42, client.GetValueFromConstructor());
163 [Test]
164 public void CanCreateServiceHostAndOpenHostFromXmlConfiguration()
166 using (new WindsorContainer()
167 .Install(Configuration.FromXmlFile("..\\..\\ConfigureServices.xml")))
169 IAmUsingWindsor client = ChannelFactory<IAmUsingWindsor>.CreateChannel(
170 new BasicHttpBinding(), new EndpointAddress("http://localhost:27198/UsingWindsor.svc"));
171 Assert.AreEqual(42, client.GetValueFromWindsorConfig());
175 #endif // DOTNET35