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.
16 using System
.Reflection
;
17 using System
.Reflection
.Emit
;
18 using Castle
.Core
.Interceptor
;
20 namespace Castle
.DynamicProxy
.Tests
23 using NUnit
.Framework
;
26 public class BaseTestCaseTestCase
: BasePEVerifyTestCase
28 public override void TearDown ()
30 ResetGeneratorAndBuilder(); // we call TearDown ourselves in these test cases
35 public void TearDown_DoesNotSaveAnything_IfNoProxyGenerated ()
37 string path
= ModuleScope
.DEFAULT_FILE_NAME
;
38 if (File
.Exists (path
))
43 Assert
.IsFalse (File
.Exists (path
));
47 public void TearDown_SavesAssembly_IfProxyGenerated ()
49 string path
= ModuleScope
.DEFAULT_FILE_NAME
;
50 if (File
.Exists (path
))
53 generator
.CreateClassProxy (typeof (object), new StandardInterceptor());
56 Assert
.IsTrue (File
.Exists (path
));
60 [ExpectedException(typeof (AssertionException
))]
61 public void TearDown_FindsVerificationErrors ()
63 ModuleBuilder moduleBuilder
= generator
.ProxyBuilder
.ModuleScope
.ObtainDynamicModule (true);
64 TypeBuilder invalidType
= moduleBuilder
.DefineType ("InvalidType");
65 MethodBuilder invalidMethod
= invalidType
.DefineMethod ("InvalidMethod", MethodAttributes
.Public
);
66 invalidMethod
.GetILGenerator().Emit (OpCodes
.Ldnull
); // missing RET statement
68 invalidType
.CreateType();
70 if (!IsVerificationDisabled
)
71 Console
.WriteLine ("This next test case is expected to yield a verification error.");
77 public void DisableVerification_DisablesVerificationForTestCase ()
79 DisableVerification();
80 TearDown_FindsVerificationErrors();
84 public void DisableVerification_ResetInNextTestCase1 ()
86 Assert
.IsFalse (IsVerificationDisabled
);
87 DisableVerification();
88 Assert
.IsTrue (IsVerificationDisabled
);
92 public void DisableVerification_ResetInNextTestCase2 ()
94 Assert
.IsFalse (IsVerificationDisabled
);
95 DisableVerification();
96 Assert
.IsTrue (IsVerificationDisabled
);