How to do it...

To create a unit test for the vehicle service order's form, follow these steps:

  1. We must start from the main Dynamics 365 for Operations window; otherwise, the generated code may fail.
  2. Once at the main menu, click on the settings icon (the cog) and choose Task recorder.
  3. Click on Create recording in the Task recorder sidebar.
  4. Enter ConWHSServiceOrderTest in the Recording name field, and a description of what we expect to happen. This will become the class name.
  5. Click on Start.
  6. Navigate to the form to test, in our case, Vehicle service orders.
  7. Create a new service order, and add two lines. The sidebar will record each interaction with the form, so it can pay off to rehearse this first to minimize the number of steps it creates.
To add validation, right-click on the field and choose Task recorder | Validate | Current value.
  1. Once done, press the Stop button on the top left of the screen.
  2. In the Task recorder sidebar, click on Save as developer recording. Save this file somewhere you can find it later.
  3. Go back to Visual Studio.
  4. To save time, right-click on the ConWHSVehicleManagementTest project and choose Set as StartUp Project.
  5. Choose Import Task Recoding from the Dynamics 365 | Addins menu.
  1. Use the Browse button to find the task recording created earlier. Enter the company used to create the task recording in the Company field. The following screenshot is an example:
If we used the New Project method, we would select the ConWHSVehicleManagementTest model as Model. When creating the project, ensure that the Solution drop-down is set to Add to solution.
  1. This created a class named after the task recording name, which, in our case, is ConWHSServiceOrderTest.
  2. In my case, I added a validation to the line number control, which resulted in the following code in the setupData method:
ConWHSVehicleServiceTable_LinesGrid_LineNum = 0; 
ConWHSVehicleServiceTable_LinesGrid_LineNum1 = 0;
This is clearly a bug, and we can set the expected values by editing this code. In my case, I will make them 1 and 2, respectively.
  1. If we build the project now, we will get missing assembly errors. This is because the generated code references standard form adaptors. Add a reference to the following packages to the ConWHSVehicleManagementTest model:
    • ApplicationFoundationFormAdaptor
    • ApplicationPlatformFormAdaptor
    • ApplicationSuite
    • ApplicationSuiteFormAdaptor
  1. If we hadn't corrected the line numbers, the test run would correctly state the state that the validation for the line number failed. This would then need to be corrected in code and the test rerun.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.145.173