1
// Copyright 2004-2008 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
18 using System
.ServiceModel
;
19 using Castle
.MicroKernel
.Registration
;
21 using Castle
.Facilities
.WcfIntegration
.Demo
;
22 using NUnit
.Framework
;
25 public class ServiceHostFixture
28 public void CanCreateServiceHost()
30 WindsorServiceHost host
= new WindsorServiceHost(
31 new WindsorContainer().Kernel
, typeof (Operations
));
32 Assert
.IsNotNull(host
);
36 public void CanCreateServiceHostAndOpenHost()
38 using (new WindsorContainer()
39 .AddFacility("wcf_facility", new WcfFacility())
40 .Register(Component
.For
<IOperations
>().ImplementedBy
<Operations
>()
41 .CustomDependencies(new
44 serviceModel
= new WcfServiceModel()
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());
59 public void CanCreateServiceHostAndOpenHostFromConfiguration()
61 using (new WindsorContainer()
62 .AddFacility("wcf_facility", new WcfFacility())
63 .Register(Component
.For
<UsingWindsor
>()
64 .CustomDependencies(new
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());
78 public void CanCreateServiceHostAndOpenHostWithMultipleEndpoints()
80 using (new WindsorContainer()
81 .AddFacility("wcf_facility", new WcfFacility())
82 .Register(Component
.For
<Operations
>()
83 .CustomDependencies(new
86 serviceModel
= new WcfServiceModel()
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"));
110 public void CanCreateServiceHostAndOpenHostWithRelativeEndpoints()
112 using (new WindsorContainer()
113 .AddFacility("wcf_facility", new WcfFacility())
114 .Register(Component
.For
<Operations
>()
115 .CustomDependencies(new
118 serviceModel
= new WcfServiceModel()
120 "net.tcp://localhost/Operations",
121 "http://localhost:27198/UsingWindsor.svc")
123 WcfEndpoint
.ForContract
<IOperations
>()
124 .BoundTo(new NetTcpBinding()),
125 WcfEndpoint
.ForContract
<IOperationsEx
>()
126 .BoundTo(new BasicHttpBinding())
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"));
143 public void CanCreateServiceHostAndOpenHostWithListenAddress()
145 using (new WindsorContainer()
146 .AddFacility("wcf_facility", new WcfFacility())
147 .Register(Component
.For
<IOperations
>().ImplementedBy
<Operations
>()
148 .CustomDependencies(new
151 serviceModel
= new WcfServiceModel()
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());