fake-xrm-easy icon indicating copy to clipboard operation
fake-xrm-easy copied to clipboard

Create entity with statecode attribute occurs an exception

Open johanvandam opened this issue 5 years ago • 5 comments

I have a UnitTest where a record is created with a statecode attribute. The create in the faked OrganizationService failed with the following errormessage:

When creating an entity with logical name 'account', or any other entity, it is not possible to create records with the statecode property. Statecode must be set after creation.

My code:

        var fakedContext = new XrmFakedContext();

        var service = fakedContext.GetOrganizationService();

        var account = new Entity("account")
        {
            ["name"] = _autoFixture.Create<string>(),
            ["statecode"] = new OptionSetValue(0)
        };

        service.Create(account);

The code does work in Dynamics Online, it is allowed to create an account record with a statecode. My Dynamics instance version: 1710 (9.1.0.12935) online I use FakeXrmEasy.9 version 1.57.0

johanvandam avatar Feb 14 '20 11:02 johanvandam

This wrong behavior was introduced in #214. This of course complicates unit testing when faked context doesn't throws exceptions which real CRM doesn't.

Perhaps Creating records with specified statuscode/statecode or updating inactive records were invalid operation for older CRM releases? There was a time where Owner could be changed with AssignRequest and {state,status}code with SetStateRequest, but is now deprecated and UpdateRequest allows setting these values: Behavior of specialized update operations

@jordimontana82 perhaps #214 should be rollbacked or limited to older CRM versions if that was the case back then?

janis-veinbergs avatar Sep 01 '20 14:09 janis-veinbergs

Thanks for reporting this @janis-veinbergs @johanvandam.

Yes, I believe this would require branching the codebase based on being >= 9 version or not. Cause previous versions of Dynamics 365 might be enforcing the restriction in that PR #214 which is now deprecated for the newer versions.

jordimontana82 avatar Oct 30 '20 09:10 jordimontana82

Hi @jordimontana82, just wondering about the status of this. It's still open (and the issue still exists) but it looks like the issue has been fixed and the fix has been merged. Will the fix be in the v2/v3 releases? ;-)

bwmodular avatar Apr 26 '22 13:04 bwmodular

Hi Ben, it looks like it was merged in a fork ;)

Anyway, it's an easy one so raised another issue and will be dropped in the next release: DynamicsValue/fake-xrm-easy#36

@bwmodular

jordimontana82 avatar Apr 26 '22 13:04 jordimontana82

That's great @jordimontana82 - Another good reason to migrate to version 2! :-)

bwmodular avatar Apr 26 '22 13:04 bwmodular