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
.Lang
.Tests
.Types
19 using NUnit
.Framework
;
21 using AspectSharp
.Lang
.AST
;
22 using AspectSharp
.Lang
.Steps
;
23 using AspectSharp
.Lang
.Steps
.Semantic
;
24 using AspectSharp
.Lang
.Steps
.Types
;
25 using AspectSharp
.Lang
.Tests
.Types
.Mixins
;
26 using AspectSharp
.Lang
.Tests
.Types
.Matcher
;
29 /// Summary description for ResolveTypesStepTestCase.
32 public class ResolveTypesStepTestCase
: ParserTestCaseBase
35 public void AssembliesResolved()
37 String content
= "import System.Collection in System";
39 EngineConfiguration conf
= ProcessContent(content
);
40 Assert
.IsFalse(_context
.HasErrors
);
42 foreach(ImportDirective import
in conf
.Imports
)
44 Assert
.IsNotNull( import
.AssemblyReference
);
45 Assert
.IsNotNull( import
.AssemblyReference
.ResolvedAssembly
);
50 public void MixinResolvedFullTypeName()
52 String content
= "mixins \r\n" +
54 "\"customer\" : System.Collections.ArrayList" +
57 EngineConfiguration conf
= ProcessContent(content
);
58 Assert
.IsFalse(_context
.HasErrors
);
59 MixinEntryDefinition mixin
= conf
.Mixins
[0];
60 Assert
.IsNotNull( mixin
.Key
);
61 Assert
.IsNotNull( mixin
.TypeReference
);
62 Assert
.IsNotNull( mixin
.TypeReference
.ResolvedType
);
63 Assert
.AreEqual( typeof(System
.Collections
.ArrayList
), mixin
.TypeReference
.ResolvedType
);
67 public void MixinResolvedUsingImport()
69 String content
= "import System.Collections " +
72 "\"customer\" : ArrayList" +
75 EngineConfiguration conf
= ProcessContent(content
);
76 Assert
.IsFalse(_context
.HasErrors
);
77 MixinEntryDefinition mixin
= conf
.Mixins
[0];
78 Assert
.IsNotNull( mixin
.Key
);
79 Assert
.IsNotNull( mixin
.TypeReference
);
80 Assert
.IsNotNull( mixin
.TypeReference
.ResolvedType
);
81 Assert
.AreEqual( typeof(System
.Collections
.ArrayList
), mixin
.TypeReference
.ResolvedType
);
85 public void MixinResolvedFullTypeNameAndAssembly()
87 String content
= " " +
90 "\"customer\" : AspectSharp.Lang.Tests.Types.Mixins.MockMixin in AspectSharp.Lang.Tests" +
93 EngineConfiguration conf
= ProcessContent(content
);
94 Assert
.IsFalse(_context
.HasErrors
);
95 MixinEntryDefinition mixin
= conf
.Mixins
[0];
96 Assert
.IsNotNull( mixin
.Key
);
97 Assert
.IsNotNull( mixin
.TypeReference
);
98 Assert
.IsNotNull( mixin
.TypeReference
.ResolvedType
);
99 Assert
.AreEqual( typeof(MockMixin
), mixin
.TypeReference
.ResolvedType
);
103 public void GlobalsCorrectlyReferenced()
105 String content
= " " +
106 "interceptors \r\n" +
108 "\"customer\" : System.Collections.Hashtable" +
112 "\"customer\" : AspectSharp.Lang.Tests.Types.Mixins.MockMixin in AspectSharp.Lang.Tests" +
115 "aspect McBrother for System.Collections.ArrayList " +
117 " include \"customer\"" +
119 " pointcut method(*)" +
120 " advice(\"customer\")" +
126 EngineConfiguration conf
= ProcessContent(content
);
127 Assert
.IsFalse(_context
.HasErrors
);
129 AspectDefinition aspect
= conf
.Aspects
[0];
130 MixinDefinition mixin
= aspect
.Mixins
[0];
131 InterceptorDefinition interceptor
= aspect
.PointCuts
[0].Advices
[0];
133 Assert
.IsNotNull( mixin
.TypeReference
);
134 Assert
.IsNotNull( mixin
.TypeReference
.ResolvedType
);
135 Assert
.AreEqual( typeof(MockMixin
), mixin
.TypeReference
.ResolvedType
);
137 Assert
.IsNotNull( interceptor
.TypeReference
);
138 Assert
.IsNotNull( interceptor
.TypeReference
.ResolvedType
);
139 Assert
.AreEqual( typeof(System
.Collections
.Hashtable
), interceptor
.TypeReference
.ResolvedType
);
143 public void AspectTarget()
145 String content
= "" +
146 "aspect McBrother for AspectSharp.Lang.Tests.Types.Mixins.MockMixin in AspectSharp.Lang.Tests " +
151 EngineConfiguration conf
= ProcessContent(content
);
152 Assert
.IsFalse(_context
.HasErrors
);
154 AspectDefinition aspect
= conf
.Aspects
[0];
156 Assert
.IsNotNull( aspect
.TargetType
.SingleType
);
157 Assert
.IsNotNull( aspect
.TargetType
.SingleType
.ResolvedType
);
158 Assert
.AreEqual( typeof(MockMixin
), aspect
.TargetType
.SingleType
.ResolvedType
);
162 public void AspectTargetingNamespace()
164 String content
= "" +
165 "aspect McBrother for [AspectSharp.Lang.Tests.Types.Mixins] " +
170 EngineConfiguration conf
= ProcessContent(content
);
171 Assert
.IsFalse(_context
.HasErrors
);
173 AspectDefinition aspect
= conf
.Aspects
[0];
175 Assert
.AreEqual( TargetStrategyEnum
.Namespace
, aspect
.TargetType
.TargetStrategy
);
176 Assert
.AreEqual( "AspectSharp.Lang.Tests.Types.Mixins", aspect
.TargetType
.NamespaceRoot
);
177 Assert
.AreEqual( 0, aspect
.TargetType
.Excludes
.Count
);
178 Assert
.IsNull( aspect
.TargetType
.SingleType
);
182 public void AspectTargetingNamespaceWithExcludes()
184 String content
= "import System.Collections " +
185 "aspect McBrother for [System.Collections excludes(Stack) ] " +
190 EngineConfiguration conf
= ProcessContent(content
);
191 Assert
.IsFalse(_context
.HasErrors
);
193 AspectDefinition aspect
= conf
.Aspects
[0];
195 Assert
.AreEqual( TargetStrategyEnum
.Namespace
, aspect
.TargetType
.TargetStrategy
);
196 Assert
.AreEqual( "System.Collections", aspect
.TargetType
.NamespaceRoot
);
197 Assert
.AreEqual( 1, aspect
.TargetType
.Excludes
.Count
);
199 TypeReference typeRef
= aspect
.TargetType
.Excludes
[0];
200 Assert
.AreEqual( typeof(System
.Collections
.Stack
), typeRef
.ResolvedType
);
204 public void AspectTargetingNamespaceWithMoreExcludes()
206 String content
= "import System.Collections " +
207 "aspect McBrother for [System.Collections excludes(Stack; ArrayList) ] " +
212 EngineConfiguration conf
= ProcessContent(content
);
213 Assert
.IsFalse(_context
.HasErrors
);
215 AspectDefinition aspect
= conf
.Aspects
[0];
217 Assert
.AreEqual( TargetStrategyEnum
.Namespace
, aspect
.TargetType
.TargetStrategy
);
218 Assert
.AreEqual( "System.Collections", aspect
.TargetType
.NamespaceRoot
);
219 Assert
.AreEqual( 2, aspect
.TargetType
.Excludes
.Count
);
221 TypeReference typeRef
= aspect
.TargetType
.Excludes
[0];
222 Assert
.AreEqual( typeof(System
.Collections
.Stack
), typeRef
.ResolvedType
);
223 typeRef
= aspect
.TargetType
.Excludes
[1];
224 Assert
.AreEqual( typeof(System
.Collections
.ArrayList
), typeRef
.ResolvedType
);
228 public void AspectTargetingCustom()
230 String content
= "" +
231 "aspect McBrother for [ customMatcher(AspectSharp.Lang.Tests.Types.Matcher.ValidMatcher) ] " +
236 EngineConfiguration conf
= ProcessContent(content
);
237 Assert
.IsFalse(_context
.HasErrors
);
239 AspectDefinition aspect
= conf
.Aspects
[0];
241 Assert
.AreEqual( TargetStrategyEnum
.Custom
, aspect
.TargetType
.TargetStrategy
);
242 Assert
.IsNotNull( aspect
.TargetType
.CustomMatcherType
);
243 Assert
.IsNotNull( aspect
.TargetType
.CustomMatcherType
.ResolvedType
);
244 Assert
.AreEqual( typeof(ValidMatcher
), aspect
.TargetType
.CustomMatcherType
.ResolvedType
);
248 public void AspectTargetingAssignable()
250 String content
= "" +
251 "aspect McBrother for [ assignableFrom(System.Collections.IList) ] " +
256 EngineConfiguration conf
= ProcessContent(content
);
257 Assert
.IsFalse(_context
.HasErrors
);
259 AspectDefinition aspect
= conf
.Aspects
[0];
261 Assert
.AreEqual( TargetStrategyEnum
.Assignable
, aspect
.TargetType
.TargetStrategy
);
262 Assert
.IsNotNull( aspect
.TargetType
.AssignType
);
263 Assert
.IsNotNull( aspect
.TargetType
.AssignType
.ResolvedType
);
264 Assert
.AreEqual( typeof(System
.Collections
.IList
), aspect
.TargetType
.AssignType
.ResolvedType
);
267 protected override void AddSteps(StepChainBuilder chain
)
269 chain
.AddStep(new SemanticAnalizerStep());
270 chain
.AddStep(new ResolveTypesStep());