Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/arturwincenciak/research-aop-weaving-mono.cecil-fody

An article about testing the advice, weaved code by Fody.
https://github.com/arturwincenciak/research-aop-weaving-mono.cecil-fody

aspect-oriented-programming fody mono-cecil weaving

Last synced: 21 days ago
JSON representation

An article about testing the advice, weaved code by Fody.

Awesome Lists containing this project

README

        

![Icon](https://raw.github.com/Fody/BasicFodyAddin/master/Icons/package_icon.png)

This is a simple solution built as a starter for writing [Fody](https://github.com/Fody/Fody) addins.

### BasicFodyAddin Project

The project that does the weaving.

#### Output of the project

It outputs a file named SampleFodyAddin.Fody. The '.Fody' suffix is necessary for it to be picked up by Fody.

#### MethodCallsCounterWeaver

MethodCallsCounterWeaver.cs is where the target assembly is modified. Fody will pick up this type during a its processing.

In this case a new type conteins a method with Attribute 'CountCallsThemAttribute' is being modified by inject counter of call these methhods.

For example code before weaving:

public class Businessman
{
[CountCallsThem]
public void MakeNewSturtUp()
{
// ...
}

[CountCallsThem]
public void BuyCar()
{
// ...
}
}

The code after weaving:

public class Businessman
{
public int MakeNewSturtUpCallsCount;

public int BuyCarCallsCount;

[CountCallsThem]
public void MakeNewSturtUp()
{
this.MakeNewSturtUpCallsCount++;
}

[CountCallsThem]
public void BuyCar()
{
this.BuyCarCallsCount++;
}
}

#### HellowWorldWeaver

In this case a new type is being injected into the target assembly that looks like this.

public class Hello
{
public string World()
{
return "Hello World";
}
}

See [ModuleWeaver](https://github.com/Fody/Fody/wiki/ModuleWeaver)
for more details.

### Nuget Project

Fody addins are deployed as [nuget](http://nuget.org/) packages. NugetProject builds the package for SampleFodyAddin as part of a build. The output of this project is placed in *SolutionDir*/NuGetBuild.

This project uses [pepita](https://github.com/SimonCropp/Pepita) to construct the package but you could also use nuget.exe.

For more information on the nuget structure of Fody addins see [DeployingAddinsAsNugets](https://github.com/Fody/Fody/wiki/DeployingAddinsAsNugets)

### AssemblyToProcess Project

A target assembly to process and then validate with unit tests.

### Tests Project

This is where you would place your unit tests.

Note that it does not reference AssemblyToProcess as this could cause assembly loading issues. However we want to force AssemblyToProcess to be built prior to the Tests project. So in Tests.csproj there is a non-reference dependency to force the build order.


false

The test assembly contains three parts.

#### 1. WeaverTests.Setup()

A helper class that takes the output of AssemblyToProcess and uses ModuleWeaver to process it. It also create a copy of the target assembly suffixed with '2' so a side-by-side comparison of the before and after IL can be done using a decompiler.

#### 2. WeaverTests.Verifier()

A helper class that runs [peverfiy](http://msdn.microsoft.com/en-us/library/62bwd2yd.aspx) to validate the resultant assembly.

#### 3. Tests

Tests project showes how to test the code weaved during compilation process. The actual unit test project contains HelloWorldWeaverTester.cs and CallCounterWeaverTester.cs.

WeaverTests.cs takes weaved assembly to System.Reflection.Assembly object will test.

### No reference to Fody

Not that there is no reference to Fody nor are any Fody files included in the solution. Interaction with Fody is done by convention at compile time.

## Icon

Lego designed by Timur Zima from The Noun Project