The main idea of this project it to show a way to add 'profiling' methods calls into 'measured' methods.
Basically we have a main project ShugiShugi that hold a reference to ShugiShugi.Common project to make ETW calls. Then we have a ShugiShugi.Test project that run usual XUnit tests agains ShugiShugi project.
What I want to do - is to dynamically add 'Test started' and 'Test finished' functions calls in each XUnit test method. So it gonna look like this:
[Fact]
public void TestFunc1()
{
Log("Test started");
// test code here
// Assert.xxxxx
Log("Test finished");
}Note: I'm doing it on tests function because we have to choose functions where to add dynamic code. Methods that have attributes is easy to Select, otherwise I have to manually pass the names of the methods....
To make it interesting the Log functions themselves will be also dynamically generated in ShugiShugi.Common project.
So here are the steps:
- Select all methods that have
[Fact]attribute on them - On each method:
- Create new method in
ShugiShugi.Commonproject with the name of test method + Log as a method name - Inject
ILcode to call this method above in the beginning and end of test function
- Create new method in
- This project use Mono.Cecil as an engine to insert
ILcode
- Clone
- Build
- Checkout the
ShugiShugi.Test.dllfile with ilSpy or any other assembly code viewer
- Added
MSBuildTargettoShugiShugi.Testproject that will automatically runLogWrapperonShugiShugi.Testoutput DLL