Pipeline Simulation is an advanced feature of FakeXrmEasy.
With Pipeline Simulation enabled, FakeXrmEasy will automatically fire plugin executions as long as these plugins are registered as plugin steps in FakeXrmEasy.
The plugin steps need to be registered manually right now, in a future version these will be automatically registered based on attributes.
In order to use Pipeline Simulation, you need to enable it in the middleware first:
The UsePipelineSimulation() needs to be put in front of every other middleware step so it would fire any PreOperation steps before any other message.
Every time a request is executed, FakeXrmEasy will determine if there is an appropiate plugin registered for that request, and will execute it accordingly.
See section below about how to register plugin steps in FakeXrmEasy.
public class FakeXrmEasyPipelineTestsBase
{
protected readonly IXrmFakedContext _context;
protected readonly IOrganizationService _service;
public FakeXrmEasyPipelineTestsBase()
{
_context = MiddlewareBuilder
.New()
.AddCrud()
.AddFakeMessageExecutors()
.AddPipelineSimulation()
.UsePipelineSimulation()
.UseCrud()
.UseMessages()
.Build();
_service = _context.GetAsyncOrganizationService();
}
}
In order to register plugins you can use the RegisterPluginStep method, with different overloads.
A very simple way of registering a plugin step is like the one below, which would register the AccountNumberPlugin against the PreOperation of the Create message.
This will fire this plugin against the Create message of any entity.
using FakeXrmEasy.Pipeline;
public class PipelineTests: FakeXrmEasyPipelineTestsBase
{
[Fact]
public void Should_set_account_number_on_account_create()
{
_context.RegisterPluginStep<AccountNumberPlugin>("Create", ProcessingStepStage.Preoperation);
_context.ExecutePluginWith<CreateAccountPlugin>();
var account = _context.CreateQuery<Account>().FirstOrDefault();
Assert.NotNull(account);
Assert.True(account.Attributes.ContainsKey("accountnumber"));
Assert.NotNull(account["accountnumber"]);
}
}
There is a separate overload where you could specify for which entity should fire the message, i.e.:
_context.RegisterPluginStep<AccountNumberPlugin, Account>("Create");
The methods allow passing in other properties, like filtering attributes, rank (the order of execution), and so on.