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 System
.ServiceModel
.Description
;
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
;
28 using NUnit
.Framework
;
31 public class WcfServiceFixture
33 #region Setup/Teardown
36 public void TestInitialize()
38 windsorContainer
= new WindsorContainer()
39 .AddFacility("wcf_facility", new WcfFacility())
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
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"));
66 public void TestCleanup()
68 windsorContainer
.Dispose();
73 private IWindsorContainer windsorContainer
;
74 private IOperations client
;
77 public void CanCallServiceAndGetValueFromWindsorConfig()
79 int result
= client
.GetValueFromConstructor();
80 Assert
.AreEqual(42, result
);
84 public void CanUseStandardDynamicProxyInterceptorsOnServices()
86 Assert
.AreEqual(0, LoggingInterceptor
.Calls
.Count
);
87 client
.GetValueFromConstructor();
88 Assert
.AreEqual(1, LoggingInterceptor
.Calls
.Count
);
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");
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();