Missed the test project.
[castle.git] / Facilities / Wcf / Castle.Facilities.WcfIntegration.Tests / WcfServiceFixture.cs
blob402ad6c1b11603b748944aca13ad07a3b6ffc3ca
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.Collections.Generic;
19 using System.ServiceModel;
20 using System.ServiceModel.Description;
21 using Castle.Core;
22 using Castle.Core.Interceptor;
23 using Castle.Facilities.WcfIntegration.Demo;
24 using Castle.Facilities.WcfIntegration.Tests.Behaviors;
25 using Castle.MicroKernel;
26 using Castle.MicroKernel.Registration;
27 using Castle.Windsor;
28 using NUnit.Framework;
30 [TestFixture]
31 public class WcfServiceFixture
33 #region Setup/Teardown
35 [SetUp]
36 public void TestInitialize()
38 windsorContainer = new WindsorContainer()
39 .AddFacility("wcf_facility", new WcfFacility())
40 .Register(
41 Component.For<LoggingInterceptor>(),
42 Component.For<IServiceBehavior>().ImplementedBy<CallCountServiceBehavior>(),
43 Component.For<IEndpointBehavior>().ImplementedBy<UnitOfworkEndPointBehavior>(),
44 Component.For<IOperations>().ImplementedBy<Operations>()
45 .Interceptors(InterceptorReference.ForType<LoggingInterceptor>()).Anywhere
46 .CustomDependencies(new
48 number = 42,
49 serviceModel = new WcfServiceModel()
50 .AddEndpoints(new WcfEndpoint()
52 Binding = new NetTcpBinding(),
53 Address = "net.tcp://localhost/Operations"
58 LoggingInterceptor.Calls.Clear();
59 CallCountServiceBehavior.CallCount = 0;
61 client = ChannelFactory<IOperations>.CreateChannel(
62 new NetTcpBinding(), new EndpointAddress("net.tcp://localhost/Operations"));
65 [TearDown]
66 public void TestCleanup()
68 windsorContainer.Dispose();
71 #endregion
73 private IWindsorContainer windsorContainer;
74 private IOperations client;
76 [Test]
77 public void CanCallServiceAndGetValueFromWindsorConfig()
79 int result = client.GetValueFromConstructor();
80 Assert.AreEqual(42, result);
83 [Test]
84 public void CanUseStandardDynamicProxyInterceptorsOnServices()
86 Assert.AreEqual(0, LoggingInterceptor.Calls.Count);
87 client.GetValueFromConstructor();
88 Assert.AreEqual(1, LoggingInterceptor.Calls.Count);
91 [Test]
92 public void WillApplyEndPointBehaviors()
94 Assert.IsFalse(UnitOfWork.initialized, "Should be false before starting");
95 bool unitOfWorkIsInitialized_DuringCall = client.UnitOfWorkIsInitialized();
96 Assert.IsTrue(unitOfWorkIsInitialized_DuringCall);
97 Assert.IsFalse(UnitOfWork.initialized, "Should be false after call");
100 [Test]
101 public void WillApplyServiceBehaviors()
103 Assert.AreEqual(0, CallCountServiceBehavior.CallCount);
104 client.GetValueFromConstructor();
105 Assert.AreEqual(1, CallCountServiceBehavior.CallCount);
109 public class LoggingInterceptor : IInterceptor
111 public static List<string> Calls = new List<string>();
113 #region IInterceptor Members
115 public void Intercept(IInvocation invocation)
117 Calls.Add(invocation.Method.Name);
118 invocation.Proceed();
121 #endregion