Little code cleanup. Since WCF creates TransparentProxy that implements IDisposable...
[castle.git] / Facilities / Wcf / Castle.Facilities.WcfIntegration.Tests / WcfClientFixture.cs
blobf5430b51d2c055f5eb979e6da35cd20ebf9a666c
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.ServiceModel;
19 using Castle.Core;
20 using Castle.MicroKernel.Registration;
21 using Castle.Windsor;
22 using Castle.Facilities.WcfIntegration.Demo;
23 using NUnit.Framework;
25 [TestFixture]
26 public class WcfClientFixture
28 #region Setup/Teardown
30 [SetUp]
31 public void TestInitialize()
33 windsorContainer = new WindsorContainer()
34 .AddFacility("wcf_facility", new WcfFacility(
35 new WcfClientModel()
37 Endpoint = WcfEndpoint.ForContract<IOperations>()
38 .BoundTo(new NetTcpBinding())
39 .At("net.tcp://localhost/Operations")
40 }))
41 .Register(
42 Component.For<IOperations>().ImplementedBy<Operations>()
43 .CustomDependencies(new
45 number = 42,
46 serviceModel = new WcfServiceModel()
47 .AddEndpoints(
48 WcfEndpoint.BoundTo(new NetTcpBinding())
49 .At("net.tcp://localhost/Operations")
51 }),
52 Component.For<IAmUsingWindsor>().ImplementedBy<UsingWindsor>()
53 .CustomDependencies(new
55 number = 42,
56 serviceModel = new WcfServiceModel()
61 [TearDown]
62 public void TestCleanup()
64 windsorContainer.Dispose();
67 #endregion
69 private IWindsorContainer windsorContainer;
71 [Test]
72 public void CanResolveClientAssociatedWithChannel()
74 windsorContainer.Register(
75 Component.For<IOperations>()
76 .Named("operations")
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());
92 [Test]
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")
104 }));
106 IAmUsingWindsor client = windsorContainer.Resolve<IAmUsingWindsor>("usingWindsor");
107 Assert.AreEqual(42, client.GetValueFromWindsorConfig());
110 [Test]
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());
119 [Test]
120 public void CanResolveClientAssociatedWithChannelWithContextOverride()
122 windsorContainer.Register(
123 Component.For<IOperations>()
124 .Named("operations")
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>(
137 "operations", new
139 clientModel = new WcfClientModel()
141 Endpoint = WcfEndpoint
142 .BoundTo(new NetTcpBinding())
143 .At("net.tcp://localhost/Operations")
147 Assert.AreEqual(42, client.GetValueFromConstructor());
150 [Test]
151 public void CanResolveClientAssociatedWithChannelUsingViaAddress()
153 using (IWindsorContainer localContainer = new WindsorContainer()
154 .AddFacility("wcf_facility", new WcfFacility())
155 .Register(
156 Component.For<IOperations>().ImplementedBy<Operations>()
157 .CustomDependencies(new
159 number = 22,
160 serviceModel = new WcfServiceModel()
161 .AddEndpoints(
162 WcfEndpoint.BoundTo(new NetTcpBinding())
163 .At("urn:castle:operations")
164 .Via("net.tcp://localhost/OperationsVia")
167 Component.For<IOperations>()
168 .Named("operations")
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());