jordimontana82 / fake-xrm-easy

The testing framework for Dynamics CRM and Dynamics 365 which runs on an In-Memory context and deals with mocks or fakes for you
https://dynamicsvalue.com/get-started/overview?source=git
Other
263 stars 182 forks source link

In Code Activity Logical Name does not exist #598

Closed valredr closed 1 year ago

valredr commented 1 year ago

Please find below the code

    [Fact]
    public void Postive_scenario_is_working()
    {
        //Inputs
        var wfContext = _context.GetDefaultWorkflowContext();
        //Inputs
        var inputs = new Dictionary<string, object>() {
                        { "RecordId", Guid.Empty.ToString() },
                        { "Reason", "sfsdfsdf" },
                        { "EntityType", "account" }
                        };
        UpdateEntityAsCancelled codeActivity = new UpdateEntityAsCancelled();

        var result = _context.ExecuteCodeActivity<UpdateEntityAsCancelled>
            (wfContext, inputs, codeActivity);

        NAssert.True(((string)result["OutParameter"]).Equals("true"));
    }

Code Activity sample below

            IOrganizationServiceFactory serviceFactory = context.GetExtension<IOrganizationServiceFactory>();
            IOrganizationService service = serviceFactory.CreateOrganizationService(wrkContext.UserId);
            Guid entityId = new Guid(RecordId.Get<string>(context));
            string reason = Reason.Get<string>(context);
            string entityType = EntityType.Get<string>(context);
            tracing.Trace("Entity type is" + entityType);
            Entity updateEntity = new Entity(entityType)
            {
                Id = entityId
            };
            service.Update(updateEntity);
            OutParameter.Set(context, "true");

When i run the test in the code activity when service.update is called it gives error that logical name does not exist

jordimontana82 commented 1 year ago

Hi Valres,

You're likely trying to update an entity record that wasn't initialised (doesn't exist in the In-Memory) database, hence the error.

Please call .Initialize() method first.

Also, this repo is for a version that is deprecated. The newer versions (>= 2.x) live on DynamicsValue/fake-xrm-easy and they require a commercial license for consulting projects that don't want to disclose their source code for the benefit of the community.....

Here's more info (second link below explains the Initalize method and testing with data):

https://dynamicsvalue.github.io/fake-xrm-easy-docs/quickstart/migrating-from-1x/

https://dynamicsvalue.github.io/fake-xrm-easy-docs/quickstart/testing-with-data/