formatted nav patterns

This commit is contained in:
christianbraeunlich 2022-02-05 18:19:26 +01:00
parent 38a19d75d8
commit 2fad891a77
59 changed files with 1403 additions and 1970 deletions

View file

@ -22,23 +22,27 @@ Context: Azure Machine Learning services are paid. However, Dynamics NAV include
The test below checks that, when the monthly quota is exceeded, then the function IsAzureMLLimitReached returns TRUE.
\[Test\]
PROCEDURE AzureMLProcessingTimeExceedsLimit@11();
VAR
```al
[Test]
PROCEDURE AzureMLProcessingTimeExceedsLimit@11();
VAR
AzureMachineLearningUsage@1004 : Record 2002;
ProcessingTime@1000 : Decimal;
BEGIN
// \[SCENARIO\] Azure Machine Learning Processing time exceeds AzureML limit
// \[GIVEN\] AzureMachineLearningUsage \> 0
BEGIN
// [SCENARIO] Azure Machine Learning Processing time exceeds AzureML limit
// [GIVEN] AzureMachineLearningUsage > 0
Initialize; // calls PermissionManager.SetTestabilitySoftwareAsAService(TRUE);
ProcessingTime := LibraryRandom.RandDec(1000,2);
AzureMachineLearningUsage.IncrementTotalProcessingTime(ProcessingTime);
// \[WHEN\] When IsAzureMLLimitReached is invoked with Limit more than Processing time
// \[THEN\] HasAzureLimitReached returns TRUE
AzureMachineLearningUsage.IncrementTotalProcessingTime(ProcessingTime);
// [WHEN] When IsAzureMLLimitReached is invoked with Limit more than Processing time
// [THEN] HasAzureLimitReached returns TRUE
Assert.IsTrue(AzureMachineLearningUsage.IsAzureMLLimitReached(ProcessingTime - 1),
'HasAzureLimitReached returns wrong value when Processing time exceeds Limit.');
'HasAzureLimitReached returns wrong value when Processing time exceeds Limit.');
PermissionManager.SetTestabilitySoftwareAsAService(FALSE);
END;
END;
```
The figure below explains what happens when the Permission Manager is not a singleton. When it is invoked from different places (first from the test, second from the production code), then different instances of the Permission Manager will fire up and answer. In detail:
@ -50,8 +54,6 @@ The figure below explains what happens when the Permission Manager is not a sing
[![ ][image1]][anchor1]
****
**Solution:** restrict the number of instantiations of a codeunit to only one, by setting the codeunit property **SingleInstance** to **Yes**.
Returning to the previous example, let's analyze the case when the codeunit Permission Manager is a singleton codeunit:
@ -60,8 +62,7 @@ Returning to the previous example, let's analyze the case when the codeunit Perm
When the codeunit Permission Manager is a singleton, then no matter from where it is invoked, the same instance will be reached. Therefore, the status set by the test (SaaS = TRUE) will be reachable from the production code, and the test will pass, as seen in the figure below.
**[![ ][image3]][anchor3]
**
[![ ][image3]][anchor3]
**Consequences**
@ -84,9 +85,8 @@ Most of the usages in NAV refer to the so-called "management codeunits". The man
* Codeunit 9002 Permission Manager
* Etc.
**Note:** while the object-oriented **Singleton** pattern can restrict the number of instantiations of the singleton to an integer n \> 0, in Dynamics NAV the **Singleton Codeunit** can only have n=1\.
**Note:** while the object-oriented **Singleton** pattern can restrict the number of instantiations of the singleton to an integer n > 0, in Dynamics NAV the **Singleton Codeunit** can only have n=1\.
__