1

I need to create a unit test that will use the following pipeline

Sitecore.Analytics.Pipelines.StartTracking

It then needs to see if the tracking is enabled and then check if a cookie exists.

I saw some code that could help me get started but I am new to pipeline unit tests for Sitecore so I am a little confused what I need to do to make it work.

I am using xunit and Sitecore.FakeDB for Sitecore version: 8.2.

Thanks in advance.

[Fact]
public void ProcessTest()
{
    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);
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.