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
19 using NUnit
.Framework
;
21 using AspectSharp
.Lang
.AST
;
24 /// Summary description for ParserGlobalsTestCase.
27 public class ParserGlobalsTestCase
: ParserTestCaseBase
30 public void ParsingMixinDeclaration()
32 AspectParser parser
= CreateParser(
35 "\"customer\" : CustomerMixin" +
37 EngineConfiguration conf
= parser
.Parse();
38 Assert
.IsNotNull(conf
);
39 Assert
.IsNotNull(conf
.Mixins
);
40 Assert
.AreEqual(1, conf
.Mixins
.Count
);
41 MixinEntryDefinition def
= conf
.Mixins
[0];
42 Assert
.IsNotNull(def
);
43 Assert
.AreEqual("customer", def
.Key
);
44 Assert
.AreEqual(TargetTypeEnum
.Type
, def
.TypeReference
.TargetType
);
45 Assert
.AreEqual("CustomerMixin", def
.TypeReference
.TypeName
);
49 public void ParsingMixinDeclarationWithAssembly()
51 AspectParser parser
= CreateParser(
54 "\"customer\" : Namespace.CustomerMixin in MyAssembly" +
56 EngineConfiguration conf
= parser
.Parse();
57 Assert
.IsNotNull(conf
);
58 Assert
.IsNotNull(conf
.Mixins
);
59 Assert
.AreEqual(1, conf
.Mixins
.Count
);
60 MixinEntryDefinition def
= conf
.Mixins
[0];
61 Assert
.IsNotNull(def
);
62 Assert
.AreEqual("customer", def
.Key
);
63 Assert
.AreEqual(TargetTypeEnum
.Type
, def
.TypeReference
.TargetType
);
64 Assert
.AreEqual("Namespace.CustomerMixin", def
.TypeReference
.TypeName
);
65 Assert
.AreEqual("MyAssembly", def
.TypeReference
.AssemblyReference
.AssemblyName
);
70 public void ParsingMixinsDeclarations()
72 AspectParser parser
= CreateParser(
75 " \"key1\" : Namespace.CustomerMixin1 in MyAssembly;" +
76 " \"key2\" : Namespace.CustomerMixin2 in MyAssembly;" +
77 " \"key3\" : Namespace.CustomerMixin3 in MyAssembly" +
79 EngineConfiguration conf
= parser
.Parse();
80 Assert
.IsNotNull(conf
);
81 Assert
.IsNotNull(conf
.Mixins
);
82 Assert
.AreEqual(3, conf
.Mixins
.Count
);
84 MixinEntryDefinition def
= conf
.Mixins
[0];
85 Assert
.IsNotNull(def
);
86 Assert
.AreEqual("key1", def
.Key
);
87 Assert
.AreEqual(TargetTypeEnum
.Type
, def
.TypeReference
.TargetType
);
88 Assert
.AreEqual("Namespace.CustomerMixin1", def
.TypeReference
.TypeName
);
89 Assert
.AreEqual("MyAssembly", def
.TypeReference
.AssemblyReference
.AssemblyName
);
92 Assert
.IsNotNull(def
);
93 Assert
.AreEqual("key2", def
.Key
);
94 Assert
.AreEqual(TargetTypeEnum
.Type
, def
.TypeReference
.TargetType
);
95 Assert
.AreEqual("Namespace.CustomerMixin2", def
.TypeReference
.TypeName
);
96 Assert
.AreEqual("MyAssembly", def
.TypeReference
.AssemblyReference
.AssemblyName
);
99 Assert
.IsNotNull(def
);
100 Assert
.AreEqual("key3", def
.Key
);
101 Assert
.AreEqual(TargetTypeEnum
.Type
, def
.TypeReference
.TargetType
);
102 Assert
.AreEqual("Namespace.CustomerMixin3", def
.TypeReference
.TypeName
);
103 Assert
.AreEqual("MyAssembly", def
.TypeReference
.AssemblyReference
.AssemblyName
);
107 public void ParsingInvalidMixinsDeclarations()
111 AspectParser parser
= CreateParser(
114 " key1 : Namespace.CustomerMixin1 in MyAssembly" +
118 Assert
.Fail("Invalid language content");
127 AspectParser parser
= CreateParser(
130 " \"key1\" : Namespace.CustomerMixin1 in MyAssembly" +
134 Assert
.Fail("Invalid language content");
143 public void ParsingInterceptorDeclaration()
145 AspectParser parser
= CreateParser(
146 "interceptors \r\n" +
148 "\"customer\" : Interceptor" +
150 EngineConfiguration conf
= parser
.Parse();
151 Assert
.IsNotNull(conf
);
152 Assert
.IsNotNull(conf
.Interceptors
);
153 Assert
.AreEqual(1, conf
.Interceptors
.Count
);
154 InterceptorEntryDefinition def
= conf
.Interceptors
[0];
155 Assert
.IsNotNull(def
);
156 Assert
.AreEqual("customer", def
.Key
);
157 Assert
.AreEqual(TargetTypeEnum
.Type
, def
.TypeReference
.TargetType
);
158 Assert
.AreEqual("Interceptor", def
.TypeReference
.TypeName
);
162 public void ParsingInterceptorDeclarationWithAssembly()
164 AspectParser parser
= CreateParser(
165 "interceptors \r\n" +
167 "\"customer\" : Namespace.Interceptor in MyAssembly" +
169 EngineConfiguration conf
= parser
.Parse();
170 Assert
.IsNotNull(conf
);
171 Assert
.IsNotNull(conf
.Interceptors
);
172 Assert
.AreEqual(1, conf
.Interceptors
.Count
);
173 InterceptorEntryDefinition def
= conf
.Interceptors
[0];
174 Assert
.IsNotNull(def
);
175 Assert
.AreEqual("customer", def
.Key
);
176 Assert
.AreEqual(TargetTypeEnum
.Type
, def
.TypeReference
.TargetType
);
177 Assert
.AreEqual("Namespace.Interceptor", def
.TypeReference
.TypeName
);
178 Assert
.AreEqual("MyAssembly", def
.TypeReference
.AssemblyReference
.AssemblyName
);
182 public void ParsingInterceptorDeclarations()
184 AspectParser parser
= CreateParser(
185 "interceptors \r\n" +
187 " \"key1\" : Namespace.Interceptor1 in MyAssembly;" +
188 " \"key2\" : Namespace.Interceptor2 in MyAssembly;" +
189 " \"key3\" : Namespace.Interceptor3 in MyAssembly" +
191 EngineConfiguration conf
= parser
.Parse();
192 Assert
.IsNotNull(conf
);
193 Assert
.IsNotNull(conf
.Interceptors
);
194 Assert
.AreEqual(3, conf
.Interceptors
.Count
);
196 InterceptorEntryDefinition def
= conf
.Interceptors
[0];
197 Assert
.IsNotNull(def
);
198 Assert
.AreEqual("key1", def
.Key
);
199 Assert
.AreEqual(TargetTypeEnum
.Type
, def
.TypeReference
.TargetType
);
200 Assert
.AreEqual("Namespace.Interceptor1", def
.TypeReference
.TypeName
);
201 Assert
.AreEqual("MyAssembly", def
.TypeReference
.AssemblyReference
.AssemblyName
);
203 def
= conf
.Interceptors
[1];
204 Assert
.IsNotNull(def
);
205 Assert
.AreEqual("key2", def
.Key
);
206 Assert
.AreEqual(TargetTypeEnum
.Type
, def
.TypeReference
.TargetType
);
207 Assert
.AreEqual("Namespace.Interceptor2", def
.TypeReference
.TypeName
);
208 Assert
.AreEqual("MyAssembly", def
.TypeReference
.AssemblyReference
.AssemblyName
);
210 def
= conf
.Interceptors
[2];
211 Assert
.IsNotNull(def
);
212 Assert
.AreEqual("key3", def
.Key
);
213 Assert
.AreEqual(TargetTypeEnum
.Type
, def
.TypeReference
.TargetType
);
214 Assert
.AreEqual("Namespace.Interceptor3", def
.TypeReference
.TypeName
);
215 Assert
.AreEqual("MyAssembly", def
.TypeReference
.AssemblyReference
.AssemblyName
);
220 public void ParsingInvalidInterceptorDeclarations()
224 AspectParser parser
= CreateParser(
225 "interceptors \r\n" +
227 " key1 : Namespace.Interceptor in MyAssembly" +
231 Assert
.Fail("Invalid language content");
240 AspectParser parser
= CreateParser(
241 "interceptors \r\n" +
243 " \"key1\" : Namespace.Interceptor in MyAssembly" +
247 Assert
.Fail("Invalid language content");