public void InterceptAllStaticMethodCalls() { // get mutable test assembly // add sharpmockdelegatetypes assembly reference // load referenced assemblies into host // scan for interception specifications // add interception targets // replace specified static method calls // save assembly var pipeline = new PostCompilerPipeline(); pipeline.AddStep(new GetMutableTargetAssembly()); pipeline.AddStep(new AddReferenceToSharpMockTypesAssembly()); pipeline.AddStep(new LoadReferencesIntoHost()); pipeline.AddStep(new ScanForStaticMethods()); pipeline.AddStep(new AddInterceptionTargetsToAssembly()); pipeline.AddStep(new ReplaceStaticMethodCalls()); pipeline.AddStep(new SaveTargetAssembly()); var ctx = new PostCompilerContext(); ctx.Args = postCompilerArgs; ctx.Host = host; ctx.Log = log; ctx.SharpMockCore = sharpMockCore; ctx.SharpMockDelegateTypes = sharpMockDelegateTypes; ctx.Registry = new ReplacementRegistry(log); pipeline.Execute(ctx); }
public void Execute(PostCompilerContext context) { host = context.Host; log = context.Log; registry = context.Registry; fakeNamespace = new FakeNamespace(context.AssemblyToAlter, host, log); AddInterceptionTargets(); }
public void Execute(PostCompilerContext context) { context.Log.WriteInfo("Executing PostCompilerPipeline."); foreach (var step in steps) { context.Log.WriteTrace("Executing step '{0}'.", step.GetType().Name); step.Execute(context); } }
public void Execute(PostCompilerContext context) { var specAssembly = Path.GetFileNameWithoutExtension(context.Args.TestAssemblyPath); var autoSpecs = String.Format("{0}.Fluent.SharpMock.SerializedSpecifications.xml", specAssembly); var serializer = new ReplaceableCodeInfoSerializer( Path.GetDirectoryName(context.Args.TestAssemblyPath)); var replaceableAssignments = context.Registry.GetRegisteredReferences(ReplaceableReferenceTypes.FieldAssignment); var replaceableAccessors = context.Registry.GetRegisteredReferences(ReplaceableReferenceTypes.FieldAccessor); var replaceableMethods = context.Registry.GetRegisteredReferences(ReplaceableReferenceTypes.Method); var replaceableCode = new ReplaceableCodeInfo(); replaceableCode.Methods = replaceableMethods.As<ReplaceableMethodInfo>(); replaceableCode.FieldAccessors = replaceableAccessors.As<ReplaceableFieldInfo>(); replaceableCode.FieldAssignments = replaceableAssignments.As<ReplaceableFieldInfo>(); serializer.SerializeSpecifications(autoSpecs, replaceableCode); SerializeExplicitSpecifications(context.Args.TestAssemblyPath); }
public void Execute(PostCompilerContext context) { var replacer = new CodeUnderTestVisitor(context.Host, context.Log, context.Registry); replacer.TraverseChildren(context.AssemblyToAlter); }