Somehow missed this with earlier checkin of fluent interface.
[castle.git] / Tools / Castle.DynamicProxy2 / Castle.DynamicProxy.Tests / BaseTestCaseTestCase.cs
bloba02bdf80848c601de2c96d8f1a54977a13874644
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 Castle.DynamicProxy.Tests
17 using System;
18 using System.IO;
19 using System.Reflection;
20 using System.Reflection.Emit;
21 using Castle.Core.Interceptor;
22 using NUnit.Framework;
24 [TestFixture]
25 public class BaseTestCaseTestCase : BasePEVerifyTestCase
27 public override void TearDown ()
29 ResetGeneratorAndBuilder(); // we call TearDown ourselves in these test cases
30 base.TearDown ();
33 [Test]
34 public void TearDown_DoesNotSaveAnything_IfNoProxyGenerated ()
36 string path = ModuleScope.DEFAULT_FILE_NAME;
37 if (File.Exists (path))
38 File.Delete (path);
40 base.TearDown();
42 Assert.IsFalse (File.Exists (path));
45 [Test]
46 public void TearDown_SavesAssembly_IfProxyGenerated ()
48 string path = ModuleScope.DEFAULT_FILE_NAME;
49 if (File.Exists (path))
50 File.Delete (path);
52 generator.CreateClassProxy (typeof (object), new StandardInterceptor());
54 base.TearDown ();
55 Assert.IsTrue (File.Exists (path));
58 [Test]
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.");
72 base.TearDown ();
75 [Test]
76 public void DisableVerification_DisablesVerificationForTestCase ()
78 DisableVerification();
79 TearDown_FindsVerificationErrors();
82 [Test]
83 public void DisableVerification_ResetInNextTestCase1 ()
85 Assert.IsFalse (IsVerificationDisabled);
86 DisableVerification();
87 Assert.IsTrue (IsVerificationDisabled);
90 [Test]
91 public void DisableVerification_ResetInNextTestCase2 ()
93 Assert.IsFalse (IsVerificationDisabled);
94 DisableVerification();
95 Assert.IsTrue (IsVerificationDisabled);