Skip to content
sergeyshushlyapin edited this page Nov 13, 2014 · 2 revisions

Important:

If you are running Sitecore 7.5 or higher, consider using Sitecore.Abstractions.ICorePipeline interface from the Sitecore.Abstractions assembly.

[Fact]
public void HowToUnitTestPipelineCallWithMockedProcessor()
{
  var args = new Sitecore.Pipelines.PipelineArgs();

  using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db())
  {
    // register a processor mock in the Pipeline Watcher
    var processor =
      Substitute.For<Sitecore.FakeDb.Pipelines.IPipelineProcessor>();
    db.PipelineWatcher.Register("mypipeline", processor);

    // call the pipeline
    Sitecore.Pipelines.CorePipeline.Run("mypipeline", args);

    // check the mocked processor is called
    processor.Received().Process(args);
  }
}
[Fact]
public void HowToUnitTestAdvancedPipelineCallWithMockedProcessor()
{
  var args = new Sitecore.Pipelines.PipelineArgs();

  using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db())
  {
    // register a processor mock in the Pipeline Watcher
    var processor =
      Substitute.For<Sitecore.FakeDb.Pipelines.IPipelineProcessor>();

    processor
      .When(p => p.Process(args))
      .Do(ci => ci.Arg<Sitecore.Pipelines.PipelineArgs>()
                  .CustomData["Result"] = "Ok");

    db.PipelineWatcher.Register("mypipeline", processor);

    // call the pipeline
    Sitecore.Pipelines.CorePipeline.Run("mypipeline", args);

    // check the result is set
    Assert.Equal("Ok", args.CustomData["Result"]);
  }
}
Clone this wiki locally