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
20 using NUnit
.Framework
;
22 using AspectSharp
.Lang
.AST
;
23 using AspectSharp
.Lang
.Steps
;
24 using AspectSharp
.Lang
.Steps
.Semantic
;
27 /// Summary description for SemanticAnalizerTestCase.
30 public class SemanticAnalizerTestCase
: ParserTestCaseBase
33 public void InvalidMixinsDeclaration()
35 String content
= "mixins [ \"\" : MyType in MyAssemblye ]";
37 Analize( CreateEngineConfiguration( content
) );
38 Assert
.IsTrue(_context
.HasErrors
);
39 AssertOutput("A key must be specified to identify the type in the map;");
43 public void InvalidInterceptorsDeclaration()
45 String content
= "interceptors [ \"\" : MyType in MyAssemblye ]";
47 Analize( CreateEngineConfiguration( content
) );
48 Assert
.IsTrue(_context
.HasErrors
);
49 AssertOutput("A key must be specified to identify the type in the map;");
53 public void AspectsWithSameName()
55 String content
= "aspect McBrother for X end aspect McBrother for Y end";
57 Analize( CreateEngineConfiguration( content
) );
58 Assert
.IsTrue(_context
.HasErrors
);
59 AssertOutput("The name given to an aspect must be unique;");
63 public void IncludingTheSameMixinTwice()
65 String content
= "aspect McBrother for X " +
71 Analize( CreateEngineConfiguration( content
) );
72 Assert
.IsTrue(_context
.HasErrors
);
73 AssertOutput("You shouldn't include the same mixin more than one time;");
77 public void CorrectIncludeUsage()
79 String content
= "aspect McBrother for X " +
84 Analize( CreateEngineConfiguration( content
) );
85 Assert
.IsFalse(_context
.HasErrors
);
89 public void DuplicatePointcuts()
91 String content
= "aspect McBrother for X " +
92 " pointcut method(*) " +
95 " pointcut method(*) " +
99 Analize( CreateEngineConfiguration( content
) );
100 Assert
.IsTrue(_context
.HasErrors
);
101 AssertOutput("Duplicated pointcut definition found;");
105 public void DuplicatePointcutsWithName()
107 String content
= "aspect McBrother for X " +
108 " pointcut method(* Name) " +
111 " pointcut method(* Name) " +
115 Analize( CreateEngineConfiguration( content
) );
116 Assert
.IsTrue(_context
.HasErrors
);
117 AssertOutput("Duplicated pointcut definition found;");
121 public void DuplicatePointcutsWithNameAndRetType()
123 String content
= "aspect McBrother for X " +
124 " pointcut method(string Name) " +
127 " pointcut method(String Name) " +
131 Analize( CreateEngineConfiguration( content
) );
132 Assert
.IsTrue(_context
.HasErrors
);
133 AssertOutput("Duplicated pointcut definition found;");
137 public void DuplicatePointcutsWithNameArgumentsAndRetType()
139 String content
= "aspect McBrother for X " +
140 " pointcut method(string Name(string, int)) " +
143 " pointcut method(String Name(string, int)) " +
147 Analize( CreateEngineConfiguration( content
) );
148 Assert
.IsTrue(_context
.HasErrors
);
149 AssertOutput("Duplicated pointcut definition found;");
153 public void ValidPointcutsWithNameArgumentsAndRetType()
155 String content
= "aspect McBrother for X " +
156 " pointcut method(string Name(string, int)) " +
159 " pointcut method(String Name(int, int)) " +
163 Analize( CreateEngineConfiguration( content
) );
164 Assert
.IsFalse(_context
.HasErrors
);
168 public void ValidPointcutsWithName()
170 String content
= "aspect McBrother for X " +
171 " pointcut method(* Name(string, int)) " +
174 " pointcut method(* Name()) " +
178 Analize( CreateEngineConfiguration( content
) );
179 Assert
.IsFalse(_context
.HasErrors
);
183 public void InvalidPointcutDeclaration()
185 String content
= "aspect McBrother for X " +
186 " pointcut property|propertyread(*) " +
190 Analize( CreateEngineConfiguration( content
) );
191 Assert
.IsTrue(_context
.HasErrors
);
192 AssertOutput("Meaningless declaration. A pointcut to a property can't be combined with property read or write. This is implied;");
196 public void DuplicateInterceptorsInPointcut()
198 String content
= "aspect McBrother for X " +
199 " pointcut property(* Name) " +
201 " advice(Interceptors.SecurityInterceptor in MyAssembly) " +
202 " advice(Interceptors.SecurityInterceptor in MyAssembly) " +
207 Analize( CreateEngineConfiguration( content
) );
208 Assert
.IsTrue(_context
.HasErrors
);
209 AssertOutput("Duplicated advices found;");
212 protected EngineConfiguration
CreateEngineConfiguration(String content
)
214 AspectParser parser
= base.CreateParser(content
);
215 return parser
.Parse();
218 protected SemanticAnalizerStep
Analize(EngineConfiguration conf
)
220 return Analize(conf
, null);
223 protected SemanticAnalizerStep
Analize(EngineConfiguration conf
, IStep next
)
225 SemanticAnalizerStep analizer
= new SemanticAnalizerStep();
226 analizer
.Next
= next
;
227 _context
= new Context();
228 _context
.Error
+= new ErrorDelegate(OnError
);
229 analizer
.Process(_context
, conf
);