Skip to content

When creating a record, the record ID is not set in the target when using pipeline simulation #216

@SvenRahnSIT

Description

@SvenRahnSIT

Minimal test case:

using FakeXrmEasy.Abstractions.Enums;
using FakeXrmEasy.Middleware;
using FakeXrmEasy.Middleware.Crud;
using FakeXrmEasy.Middleware.Messages;
using FakeXrmEasy.Middleware.Pipeline;
using FakeXrmEasy.Pipeline;
using FakeXrmEasy.Plugins.PluginSteps;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Xrm.Sdk;
using System;
using SIT.Core.Plugins.Entities;

namespace SIT.Core.Plugins.Tests;

[TestClass]
public class TestClass
{
    public class TestPlugin : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            var tracing = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

            var target = (Entity)context.InputParameters["Target"];
            tracing.Trace($"Entity Logical Name: {target.LogicalName}");
            tracing.Trace($"Entity ID: {target.Id}");
        }
    }

    [TestMethod]
    public void Test()
    {
        // Arange
        var context = MiddlewareBuilder
            .New()
            .AddCrud()
            .AddFakeMessageExecutors()
            .AddGenericFakeMessageExecutors()
            .AddPipelineSimulation()
            .UsePipelineSimulation()
            .UseCrud()
            .UseMessages()
            .SetLicense(FakeXrmEasyLicense.RPL_1_5)
            .Build();

        context.RegisterPluginStep<TestPlugin>(new PluginStepDefinition()
        {
            MessageName = "Create",
            EntityLogicalName = Contact.EntityLogicalName,
            Stage = FakeXrmEasy.Abstractions.Plugins.Enums.ProcessingStepStage.Postoperation,
        });

        // Act
        var service = context.GetOrganizationService();
        var contactId = service.Create(new Contact());

        // Assert
        var trace = context.GetTracingService().DumpTrace().Split([Environment.NewLine], StringSplitOptions.RemoveEmptyEntries);

        Assert.AreEqual($"Entity Logical Name: {Contact.EntityLogicalName}", trace[0]);
        Assert.AreEqual($"Entity ID: {contactId}", trace[1]);
    }
}

might be similar to #162

Fails with

Assert.AreEqual failed. String lengths are both 47 but differ at index 11. 'expected' expression: '$"Entity ID: {contactId}"', 'actual' expression: 'trace[1]'.
Expected: "Entity ID: 5ddeb8c5-3ed8-4e15-ac52-bc3..."
But was:  "Entity ID: 00000000-0000-0000-0000-000..."

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions