Merge pull request #200 from ch5oh/master
[mono.git] / mcs / class / corlib / Test / System.Diagnostics.Contracts / Helpers / TestContractBase.cs
1 #if NET_4_0
2
3 using System;
4 using System.Collections.Generic;
5 using System.Linq;
6 using System.Text;
7 using NUnit.Framework;
8 using System.Diagnostics.Contracts;
9 using System.Diagnostics;
10 using System.Reflection;
11 using System.Diagnostics.Contracts.Internal;
12
13 namespace MonoTests.System.Diagnostics.Contracts.Helpers {
14
15         public class TestContractBase {
16
17                 protected TestContractBase() {
18                         // Get the type of System.Diagnostics.Contracts.ContractException
19                         // Have to do this differently depending on how the test is being run.
20                         this.ContractExceptionType = Type.GetType("System.Diagnostics.Contracts.ContractException");
21                         if (this.ContractExceptionType == null) {
22                                 // Special code for when Contracts namespace is not in CorLib
23                                 var mGetContractExceptionType = typeof (Contract).GetMethod ("GetContractExceptionType", BindingFlags.NonPublic | BindingFlags.Static);
24                                 this.ContractExceptionType = (Type) mGetContractExceptionType.Invoke (null, null);
25                         }
26                 }
27
28                 [SetUp]
29                 public void Setup() {
30                         // Remove all event handlers from Contract.ContractFailed
31                         var eventField = typeof(Contract).GetField("ContractFailed", BindingFlags.Static | BindingFlags.NonPublic);
32                         if (eventField == null) {
33                                 // But in MS.NET it's done this way.
34                                 eventField = typeof(ContractHelper).GetField("contractFailedEvent", BindingFlags.Static | BindingFlags.NonPublic);
35                         }
36                         eventField.SetValue(null, null);
37                 }
38
39                 [TearDown]
40                 public void TearDown() {
41                 }
42
43                 protected Type ContractExceptionType { get; private set; }
44
45         }
46 }
47
48 #endif