From da34def90da23cfd81b03a227282222396280045 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Guldmund?= Date: Thu, 2 May 2024 14:33:45 +0200 Subject: [PATCH] #12 Rearrange sections in README for clarity --- README.md | 52 +++++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 1f2e31e..56bb6ae 100644 --- a/README.md +++ b/README.md @@ -115,6 +115,31 @@ Shim structShim = Shim.Replace(() => Is.A().DoSomething()).With( _Note: You cannot shim methods on specific instances of Value Types_ +### Isolating your code + +```csharp +// This block executes immediately +PoseContext.Isolate(() => +{ + // All code that executes within this block + // is isolated and shimmed methods are replaced + + // Outputs "Hijacked: Hello World!" + Console.WriteLine("Hello World!"); + + // Outputs "4/4/04 12:00:00 AM" + Console.WriteLine(DateTime.Now); + + // Outputs "doing someting else" + new MyClass().DoSomething(); + + // Outputs "doing someting else with myClass" + myClass.DoSomething(); + +}, consoleShim, dateTimeShim, classPropShim, classShim, myClassShim, structShim); +``` + +## Async usage ### Shim static async method ```csharp using Pose; @@ -126,6 +151,7 @@ Shim staticTaskShim = Shim.Replace(() => DoWorkAsync()).With( return Task.CompletedTask; }); ``` + ### Shim async instance method of a Reference Type ```csharp using Pose; @@ -153,32 +179,8 @@ Shim myClassTaskShim = Shim.Replace(() => myClass.DoSomethingAsync()).With( }); ``` -### Isolating your code - -#### Non-async -```csharp -// This block executes immediately -PoseContext.Isolate(() => -{ - // All code that executes within this block - // is isolated and shimmed methods are replaced - - // Outputs "Hijacked: Hello World!" - Console.WriteLine("Hello World!"); - - // Outputs "4/4/04 12:00:00 AM" - Console.WriteLine(DateTime.Now); - - // Outputs "doing someting else" - new MyClass().DoSomething(); - - // Outputs "doing someting else with myClass" - myClass.DoSomething(); - -}, consoleShim, dateTimeShim, classPropShim, classShim, myClassShim, structShim); -``` +### Isolating your async code -#### Async ```csharp // This block executes immediately await PoseContext.Isolate(async () =>