Added container accessor to Castle.Core
[castle.git] / AspectSharp / AspectSharp.Lang.Tests / ParserGlobalsTestCase.cs
blob6502f559a51da6ca520316a5ae16a65910a74721
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.Lang.Tests
17 using System;
19 using NUnit.Framework;
21 using AspectSharp.Lang.AST;
23 /// <summary>
24 /// Summary description for ParserGlobalsTestCase.
25 /// </summary>
26 [TestFixture]
27 public class ParserGlobalsTestCase : ParserTestCaseBase
29 [Test]
30 public void ParsingMixinDeclaration()
32 AspectParser parser = CreateParser(
33 "mixins \r\n" +
34 "[" +
35 "\"customer\" : CustomerMixin" +
36 "]");
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);
48 [Test]
49 public void ParsingMixinDeclarationWithAssembly()
51 AspectParser parser = CreateParser(
52 "mixins \r\n" +
53 "[" +
54 "\"customer\" : Namespace.CustomerMixin in MyAssembly" +
55 "]");
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);
69 [Test]
70 public void ParsingMixinsDeclarations()
72 AspectParser parser = CreateParser(
73 "mixins \r\n" +
74 "[" +
75 " \"key1\" : Namespace.CustomerMixin1 in MyAssembly;" +
76 " \"key2\" : Namespace.CustomerMixin2 in MyAssembly;" +
77 " \"key3\" : Namespace.CustomerMixin3 in MyAssembly" +
78 "]");
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);
91 def = conf.Mixins[1];
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);
98 def = conf.Mixins[2];
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);
106 [Test]
107 public void ParsingInvalidMixinsDeclarations()
111 AspectParser parser = CreateParser(
112 "mixins \r\n" +
113 "[" +
114 " key1 : Namespace.CustomerMixin1 in MyAssembly" +
115 "]");
116 parser.Parse();
118 Assert.Fail("Invalid language content");
120 catch(Exception)
122 // Excepted
127 AspectParser parser = CreateParser(
128 "mixins \r\n" +
129 "[" +
130 " \"key1\" : Namespace.CustomerMixin1 in MyAssembly" +
131 "");
132 parser.Parse();
134 Assert.Fail("Invalid language content");
136 catch(Exception)
138 // Excepted
142 [Test]
143 public void ParsingInterceptorDeclaration()
145 AspectParser parser = CreateParser(
146 "interceptors \r\n" +
147 "[" +
148 "\"customer\" : Interceptor" +
149 "]");
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);
161 [Test]
162 public void ParsingInterceptorDeclarationWithAssembly()
164 AspectParser parser = CreateParser(
165 "interceptors \r\n" +
166 "[" +
167 "\"customer\" : Namespace.Interceptor in MyAssembly" +
168 "]");
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);
181 [Test]
182 public void ParsingInterceptorDeclarations()
184 AspectParser parser = CreateParser(
185 "interceptors \r\n" +
186 "[" +
187 " \"key1\" : Namespace.Interceptor1 in MyAssembly;" +
188 " \"key2\" : Namespace.Interceptor2 in MyAssembly;" +
189 " \"key3\" : Namespace.Interceptor3 in MyAssembly" +
190 "]");
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);
219 [Test]
220 public void ParsingInvalidInterceptorDeclarations()
224 AspectParser parser = CreateParser(
225 "interceptors \r\n" +
226 "[" +
227 " key1 : Namespace.Interceptor in MyAssembly" +
228 "]");
229 parser.Parse();
231 Assert.Fail("Invalid language content");
233 catch(Exception)
235 // Excepted
240 AspectParser parser = CreateParser(
241 "interceptors \r\n" +
242 "[" +
243 " \"key1\" : Namespace.Interceptor in MyAssembly" +
244 "");
245 parser.Parse();
247 Assert.Fail("Invalid language content");
249 catch(Exception)
251 // Excepted