fakexrmeasy.2016 v0.0.4
FakeXrmEasy.Js
This project aims to provide mocks already implemented for Web API calls made from Javascript. This is a work in progress and way less mature than its C# counterpart.
NEW: Dependency on edge.js has been removed, the npm runs entirely in the npm process only (no clr code running behind the scenes) which provide an easier setup and much better performance.
Goals
To be able to unit test Dynamics CRM Web Api calls as easily as possible, given that:
The focus will be on unit testing Web API calls, not the Xrm Page, as there are other projects for that already (see https://github.com/camelCaseDave/xrm-mock).
Executing web api queries doesn't involve any access to the DOM, which means we could even use Node for testing. This is also the same for the Xrm Page, where we shouldn't access the DOM (i.e. via jQuery) as it is unsupported. The only exception would be custom web resources but we can live with it because we can still separate JS logic from the logic which accesses the DOM (HTML).
We want to run unit tests as fast as possible
The Approach
Given the above, the approach chosen is the following:
- We'll use nodejs and VSCode: it's lightweight, and it offers an overwhelming number of extensions to run Javascript / Typescripts and even live unit testing runners.
So roughly, the following steps:
-> 1) XMLHttpRequests automatically intercepted to:
-> 2) Parse OData Query
-> 3) Translate OData query into Linq to objects (in javascript), and execute it
-> 4) Compose a fakeXhr response following Web Api specification
Samples
Check this repo for a sample code project.
Backlog
Done:
- Queries: Implemented $select
- Queries: Implemented $filter (relational and boolean expressions)
- Queries: Implemented $filter functions (startsWith, endsWith, substringof)
- Queries: Implemented $top functions
- Create: basic create
- Update: basic update
- Delete: basic delete
- Retrieve: basic retrieve, retrieve with $select
- Ability to add custom Web API functions / custom action mocks: please check test/XrmFakedContext/fake_message_executor_tests.ts for examples
To Do (you can use addFakeMessageExecutor function to mock any response while these are not yet implemented as a workaround) :
- Retrieve with alternate keys
- Retrieve a single property value
- Retrieve navigation property values (similar to $expand for queries)
- Create related entities in one operation
- Associate entities on Create
- Delete single property values
- Update with data representation returned (simulate update + get message)
- Update by single attribute (PUT)
Limit upsert via headers (If-Match, If-Not-Match)
Queries: Implement $expand functions
- Queries: Implement $orderby functions
- Queries: Implement lookup filtering
- Optimistic concurrency simulation