Simple impl to MockRailsEngineContext.Url
[castle.git] / Tools / DynamicProxy / Castle.DynamicProxy.Tests / MultithreadTestCase.cs
blob5ecf31742d2202b8fc3d7e6829fc878f54ac294f
1 // Copyright 2004-2007 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.DynamicProxy.Test
17 using System;
18 using System.Threading;
20 using NUnit.Framework;
22 using Castle.DynamicProxy.Test.Classes;
23 using Castle.DynamicProxy.Test.Interceptors;
26 [TestFixture]
27 public class MultithreadTestCase
29 private ManualResetEvent _startEvent = new ManualResetEvent(false);
30 private ManualResetEvent _stopEvent = new ManualResetEvent(false);
31 private SpecializedServiceClass _service;
33 private ProxyGenerator _generator;
35 [SetUp]
36 public void Init()
38 _generator = new ProxyGenerator();
41 [Test]
42 public void MultithreadTest()
44 _service = (SpecializedServiceClass) _generator.CreateClassProxy(
45 typeof(SpecializedServiceClass),
46 new ResultModifiedInvocationHandler( ) );
48 const int threadCount = 10;
50 Thread[] threads = new Thread[threadCount];
52 for(int i = 0; i < threadCount; i++)
54 threads[i] = new Thread(new ThreadStart(ExecuteMethodUntilSignal));
55 threads[i].Start();
58 _startEvent.Set();
60 Thread.CurrentThread.Join(1 * 2000);
62 _stopEvent.Set();
65 public void ExecuteMethodUntilSignal()
67 _startEvent.WaitOne(int.MaxValue, false);
69 while (!_stopEvent.WaitOne(1, false))
71 Assert.AreEqual( 44, _service.Sum( 20, 25 ) );
72 Assert.AreEqual( -6, _service.Subtract( 20, 25 ) );
73 Assert.AreEqual( true, _service.Valid );