Back to Blog

Microsoft Dynamics 365 for Finance and Operations type provider tests – Part 1: Setting up

Post by |

In July 2017 Microsoft announced that type provider tests were to replace form adaptor tests as the mechanism to verify the integration between forms and the underlying code within Dynamics 365 for Finance and Operations (D365FO). The announcement outlines the reasons for the change, in that the form adaptors models were ‘expensive to run and maintain’. The new type providers in comparison provide ‘instant design time support, so that tests can access forms’ removing the need for the extra generate and compile time.

Martin Fowler is a leading author and speaker on software design and he terms these types of tests as ‘subcutaneous tests’ which operate just under the browser user interface. Within D365FO forms, they provide a way to write fast running automated tests which access the controls and trigger events to ensure your unit tested code integrates successfully. They simulate the behaviour of the user, but do not test directly through the user interface.

Searching the internet there is currently limited information and few examples covering how to set up and develop these type provider tests. In this first in a series of posts around type provider tests, we will go through the process we have used to set them up. Through the rest of the series we will take a look at writing type provider tests.

Creating the test model

Firstly we need to create a new model that is going to contain our type provider tests. This is done using the Model Management options that are located on the Dynamics 365 menu in Visual Studio. Selecting Model  Management displays some further options. One of these options is Create model….

Create model

Step 1

Selecting this option opens the Create model dialog. The create model process is a straight forward four step wizard which defines how your model will be set up. The first step is to enter the model name and other properties. Complete the fields on the Add parameters page and click the Next button.

Step one

Step 2

The second stage of the wizard called Select package will be displayed. In this step you need to select whether the model will be based on an existing package and used to create overlays, or whether you would like to create a new package to extend the application. As you are writing tests, you will create this model as a new package. Select the Create new package option and click the Next button.

Step 2

Step 3

The Select referenced packages page will be displayed as the third page, allowing you to select the other packages that the model needs to reference. For the type provider tests some of the key classes are contained in the TestEssentials package. This model should be selected. Alongside this the ApplicationFoundation package should be selected as it is required for the unit test framework classes. ApplicationPlatform is already selected and should be left selected. You will also need to select the ApplicationSuite package as this will be required when you start to write tests in the next post. You should also select any packages that contain the form and elements that you will be testing. Select the required packages and click the Next button.

Step 3

Step 4

The Summary page will be displayed as the final step in the wizard, reviewing what has been selected in the previous steps. It’s useful to select the Create new project option as it will set up a project where you can complete the remaining setup steps and start creating type provider tests. Click the Next button.

Step 4

If you ticked the Create new project check box, you will be presented with the standard Visual Studio create solution/project dialog as per the screenshot below. Enter the required project Name, select the Location of the files and specify a Solution name. Click the OK button for the solution/project to be created and opened in Visual Studio.

Step 4 part 2

You have successfully created our test model that will contain our type provider tests. You now need to add a Visual Studio project reference to the type provider assembly. This assembly is called Microsoft.Dynamics.Ax.TypeProviders.FormAdaptors.dll, and it is located on your development environment in the AosService\PackagesLocalDirectory\Bin folder. The AosService previously was located on the J drive, but in recent updates to the development environments it can also be found on the K drive.

On my development environment the full path to the assembly is:

K:\AosService\PackagesLocalDirectory\Bin\Microsoft.Dynamics.Ax.TypeProviders.FormAdaptors.dll

The next step is to add this assembly as a reference to test model project. However, from investigations we have found that adding the reference directly to the assembly in the AosService\PackagesLocalDirectory\Bin folder causes a number of errors when you build the project. The compilation complains about missing assemblies. Trying to copy the additional assemblies to the AosService\PackagesLocalDirectory\Bin folder leads to the compilation raising an error for a different missing assembly.  To resolve this issue, the Microsoft.Dynamics.Ax.TypeProviders.FormAdaptors.dll assembly was copied to the bin folder of our newly created test model. In our example the location of this is:

K:\AosService\PackagesLocalDirectory\TypeProviderTestExamples\bin

Please note the bin folder will not be created until you have built your model for the first time. So build your new test model from the Dynamics 365 menu option in Visual Studio. Then copy the Microsoft.Dynamics.Ax.TypeProviders.FormAdaptors.dll assembly from K:\AosService\PackagesLocalDirectory\Bin to the bin folder of the model i.e. K:\AosService\PackagesLocalDirectory\TypeProviderTestExamples\bin.

This will ensure that the assembly will be able to reference the other required assemblies.

The final step, back in Visual Studio is to add the project reference to the Microsoft.Dynamics.Ax.TypeProviders.FormAdaptors.dll assembly. In Visual Studio right click the References option in you newly created project. A submenu will be displayed. Select the option to Add Reference….

Add reference

In the Add Reference dialog, click the Browse tab and navigate to the bin folder of your model (K:\AosService\PackagesLocalDirectory\TypeProviderTestExamples\bin) and select Microsoft.Dynamics.Ax.TypeProviders.FormAdaptors.dll. Click the OK button.

Ad reerence part 2

Build your solution/project in Visual Studio. It should build successfully. You have successfully completed the setup for the type provider tests. In the next post you will learn  how to write a type provider test.

About the Author:


Chris Lowe is a Technical Architect for LexisNexis working on the Dynamics 365 for Finance and Operations version of the LexisOne ERP solution. He is based at the LexisNexis office in Leeds, UK, where he has been working on Dynamics 365 for Finance and Operations for approximately the last 2 years. Prior to this he was working on the Dynamics AX 2012 version of LexisOne. Before his move to Dynamics AX related technologies he worked on .Net browser based applications in both the legal and banking industries. He has 20 years’ experience working in IT software development.

| See all our contributors
Back to Blog