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 Castle
.DynamicProxy
.Tests
19 using System
.Reflection
;
20 using System
.Reflection
.Emit
;
21 using Castle
.Core
.Interceptor
;
22 using NUnit
.Framework
;
25 public class BaseTestCaseTestCase
: BasePEVerifyTestCase
27 public override void TearDown ()
29 ResetGeneratorAndBuilder(); // we call TearDown ourselves in these test cases
34 public void TearDown_DoesNotSaveAnything_IfNoProxyGenerated ()
36 string path
= ModuleScope
.DEFAULT_FILE_NAME
;
37 if (File
.Exists (path
))
42 Assert
.IsFalse (File
.Exists (path
));
46 public void TearDown_SavesAssembly_IfProxyGenerated ()
48 string path
= ModuleScope
.DEFAULT_FILE_NAME
;
49 if (File
.Exists (path
))
52 generator
.CreateClassProxy (typeof (object), new StandardInterceptor());
55 Assert
.IsTrue (File
.Exists (path
));
59 [ExpectedException(typeof (AssertionException
))]
60 public void TearDown_FindsVerificationErrors ()
62 ModuleBuilder moduleBuilder
= generator
.ProxyBuilder
.ModuleScope
.ObtainDynamicModule (true);
63 TypeBuilder invalidType
= moduleBuilder
.DefineType ("InvalidType");
64 MethodBuilder invalidMethod
= invalidType
.DefineMethod ("InvalidMethod", MethodAttributes
.Public
);
65 invalidMethod
.GetILGenerator().Emit (OpCodes
.Ldnull
); // missing RET statement
67 invalidType
.CreateType();
69 if (!IsVerificationDisabled
)
70 Console
.WriteLine ("This next test case is expected to yield a verification error.");
76 public void DisableVerification_DisablesVerificationForTestCase ()
78 DisableVerification();
79 TearDown_FindsVerificationErrors();
83 public void DisableVerification_ResetInNextTestCase1 ()
85 Assert
.IsFalse (IsVerificationDisabled
);
86 DisableVerification();
87 Assert
.IsTrue (IsVerificationDisabled
);
91 public void DisableVerification_ResetInNextTestCase2 ()
93 Assert
.IsFalse (IsVerificationDisabled
);
94 DisableVerification();
95 Assert
.IsTrue (IsVerificationDisabled
);