4 using System.Collections.Generic;
8 using System.Diagnostics.Contracts;
9 using System.Diagnostics;
10 using System.Reflection;
11 using System.Diagnostics.Contracts.Internal;
13 namespace MonoTests.System.Diagnostics.Contracts.Helpers {
15 public class TestContractBase {
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);
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);
36 eventField.SetValue(null, null);
40 public void TearDown() {
43 protected Type ContractExceptionType { get; private set; }