Skip to content
This repository has been archived by the owner on Aug 25, 2019. It is now read-only.

Latest commit

 

History

History
107 lines (74 loc) · 3.37 KB

RefactoringTutorial.md

File metadata and controls

107 lines (74 loc) · 3.37 KB

Refactoring To Async Tutorial

Contents

Prep

Step by Step

Notes

  1. All pipeline setup code occurs at the top of the method.
  2. Then the approvals call
  3. Then the sending through the pipeline

Template

// Set up Pipeline
// ApprovalPipeline
// Send thru pipeline
// Original code

1. Call the method in question from a test

Simply call the method you wish to refactor from a test. Don't think of this as a traditional unit test. Think of it more as a specialized main() method

2. Take the 1st thing to move to async and create an InputPipe of it's parameters directly above it.

var startingPointInput = new InputPipe<InputType>("InputName");

3. Place a ApprovalTests to get insight into the pipeline.

Place this right in the middle of the production code you want to refactor. It is a temporary step.

PipelineApprovals.Verify(startingPointInput);

With a DotReporter (on the test)

[UseReporter(typeof(DotReporter))]

4. Inspect result in VsCode

5. Add a process as a delegate

If the code isn't in a method, extract it to one first

 var methodCallPipe = startingPoint.Process(TheMethodCall)

Do this above the approvals.Verify(). Run it again for feedback

6. Add a collector, and send input in

 var methodCallCollector = methodCallPipe.Collect();
 startingPoint.Send(firstParameter);
 var variable = methodCallCollector.SingleResult;

7. Process and Collect the next step in the pipeline

8. (optional) Delete dead code

9. Goto step 7

Handling multiple parameters

Everything is a single parameter. To use multiple, you'll have to join them into tuples. If this is requires new inputs, you'll need multiple input pipes