Fake Xrm Easy TDD for Dynamics made simple

  • Slides: 59
Download presentation
#Fake. Xrm. Easy TDD for Dynamics made simple

#Fake. Xrm. Easy TDD for Dynamics made simple

Hi! @jordimontana 82

Hi! @jordimontana 82

Why Unit Testing?

Why Unit Testing?

1. Cost €

1. Cost €

1. Epic Bugs: Space Bugs

1. Epic Bugs: Space Bugs

1. Epic Bugs: Space Bugs In 1996, first ESA’s Ariane-5 mission…

1. Epic Bugs: Space Bugs In 1996, first ESA’s Ariane-5 mission…

1. Epic Bugs: Space Bugs In 1996, first ESA’s Ariane-5 mission… > $370 Million

1. Epic Bugs: Space Bugs In 1996, first ESA’s Ariane-5 mission… > $370 Million project…

1. Epic Bugs: Space Bugs In 1996, first ESA’s Ariane-5 mission… > $370 Million

1. Epic Bugs: Space Bugs In 1996, first ESA’s Ariane-5 mission… > $370 Million project… …which blew up in 40 secs due to an integer overflow

2. Epic Bugs: Space Bugs In 1999, NASA’s Mars Climate Orbiter… $ 320 Million

2. Epic Bugs: Space Bugs In 1999, NASA’s Mars Climate Orbiter… $ 320 Million Project…

2. Epic Bugs: Space Bugs In 1999, NASA’s Mars Climate Orbiter… $ 320 Million

2. Epic Bugs: Space Bugs In 1999, NASA’s Mars Climate Orbiter… $ 320 Million Project… … burned up by a unit of measure conversion issue

3 Epic Bugs: Financial $440 Million

3 Epic Bugs: Financial $440 Million

3 Epic Bugs: Financial Bankrupt in 45 mins

3 Epic Bugs: Financial Bankrupt in 45 mins

Bugs have consequences… both external and internal

Bugs have consequences… both external and internal

Bugs have consequences… both external and internal

Bugs have consequences… both external and internal

2. External implications Brand

2. External implications Brand

Brand implications

Brand implications

Brand implications

Brand implications

3. Internal implications Pain… or… can you sleep at night?

3. Internal implications Pain… or… can you sleep at night?

“Unit testing gives us automated regression testing. ”

“Unit testing gives us automated regression testing. ”

“It does so during development, before deploy, functional testing, UAT, Staging and, of course,

“It does so during development, before deploy, functional testing, UAT, Staging and, of course, Production. ”

Unit Tests vs UI / Api Testing…

Unit Tests vs UI / Api Testing…

Why Unit Testing vs… - Fast - Reliable - Isolation

Why Unit Testing vs… - Fast - Reliable - Isolation

Why Unit Testing vs… - Is something broken? - What exactly? - Where?

Why Unit Testing vs… - Is something broken? - What exactly? - Where?

Unit testing cons… - Is not gonna find new bugs for us… - Not

Unit testing cons… - Is not gonna find new bugs for us… - Not for high level testing like UI or E 2 E tests…

“That’s why we need testers!” “So that we can create new unit tests for

“That’s why we need testers!” “So that we can create new unit tests for the bugs they raise!”

Bug = Missing Unit Test

Bug = Missing Unit Test

Large projects and changes - 500+ Custom entities - 80+ Plugins - 540+ Plugin

Large projects and changes - 500+ Custom entities - 80+ Plugins - 540+ Plugin Steps - 780+ Workflows

Large projects and changes - Web portals - SSIS packages + SSRS Reports -

Large projects and changes - Web portals - SSIS packages + SSRS Reports - GIS, MDS, Mobile apps, …

“Unit + integration tests provide a sustainable approach to change management. ”

“Unit + integration tests provide a sustainable approach to change management. ”

Why Fake. Xrm. Easy?

Why Fake. Xrm. Easy?

1. Why Fake. Xrm. Easy? CRM SDK is pretty much “static” composed of: -

1. Why Fake. Xrm. Easy? CRM SDK is pretty much “static” composed of: - CRUD - Queries - Other messages

2. Why Fake. Xrm. Easy? Prior to 2014… started doing unit testing with Fake.

2. Why Fake. Xrm. Easy? Prior to 2014… started doing unit testing with Fake. It. Easy and…. - Found myself doing a lot of repetitive tasks… - … and many problems

Problems with existing general purpose. NET frameworks - Generic & Complex - Mocking Queries

Problems with existing general purpose. NET frameworks - Generic & Complex - Mocking Queries is REALLY hard - Multiple CRM messages to mock

Problem #1: Complexity var mock = new Mock<IOrganization. Service>(); mock. Setup(service => service. Create(It.

Problem #1: Complexity var mock = new Mock<IOrganization. Service>(); mock. Setup(service => service. Create(It. Is. Any<Entity>())). Callback((Entity e) => { e. Id = id; entities. Add(e); }). Returns((Entity e) => id);

Problem #2: Mocks ignore query filters / joins etc…

Problem #2: Mocks ignore query filters / joins etc…

Problem #3: A single. Execute() method with a bunch of different messages to mock

Problem #3: A single. Execute() method with a bunch of different messages to mock

Unit testing for Dynamics 365 would be amazing if….

Unit testing for Dynamics 365 would be amazing if….

… everything was already mocked for us, by default.

… everything was already mocked for us, by default.

So… Fake. Xrm. Easy was born in November 2014

So… Fake. Xrm. Easy was born in November 2014

How it Works? - 1 single ctx. Get. Organization. Service() call needed. - Query

How it Works? - 1 single ctx. Get. Organization. Service() call needed. - Query Engine: Query. Expression, LINQ, Fetch. Xml, Query. By. Attribute - Fake Messages: many implemented, but not all of them… yet (pull requests pls!)

Architecture Overview IOrganization. Service Fake. It. Easy Fake Message Executors CRUD Query Engine In-Memory

Architecture Overview IOrganization. Service Fake. It. Easy Fake Message Executors CRUD Query Engine In-Memory DB (this is actually way more simple than it sounds!)

In-Memory DB - 2 Levels of Dictionaries - First level indexes by Entity Name,

In-Memory DB - 2 Levels of Dictionaries - First level indexes by Entity Name, second level indexes entity records by Id (Guid) to simulate the different CRM tables. In-Memory DB (this is actually way more simple than it sounds!)

Fast! In-Memory DB Mainly because memory is several orders of magnitude faster than disks

Fast! In-Memory DB Mainly because memory is several orders of magnitude faster than disks or network. Also, because even in-memory, dictionaries gives us generally Θ(1) algorithm complexity: Constant Access Time for CRUD operations. Given O(n) the worst case. CRUD In-Memory DB (this is actually way more simple than it sounds!)

What about the Query Engine…? Query Engine In-Memory DB (this is actually way more

What about the Query Engine…? Query Engine In-Memory DB (this is actually way more simple than it sounds!)

CRM LINQ Provider CRM LINQ Query. Expression In-Memory DB (Dictionaries here…)

CRM LINQ Provider CRM LINQ Query. Expression In-Memory DB (Dictionaries here…)

What about the Query Engine…? CRM LINQ Query. Expression ? ? ? In-Memory DB

What about the Query Engine…? CRM LINQ Query. Expression ? ? ? In-Memory DB (Dictionaries here…)

What about the Query Engine…? CRM LINQ Query. Expression LINQ In-Memory DB (Dictionaries) Query

What about the Query Engine…? CRM LINQ Query. Expression LINQ In-Memory DB (Dictionaries) Query Translation Step

What about the Query Engine…? CRM LINQ Query. By. Attribute Query. Expression LINQ In-Memory

What about the Query Engine…? CRM LINQ Query. By. Attribute Query. Expression LINQ In-Memory DB (Dictionaries) Fetch. Xml

What about the Query Engine…? CRM LINQ Query. By. Attribute Query. Expression LINQ In-Memory

What about the Query Engine…? CRM LINQ Query. By. Attribute Query. Expression LINQ In-Memory DB (Dictionaries) Fetch. Xml

To recap… - 1 single ctx. Get. Organization. Service() call needed. - Query Engine:

To recap… - 1 single ctx. Get. Organization. Service() call needed. - Query Engine: Query. Expression, LINQ, Fetch. Xml, Query. By. Attribute - Fake Messages: many implemented, but not all of them… yet (pull requests pls!)

“Fake. Xrm. Easy provides a sustainable and cost-effective approach to facilitate change management for

“Fake. Xrm. Easy provides a sustainable and cost-effective approach to facilitate change management for Dynamics 365”

Applications “Any. NET app connected to an IOrganization. Service”

Applications “Any. NET app connected to an IOrganization. Service”

Applications - Web portals Plugins, Code. Activities, Custom Actions Console apps Xamarin apps Script

Applications - Web portals Plugins, Code. Activities, Custom Actions Console apps Xamarin apps Script component in SSIS WPF …

DEMO TIME!

DEMO TIME!

Thanks! @Digital. Flow @slahn @arjenst @rajyraman @ccellar @bacon 1986 @daryllabar * Sorted by num

Thanks! @Digital. Flow @slahn @arjenst @rajyraman @ccellar @bacon 1986 @daryllabar * Sorted by num of contributions

References Epic Bugs http: //www. computerworld. com/article/2515483/enterprise-applications/epic-failures--11 infamous-software-bugs. html https: //en. wikipedia. org/wiki/Cluster_(spacecraft) https:

References Epic Bugs http: //www. computerworld. com/article/2515483/enterprise-applications/epic-failures--11 infamous-software-bugs. html https: //en. wikipedia. org/wiki/Cluster_(spacecraft) https: //dougseven. com/2014/04/17/knightmare-a-devops-cautionary-tale/ Testing Pyramid / TDD https: //martinfowler. com/bliki/Test. Pyramid. html https: //testing. googleblog. com/2015/04/just-say-no-to-more-end-to-end-tests. html https: //www. thoughtworks. com/insights/blog/mockists-are-dead-long-live-classicists