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
;
20 using Castle
.MicroKernel
.Registration
;
22 using Castle
.Facilities
.WcfIntegration
.Demo
;
23 using NUnit
.Framework
;
26 public class WcfClientFixture
28 #region Setup/Teardown
31 public void TestInitialize()
33 windsorContainer
= new WindsorContainer()
34 .AddFacility("wcf_facility", new WcfFacility(
37 Endpoint
= WcfEndpoint
.ForContract
<IOperations
>()
38 .BoundTo(new NetTcpBinding())
39 .At("net.tcp://localhost/Operations")
42 Component
.For
<IOperations
>().ImplementedBy
<Operations
>()
43 .CustomDependencies(new
46 serviceModel
= new WcfServiceModel()
48 WcfEndpoint
.BoundTo(new NetTcpBinding())
49 .At("net.tcp://localhost/Operations")
52 Component
.For
<IAmUsingWindsor
>().ImplementedBy
<UsingWindsor
>()
53 .CustomDependencies(new
56 serviceModel
= new WcfServiceModel()
62 public void TestCleanup()
64 windsorContainer
.Dispose();
69 private IWindsorContainer windsorContainer
;
72 public void CanResolveClientAssociatedWithChannel()
74 windsorContainer
.Register(
75 Component
.For
<IOperations
>()
77 .CustomDependencies(new
79 clientModel
= new WcfClientModel()
81 Endpoint
= WcfEndpoint
82 .BoundTo(new NetTcpBinding())
83 .At("net.tcp://localhost/Operations")
88 IOperations client
= windsorContainer
.Resolve
<IOperations
>("operations");
89 Assert
.AreEqual(42, client
.GetValueFromConstructor());
93 public void CanResolveClientAssociatedWithChannelFromConfiguration()
95 windsorContainer
.Register(Component
.For
<IAmUsingWindsor
>()
96 .Named("usingWindsor")
97 .CustomDependencies(new
99 clientModel
= new WcfClientModel()
101 Endpoint
= WcfEndpoint
102 .FromConfiguration("WSHttpBinding_IAmUsingWindsor")
106 IAmUsingWindsor client
= windsorContainer
.Resolve
<IAmUsingWindsor
>("usingWindsor");
107 Assert
.AreEqual(42, client
.GetValueFromWindsorConfig());
111 public void CanResolveClientWhenListedInTheFacility()
113 windsorContainer
.Register(Component
.For
<ClassNeedingService
>());
114 ClassNeedingService component
= windsorContainer
.Resolve
<ClassNeedingService
>();
115 Assert
.IsNotNull(component
.Operations
);
116 Assert
.AreEqual(42, component
.Operations
.GetValueFromConstructor());
120 public void CanResolveClientAssociatedWithChannelWithContextOverride()
122 windsorContainer
.Register(
123 Component
.For
<IOperations
>()
125 .CustomDependencies(new
127 clientModel
= new WcfClientModel()
129 Endpoint
= WcfEndpoint
130 .BoundTo(new BasicHttpBinding())
131 .At("http://localhost/BadOperations")
136 IOperations client
= windsorContainer
.Resolve
<IOperations
>(
139 clientModel
= new WcfClientModel()
141 Endpoint
= WcfEndpoint
142 .BoundTo(new NetTcpBinding())
143 .At("net.tcp://localhost/Operations")
147 Assert
.AreEqual(42, client
.GetValueFromConstructor());
151 public void CanResolveClientAssociatedWithChannelUsingViaAddress()
153 using (IWindsorContainer localContainer
= new WindsorContainer()
154 .AddFacility("wcf_facility", new WcfFacility())
156 Component
.For
<IOperations
>().ImplementedBy
<Operations
>()
157 .CustomDependencies(new
160 serviceModel
= new WcfServiceModel()
162 WcfEndpoint
.BoundTo(new NetTcpBinding())
163 .At("urn:castle:operations")
164 .Via("net.tcp://localhost/OperationsVia")
167 Component
.For
<IOperations
>()
169 .CustomDependencies(new
171 clientModel
= new WcfClientModel()
173 Endpoint
= WcfEndpoint
174 .BoundTo(new NetTcpBinding())
175 .At("urn:castle:operations")
176 .Via("net.tcp://localhost/OperationsVia")
181 IOperations client
= localContainer
.Resolve
<IOperations
>("operations");
182 Assert
.AreEqual(22, client
.GetValueFromConstructor());