Added container accessor to Castle.Core
[castle.git] / AspectSharp / AspectSharp.Tests / OptimizationTestCase.cs
blobb12e11ac65cd2d7705386144332d188a39d23b83
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 AspectSharp.Tests
17 using System;
19 using NUnit.Framework;
21 using AspectSharp.Tests.Classes;
22 using AspectSharp.Builder;
24 /// <summary>
25 /// Summary description for OptimizationTestCase.
26 /// </summary>
27 [TestFixture]
28 public class OptimizationTestCase
30 [Test]
31 public void InterceptAll()
33 String contents = "import AspectSharp.Tests.Classes in AspectSharp.Tests " +
34 " " +
35 " aspect MyAspect for ComplexClass " +
36 " " +
37 " pointcut method|property(*)" +
38 " advice(AspectSharp.Tests.Classes.LogInvocationInterceptor)" +
39 " end" +
40 " " +
41 " end ";
43 AspectEngineBuilder builder = new AspectLanguageEngineBuilder(contents);
44 AspectEngine engine = builder.Build();
45 WrapAndInvokeEverything(engine);
48 [Test]
49 public void InterceptWithComplexSignatures()
51 String contents = "import AspectSharp.Tests.Classes in AspectSharp.Tests " +
52 " " +
53 " aspect MyAspect for ComplexClass " +
54 " " +
55 " pointcut method(* Do.*(*))" +
56 " advice(AspectSharp.Tests.Classes.LogInvocationInterceptor)" +
57 " end" +
58 " " +
59 " pointcut propertyread(*)" +
60 " advice(AspectSharp.Tests.Classes.LogInvocationInterceptor)" +
61 " end" +
62 " " +
63 " pointcut propertywrite(*)" +
64 " advice(AspectSharp.Tests.Classes.LogInvocationInterceptor)" +
65 " end" +
66 " " +
67 " end ";
69 AspectEngineBuilder builder = new AspectLanguageEngineBuilder(contents);
70 AspectEngine engine = builder.Build();
71 WrapAndInvokeEverything(engine);
74 private static void WrapAndInvokeEverything(AspectEngine engine)
76 long begin = DateTime.Now.Ticks;
78 ComplexClass instance = engine.WrapClass(typeof(ComplexClass)) as ComplexClass;
80 for(int i=0; i < 10000; i++)
82 instance.DoNothing();
83 instance.DoSomething();
84 instance.DoSomething(1);
85 instance.DoSomething(1, "hiya");
86 instance.Name = "John Johnson";
87 Assert.AreEqual( "John Johnson", instance.Name );
88 instance.Started = true;
89 Assert.IsTrue( instance.Started );
92 long end = DateTime.Now.Ticks;
93 long result = (end - begin) / 1000;
94 System.Console.WriteLine( "Execution took " + (result).ToString() + " ms " );