public void Test() { InstrumentedAssembly instrumentedAssembly; TypeDefinition typeDefinition; if (_methodToInstrument != null) { var methodDefinition = _methodToInstrument.ToDefinition(); typeDefinition = methodDefinition?.DeclaringType; instrumentedAssembly = methodDefinition.Instrument(); var il = new ILFormatter(false).FormatMethodBody(methodDefinition); il.NormalizeLineEndings().Should().Be(ExpectedIL.NormalizeLineEndings()); } else { typeDefinition = _typeToInstrument.ToDefinition(); instrumentedAssembly = typeDefinition.Instrument(); var il = new ILFormatter(false).FormatType(typeDefinition); il.NormalizeLineEndings().Should().Be(ExpectedIL.NormalizeLineEndings()); } var instrumentedInstructions = instrumentedAssembly.SourceFiles .SelectMany(kv => kv.Value.Instructions) .ToArray(); if (ExpectedInstructions != null) { instrumentedInstructions.Should().BeEquivalentTo(ExpectedInstructions); } var instrumentedType = typeDefinition.Load(); var instrumentedTestType = instrumentedType.Assembly.GetType(GetType().FullName); var functionalTestMethod = instrumentedTestType.GetMethod(nameof(FunctionalTest)); HitContext.Current = new HitContext("Assembly", "Class", "Method"); var instrumentedTest = Activator.CreateInstance(instrumentedTestType); functionalTestMethod.Invoke(instrumentedTest, new object[0]); HitContext.Current.Hits.Should().BeEquivalentTo(ExpectedHits); }