1 // Copyright 2004-2007 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 AspectSharp
.Tests
19 using NUnit
.Framework
;
21 using AspectSharp
.Tests
.Classes
;
22 using AspectSharp
.Builder
;
25 /// Summary description for OptimizationTestCase.
28 public class OptimizationTestCase
31 public void InterceptAll()
33 String contents
= "import AspectSharp.Tests.Classes in AspectSharp.Tests " +
35 " aspect MyAspect for ComplexClass " +
37 " pointcut method|property(*)" +
38 " advice(AspectSharp.Tests.Classes.LogInvocationInterceptor)" +
43 AspectEngineBuilder builder
= new AspectLanguageEngineBuilder(contents
);
44 AspectEngine engine
= builder
.Build();
45 WrapAndInvokeEverything(engine
);
49 public void InterceptWithComplexSignatures()
51 String contents
= "import AspectSharp.Tests.Classes in AspectSharp.Tests " +
53 " aspect MyAspect for ComplexClass " +
55 " pointcut method(* Do.*(*))" +
56 " advice(AspectSharp.Tests.Classes.LogInvocationInterceptor)" +
59 " pointcut propertyread(*)" +
60 " advice(AspectSharp.Tests.Classes.LogInvocationInterceptor)" +
63 " pointcut propertywrite(*)" +
64 " advice(AspectSharp.Tests.Classes.LogInvocationInterceptor)" +
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
++)
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 " );