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(new WindsorContainer().Kernel
, typeof (Operations
));
31 Assert
.IsNotNull(host
);
35 public void CanCreateServiceHostAndOpenHost()
37 using (new WindsorContainer()
38 .AddFacility("wcf_facility", new WcfFacility())
39 .Register(Component
.For
<IOperations
>().ImplementedBy
<Operations
>()
40 .CustomDependencies(new
43 serviceModel
= new WcfServiceModel()
44 .AddEndpoints(new WcfEndpoint()
46 Binding
= new NetTcpBinding(),
47 Address
= "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 new WcfEndpoint
<IOperations
>()
90 Binding
= new NetTcpBinding(),
91 Address
= "net.tcp://localhost/Operations"
93 new WcfEndpoint
<IOperationsEx
>()
95 Binding
= new BasicHttpBinding(),
96 Address
= "http://localhost:27198/UsingWindsor.svc"
102 IOperations client
= ChannelFactory
<IOperations
>.CreateChannel(
103 new NetTcpBinding(), new EndpointAddress("net.tcp://localhost/Operations"));
104 Assert
.AreEqual(42, client
.GetValueFromConstructor());
106 IOperationsEx clientEx
= ChannelFactory
<IOperationsEx
>.CreateChannel(
107 new BasicHttpBinding(), new EndpointAddress("http://localhost:27198/UsingWindsor.svc"));
113 public void CanCreateServiceHostAndOpenHostWithRelativeEndpoints()
115 using (new WindsorContainer()
116 .AddFacility("wcf_facility", new WcfFacility())
117 .Register(Component
.For
<Operations
>()
118 .CustomDependencies(new
121 serviceModel
= new WcfServiceModel()
123 "net.tcp://localhost/Operations",
124 "http://localhost:27198/UsingWindsor.svc")
126 new WcfEndpoint
<IOperations
>()
128 Binding
= new NetTcpBinding()
130 new WcfEndpoint
<IOperationsEx
>()
132 Binding
= new BasicHttpBinding(),
139 IOperations client
= ChannelFactory
<IOperations
>.CreateChannel(
140 new NetTcpBinding(), new EndpointAddress("net.tcp://localhost/Operations"));
141 Assert
.AreEqual(42, client
.GetValueFromConstructor());
143 IOperationsEx clientEx
= ChannelFactory
<IOperationsEx
>.CreateChannel(
144 new BasicHttpBinding(), new EndpointAddress("http://localhost:27198/UsingWindsor.svc/Extended"));