-
-
Notifications
You must be signed in to change notification settings - Fork 6
first version #436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
first version #436
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
|
|
||
| { | ||
| "$schema": "https://aka.ms/codetour-schema", | ||
| "title": "Imposter", | ||
| "steps": | ||
| [ | ||
| { | ||
| "file": "rscg_examples/Imposter/src/TestClock/TestClock.csproj", | ||
| "description": "First, we add Nuget [Imposter](https://www.nuget.org/packages/Imposter/) in csproj ", | ||
| "pattern": "Imposter" | ||
| } | ||
|
|
||
| ,{ | ||
| "file": "rscg_examples/Imposter/src/TestClock/Usings.cs", | ||
| "description": "File Usings.cs ", | ||
| "pattern": "this is the code" | ||
| } | ||
|
|
||
| ,{ | ||
| "file": "rscg_examples/Imposter/src/TestClock/TestClock.cs", | ||
| "description": "File TestClock.cs ", | ||
| "pattern": "this is the code" | ||
| } | ||
|
|
||
|
|
||
| ,{ | ||
| "file": "rscg_examples/Imposter/src/TestClock/obj/GX/Imposter.CodeGenerator/Imposter.CodeGenerator.CodeGenerator.ImposterGenerator/IMyClockImposter.g.cs", | ||
| "description": "Generated File 1 from 1 : IMyClockImposter.g.cs ", | ||
| "line": 1 | ||
| } | ||
|
|
||
| ], | ||
|
|
||
| "ref": "main" | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,59 @@ | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| <h1>RSCG nr 246 : Imposter</h1> | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| <h2>Info</h2> | ||||||||||||||||||||||||||||||
| Nuget : <a href="https://www.nuget.org/packages/Imposter/" target="_blank">https://www.nuget.org/packages/Imposter/</a> | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| <p>You can find more details at : <a href="https://github.com/themidnightgospel/Imposter" target="_blank"> https://github.com/themidnightgospel/Imposter</a></p> | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| <p>Author :Bitchiko Tchelidze</p> | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| <p>Source: <a href="https://github.com/themidnightgospel/Imposter" target="_blank">https://github.com/themidnightgospel/Imposter</a> </p> | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| <h2>About</h2> | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| Generate classes from interfaces and allows return of mock data.Useful for testing and prototyping. | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
Comment on lines
+9
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix minor spacing/typos in public HTML text. -<p>Author :Bitchiko Tchelidze</p>
+<p>Author : Bitchiko Tchelidze</p>
@@
-Generate classes from interfaces and allows return of mock data.Useful for testing and prototyping.
+Generate classes from interfaces and allows return of mock data. Useful for testing and prototyping.📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
| <h2> | ||||||||||||||||||||||||||||||
| How to use | ||||||||||||||||||||||||||||||
| </h2> | ||||||||||||||||||||||||||||||
| <h3> | ||||||||||||||||||||||||||||||
| Add reference to the <a href="https://www.nuget.org/packages/Imposter/" target="_blank">Imposter</a> in the csproj | ||||||||||||||||||||||||||||||
| </h3> | ||||||||||||||||||||||||||||||
| <img src="images/Imposter/TestClock.csproj.png" width="580" height="580" /> | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| <h3>This was for me the <b>starting</b> code</h3> | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| <br /> | ||||||||||||||||||||||||||||||
| I have <b>coded</b> the file TestClock.cs | ||||||||||||||||||||||||||||||
| <br /> | ||||||||||||||||||||||||||||||
| <img src="images/Imposter/csFiles/TestClock.cs.png" width="580" height="580" /> | ||||||||||||||||||||||||||||||
| <hr /> | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| <br /> | ||||||||||||||||||||||||||||||
| I have <b>coded</b> the file Usings.cs | ||||||||||||||||||||||||||||||
| <br /> | ||||||||||||||||||||||||||||||
| <img src="images/Imposter/csFiles/Usings.cs.png" width="580" height="580" /> | ||||||||||||||||||||||||||||||
| <hr /> | ||||||||||||||||||||||||||||||
| <h3>And here are the <i>generated</i> files</h3> | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| <br /> | ||||||||||||||||||||||||||||||
| The file <i>generated</i> is IMyClockImposter.g.cs | ||||||||||||||||||||||||||||||
| <br /> | ||||||||||||||||||||||||||||||
| <img src="images/Imposter/generated/IMyClockImposter.g.cs.png" width="580" height="580" /> | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| <p> | ||||||||||||||||||||||||||||||
| You can download the code and this page as pdf from | ||||||||||||||||||||||||||||||
| <a target="_blank" href='https://ignatandrei.github.io/RSCG_Examples/v2/docs/Imposter'> | ||||||||||||||||||||||||||||||
| https://ignatandrei.github.io/RSCG_Examples/v2/docs/Imposter | ||||||||||||||||||||||||||||||
| </a> | ||||||||||||||||||||||||||||||
| </p> | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| <p> | ||||||||||||||||||||||||||||||
| You can see the whole list at | ||||||||||||||||||||||||||||||
| <a target="_blank" href='https://ignatandrei.github.io/RSCG_Examples/v2/docs/List-of-RSCG'> | ||||||||||||||||||||||||||||||
| https://ignatandrei.github.io/RSCG_Examples/v2/docs/List-of-RSCG | ||||||||||||||||||||||||||||||
| </a> | ||||||||||||||||||||||||||||||
| </p> | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "generator":{ | ||
| "name":"Imposter", | ||
| "nuget":[ | ||
| "https://www.nuget.org/packages/Imposter/" | ||
| ], | ||
| "link":"https://github.com/themidnightgospel/Imposter", | ||
| "author":"Bitchiko Tchelidze", | ||
| "source":"https://github.com/themidnightgospel/Imposter" | ||
| }, | ||
| "data":{ | ||
| "goodFor":["Generate classes from interfaces and allows return of mock data.","Useful for testing and prototyping."], | ||
| "csprojDemo":"TestClock.csproj", | ||
| "csFiles":["TestClock.cs","Usings.cs"], | ||
| "excludeDirectoryGenerated":[""], | ||
| "includeAdditionalFiles":[""] | ||
| }, | ||
| "links":{ | ||
| "blog":"", | ||
| "video":"" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Imposter — Source-generated test doubles, zero runtime overhead. A high-performance Roslyn incremental source generator that produces imposters (mocks/stubs) for interfaces and overridable class members via GenerateImposterAttribute. Ships analyzer + runtime in a single package. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| <p align="center"> | ||
| <img src="docs/imposter_logo.png" alt="Imposter logo" width="140" /> | ||
| </p> | ||
|
|
||
| <p align="center"> | ||
| Fast and Memory-Efficient Mocking Library | ||
| </p> | ||
|
|
||
| [](https://github.com/themidnightgospel/Imposter/actions/workflows/build-and-test.yml) | ||
| [](https://www.nuget.org/packages/Imposter) | ||
|
|
||
| Imposter is a mocking library that's using roslyn source generators to achieve high performance and low memory footprint. | ||
|
|
||
| Visit the [Docs](https://themidnightgospel.github.io/Imposter/) for more information | ||
|
|
||
|
Comment on lines
+12
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix “imoster” typo + minor grammar polish in README. -Imposter is a mocking library that's using roslyn source generators to achieve high performance and low memory footprint.
+Imposter is a mocking library that uses Roslyn source generators to achieve high performance and a low memory footprint.
@@
-Use `[GenerateImposter]` attribute in your **tests** project, this will generate an imoster
+Use `[GenerateImposter]` attribute in your **tests** project; this will generate an imposter
@@
-Then use can use the generated imposter in your tests
+Then you can use the generated imposter in your testsAlso applies to: 38-45 🧰 Tools🪛 LanguageTool[uncategorized] ~12-~12: If this is a compound adjective that modifies the following noun, use a hyphen. (EN_COMPOUND_ADJECTIVE_INTERNAL) 🤖 Prompt for AI Agents |
||
| ## 🚀 Quick Start | ||
|
|
||
| Add nuget package reference: | ||
|
|
||
| ```bash | ||
| dotnet add package Imposter | ||
| ``` | ||
|
|
||
| Pick an interface or non-sealed class that you would like to generate an imposter for. | ||
|
|
||
| Say we have a below interface | ||
|
|
||
| ```csharp | ||
|
|
||
| namespace Application.Domain; | ||
|
|
||
| public interface ICalculator | ||
| { | ||
| int Add(int a, int b); | ||
| } | ||
| ``` | ||
|
|
||
| Use `[GenerateImposter]` attribute in your **tests** project, this will generate an imoster | ||
|
|
||
| ```csharp | ||
| [assembly: GenerateImposter(typeof(Application.Domain.ICalculator))] | ||
| ``` | ||
|
|
||
| Then use can use the generated imposter in your tests | ||
|
|
||
| ```csharp | ||
| using System.Threading.Tasks; | ||
| using Imposter.Abstractions; | ||
|
|
||
| // c# 14 | ||
| var imposter = ICalculator.Imposter(); | ||
|
|
||
| // c# 9 - 13 | ||
| // var imposter = new ICalculatorImposter(); | ||
|
|
||
| imposter.Add(Arg<int>.Any(), Arg<int>.Any()) | ||
| .Returns(1) | ||
| .Then() | ||
| .Returns(2); | ||
|
|
||
| var calculator = imposter.Instance(); | ||
|
|
||
| calculator.Add(1, 2); // 1 | ||
| calculator.Add(1, 2); // 2 | ||
| ``` | ||
|
|
||
| Learn more: https://themidnightgospel.github.io/Imposter/ | ||
|
|
||
| ## ✨ Feature-Rich | ||
|
|
||
| - [Method Impersonation](https://themidnightgospel.github.io/Imposter/latest/methods/) | ||
| - [Property Impersonation](https://themidnightgospel.github.io/Imposter/latest/properties/) | ||
| - [Indexer Impersonation](https://themidnightgospel.github.io/Imposter/latest/indexers/) | ||
| - [Event Impersonation](https://themidnightgospel.github.io/Imposter/latest/events/) | ||
| - [Class Impersonation](https://themidnightgospel.github.io/Imposter/latest/base-implementation/) | ||
| - [Generics](https://themidnightgospel.github.io/Imposter/latest/generics/) | ||
| - [Implicit & Explicit Modes](https://themidnightgospel.github.io/Imposter/latest/implicit-vs-explicit/) | ||
| - [Use Base implementation](https://themidnightgospel.github.io/Imposter/latest/base-implementation/) | ||
| - [Async Support](https://themidnightgospel.github.io/Imposter/latest/methods/#async-methods) | ||
| - [Protected members Impersonation](https://themidnightgospel.github.io/Imposter/latest/methods/protected-members/) | ||
|
|
||
| ## ⏱️ Benchmark | ||
|
|
||
| We benchmarked the simple method-impersonation scenario: we set up a `Square` method to return `input * input` and ran it for 1, 10, 100, and 1000 iterations. | ||
|
|
||
| ```csharp | ||
| public interface ICalculator | ||
| { | ||
| int Square(int input); | ||
| } | ||
| ``` | ||
|
|
||
| Mean execution time | ||
|
|
||
| | Method | Iteration | Mean | | ||
| |-------------|-----------|----------------:| | ||
| | Moq | 1 | 69,346.1 ns | | ||
| | NSubstitute | 1 | 1,976.2 ns | | ||
| | FakItEasy | 1 | 2,006.7 ns | | ||
| | Imposter | 1 | **194.3 ns** | | ||
| | Moq | 10 | 686,282.9 ns | | ||
| | NSubstitute | 10 | 11,201.6 ns | | ||
| | FakItEasy | 10 | 12,399.0 ns | | ||
| | Imposter | 10 | **1,896.7 ns** | | ||
| | Moq | 100 | 6,804,897.3 ns | | ||
| | NSubstitute | 100 | 335,390.6 ns | | ||
| | FakItEasy | 100 | 258,220.2 ns | | ||
| | Imposter | 100 | **34,011.7 ns** | | ||
| | Moq | 1000 | 99,710,929.5 ns | | ||
| | NSubstitute | 1000 | 26,986,939.0 ns | | ||
| | FakItEasy | 1000 | 18,997,374.5 ns | | ||
| | Imposter | 1000 | **2,452,970.7 ns** | | ||
|
|
||
|
|
||
| Allocated Memory | ||
|
|
||
| | Method | Iteration | Allocated | | ||
| |-------------|-----------|------------:| | ||
| | Moq | 1 | 13.05 KB | | ||
| | NSubstitute | 1 | 7.84 KB | | ||
| | FakeItEasy | 1 | 5.84 KB | | ||
| | Imposter | 1 | **2.4 KB** | | ||
| | Moq | 10 | 115.73 KB | | ||
| | NSubstitute | 10 | 29.29 KB | | ||
| | FakeItEasy | 10 | 38.81 KB | | ||
| | Imposter | 10 | **22.37 KB** | | ||
| | Moq | 100 | 1416.91 KB | | ||
| | NSubstitute | 100 | 247.26 KB | | ||
| | FakeItEasy | 100 | 1033.38 KB | | ||
| | Imposter | 100 | **222.05 KB** | | ||
| | Moq | 1000 | 42275.19 KB | | ||
| | NSubstitute | 1000 | 2420.82 KB | | ||
| | FakeItEasy | 1000 | 77101.74 KB | | ||
| | Imposter | 1000 | **2218.93 KB** | | ||
|
|
||
|
|
||
| Benchmark Environment | ||
|
|
||
| ``` | ||
| BenchmarkDotNet v0.15.6, Windows 11 (10.0.26200.6899) | ||
| 13th Gen Intel Core i9-13900HX 2.20GHz, 1 CPU, 32 logical and 24 physical cores | ||
| .NET SDK 10.0.100 | ||
| [Host] : .NET 8.0.21 (8.0.21, 8.0.2125.47513), X64 RyuJIT x86-64-v3 | ||
| DefaultJob : .NET 8.0.21 (8.0.21, 8.0.2125.47513), X64 RyuJIT x86-64-v3 | ||
| ``` | ||
|
|
||
| See other benchmarks [benchmark](https://github.com/themidnightgospel/Imposter/blob/3172c333603fd2d76031b20be39753a9b62f31c3/benchmarks/Imposter.Benchmarks/ImposterVsMoqVsNSubstitute/SimpleMethodMockingBenchmarks.cs#L12) | ||
|
|
||
| ## Docs | ||
| Docs: https://themidnightgospel.github.io/Imposter/ | ||
|
|
||
| ## License | ||
|
|
||
| Licensed under the MIT License. See LICENSE.txt for details. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| namespace MockData; | ||
| public interface IMyClock | ||
| { | ||
| public DateTime GetNow(); | ||
| public DateTime GetUtcNow(); | ||
|
|
||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: ignatandrei/RSCG_Examples
Length of output: 51
🏁 Script executed:
Repository: ignatandrei/RSCG_Examples
Length of output: 51
🏁 Script executed:
Repository: ignatandrei/RSCG_Examples
Length of output: 175
🏁 Script executed:
Repository: ignatandrei/RSCG_Examples
Length of output: 51
🏁 Script executed:
# Read Usings.cs to check for the pattern "this is the code" cat -n ./v2/rscg_examples/Imposter/src/TestClock/Usings.csRepository: ignatandrei/RSCG_Examples
Length of output: 256
🏁 Script executed:
# Read TestClock.cs to check for the pattern "this is the code" cat -n ./v2/rscg_examples/Imposter/src/TestClock/TestClock.csRepository: ignatandrei/RSCG_Examples
Length of output: 606
🏁 Script executed:
# Verify the tour file exists and show its full content cat -n ./v2/.tours/Imposter.tourRepository: ignatandrei/RSCG_Examples
Length of output: 1292
Fix tour patterns and remove reference to build-generated file.
The patterns
"this is the code"(lines 16 and 22) do not match any content in Usings.cs or TestClock.cs. Replace them with actual matching text from those files, or omit thepatternfield.The referenced generated file at
obj/GX/Imposter.CodeGenerator/.../IMyClockImposter.g.cs(line 27) does not exist in the repository and is only created during build. Remove this step or replace it with a checked-in snapshot of the generated output under a stable path likesrc/TestClock/generated/.🤖 Prompt for AI Agents