Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

Latest commit

 

History

History
32 lines (19 loc) · 3.21 KB

DeveloperDocumentation.md

File metadata and controls

32 lines (19 loc) · 3.21 KB

Developer Documentation

This document is targeted for developers who would like to understand and potentially contribute to the SimpleStubs source code.

Build & Code Generation

SimpleStubs used Roslyn to generate stubs. The code is generated during the build (right before the build actually).

When SimpleStubs NuGet package is installed to a given project, the Etg.SimpleStubs.targets file is installed and imported in the ProjectName.nuget.targets file (which gets added to the target project). The Etg.SimpleStubs.targets file contains the necessary MSBuild tasks needed to generate the stubs. These tasks basically invoke the Etg.SimpleStubs.CodeGen.exe and add the output to the "$(IntermediateOutputPath)SimpleStubs.generated.cs" file (the $(IntermediateOutputPath) is the obj folder).

Method and Property Stubbers

If you follow the source code starting at SimpleStubsGenerator, you'll notice that the InterfaceStubber class is used to generate a stub for a given interface. The constructor of InterfaceStubber is as follows:

        public InterfaceStubber(IEnumerable<IMethodStubber> methodStubbers, IEnumerable<IPropertyStubber> propertyStubbers)
        {
            _propertyStubbers = propertyStubbers;
            _methodStubbers = new List<IMethodStubber>(methodStubbers);
        }

When an interface is stubbed, the InterfaceStubber walks through all the method/property stubbers and execute them all on each method/property in the interface. This means that you can easily add your own implementation of IMethodStubber/IPropertyStubber and it will be invoked as part of the build. To inject your own IMethodStubber/IPropertyStubber, simply update the DIModule code and add an additional entry where the constructor of InterfaceStubber is being invoked. You can also modify existing implementations of IMethodStubber/IPropertyStubber to fix bugs or add behaviour.

Testing

The test folder contains a class library project and a corresponding test project. The test project is setup in a way that it will invoke SimpleStubs with the current version of the Etg.SimpleStubs.CodeGen.exe that is available in the build directory (see Etg.SimpleStubs.targets). This will allow developers to modify the SimpleStubs code and run the unit tests without having to re-generate the NuGet every time.

Debugging

To debug SimpleStubs, simply run SimpleStubs.CodeGen console app with the appropriate parameters (-ProjectPath and -OutputPath).