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
.Collections
.Generic
;
19 using System
.ServiceModel
;
20 using Castle
.MicroKernel
.Registration
;
22 using Castle
.Windsor
.Installer
;
23 using Castle
.Facilities
.WcfIntegration
.Demo
;
24 using NUnit
.Framework
;
29 public class ServiceHostFixture
32 public void CanCreateServiceHostAndOpenHost()
34 using (new WindsorContainer()
35 .AddFacility("wcf_facility", new WcfFacility())
36 .Register(Component
.For
<IOperations
>().ImplementedBy
<Operations
>()
37 .CustomDependencies(new
40 serviceModel
= new WcfServiceModel()
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());
55 public void CanCreateServiceHostAndOpenHostFromConfiguration()
57 using (new WindsorContainer()
58 .AddFacility("wcf_facility", new WcfFacility())
59 .Register(Component
.For
<UsingWindsor
>()
60 .CustomDependencies(new
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());
74 public void CanCreateServiceHostAndOpenHostWithMultipleEndpoints()
76 using (new WindsorContainer()
77 .AddFacility("wcf_facility", new WcfFacility())
78 .Register(Component
.For
<Operations
>()
79 .CustomDependencies(new
82 serviceModel
= new WcfServiceModel()
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>());
106 public void CanCreateServiceHostAndOpenHostWithRelativeEndpoints()
108 using (new WindsorContainer()
109 .AddFacility("wcf_facility", new WcfFacility())
110 .Register(Component
.For
<Operations
>()
111 .CustomDependencies(new
114 serviceModel
= new WcfServiceModel()
116 "net.tcp://localhost/Operations",
117 "http://localhost:27198/UsingWindsor.svc")
119 WcfEndpoint
.ForContract
<IOperations
>()
120 .BoundTo(new NetTcpBinding()),
121 WcfEndpoint
.ForContract
<IOperationsEx
>()
122 .BoundTo(new BasicHttpBinding())
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>());
139 public void CanCreateServiceHostAndOpenHostWithListenAddress()
141 using (new WindsorContainer()
142 .AddFacility("wcf_facility", new WcfFacility())
143 .Register(Component
.For
<IOperations
>().ImplementedBy
<Operations
>()
144 .CustomDependencies(new
147 serviceModel
= new WcfServiceModel()
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());
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());