Fixed test issue - PEVerify is now called with a quoted assembly path (to allow for...
[castle.git] / Tools / Castle.DynamicProxy2 / Castle.DynamicProxy.Tests / BaseTestCaseTestCase.cs
blobaf7d12738fa4d24a81377cf86e0246a41fc0032f
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 using System.IO;
16 using System.Reflection;
17 using System.Reflection.Emit;
18 using Castle.Core.Interceptor;
20 namespace Castle.DynamicProxy.Tests
22 using System;
23 using NUnit.Framework;
25 [TestFixture]
26 public class BaseTestCaseTestCase : BasePEVerifyTestCase
28 public override void TearDown ()
30 ResetGeneratorAndBuilder(); // we call TearDown ourselves in these test cases
31 base.TearDown ();
34 [Test]
35 public void TearDown_DoesNotSaveAnything_IfNoProxyGenerated ()
37 string path = ModuleScope.DEFAULT_FILE_NAME;
38 if (File.Exists (path))
39 File.Delete (path);
41 base.TearDown();
43 Assert.IsFalse (File.Exists (path));
46 [Test]
47 public void TearDown_SavesAssembly_IfProxyGenerated ()
49 string path = ModuleScope.DEFAULT_FILE_NAME;
50 if (File.Exists (path))
51 File.Delete (path);
53 generator.CreateClassProxy (typeof (object), new StandardInterceptor());
55 base.TearDown ();
56 Assert.IsTrue (File.Exists (path));
59 [Test]
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.");
73 base.TearDown ();
76 [Test]
77 public void DisableVerification_DisablesVerificationForTestCase ()
79 DisableVerification();
80 TearDown_FindsVerificationErrors();
83 [Test]
84 public void DisableVerification_ResetInNextTestCase1 ()
86 Assert.IsFalse (IsVerificationDisabled);
87 DisableVerification();
88 Assert.IsTrue (IsVerificationDisabled);
91 [Test]
92 public void DisableVerification_ResetInNextTestCase2 ()
94 Assert.IsFalse (IsVerificationDisabled);
95 DisableVerification();
96 Assert.IsTrue (IsVerificationDisabled);