diff --git a/Peg Board PerformanceTest/.vscode/launch.json b/Peg Board PerformanceTest/.vscode/launch.json new file mode 100644 index 0000000..ac52f4e --- /dev/null +++ b/Peg Board PerformanceTest/.vscode/launch.json @@ -0,0 +1,5 @@ +{ + "version": "0.2.0", + "configurations": [ + ] +} diff --git a/Peg Board PerformanceTest/app.json b/Peg Board PerformanceTest/app.json new file mode 100644 index 0000000..6162e10 --- /dev/null +++ b/Peg Board PerformanceTest/app.json @@ -0,0 +1,54 @@ +{ + "id": "0dd946b2-f463-47b6-8c9b-eb6f1e91a93d", + "name": "Peg Board PerformanceTest", + "publisher": "Morten Seifert", + "version": "1.0.0.0", + "brief": "Performance Toolkit Samples (US)", + "description": "This extension provides tests that simulate business processes, such as creating sales orders, for the Business Central Performance Toolkit. Developers can use these to test for performance regressions during development.", + "platform": "25.0.0.0", + "application": "25.0.0.0", + "runtime": "14.0", + "logo": "", + "url": "", + "EULA": "", + "privacyStatement": "", + "help": "", + "target": "Cloud", + "screenshots": [], + "dependencies": [ + { + "id": "75f1590f-55c5-4501-ae63-bada5534e852", + "publisher": "Microsoft", + "name": "Performance Toolkit", + "version": "25.0.0.0" + }, + { + "id": "5d86850b-0d76-4eca-bd7b-951ad998e997", + "publisher": "Microsoft", + "name": "Tests-TestLibraries", + "version": "25.0.0.0" + } + ], + "idRanges": [ + { + "from": 50800, + "to": 50899 + } + ], + "features": [ + "TranslationFile", + "GenerateCaptions" + ], + "resourceExposurePolicy": { + "allowDebugging": true, + "allowDownloadingSource": true, + "includeSourceInSymbolFile": true + }, + "source": { + "repositoryUrl": "https://github.com/microsoft/BCApps", + "commit": "de3b663d4c9ecd6b92b7ecaf5f23935a47d5634c" + }, + "build": {}, + "internalsVisibleTo": [], + "keyVaultUrls": [] +} diff --git a/Peg Board PerformanceTest/bcptSuite.json b/Peg Board PerformanceTest/bcptSuite.json new file mode 100644 index 0000000..9769bf6 --- /dev/null +++ b/Peg Board PerformanceTest/bcptSuite.json @@ -0,0 +1,54 @@ +{ + "code": "10UserTest", + "description": "10 User Test", + "durationInMinutes": 5, + "defaultMinimumUserDelayInMilliSeconds": 120, + "oneDayCorrespondsToInMinutes": 10, + "tag": "10UserTest", + "bcptSuiteLines": [ + { + "codeunitID": 50807, + "numberOfSessions": 1, + "description": "BCPT Detail Trial Bal. Report", + "minimumUserDelay": 100, + "maximumUserDelay": 1000, + "delayBetweenIterations": 10, + "delayType": "Fixed", + "runInForeground": false + }, + { + "codeunitID": 50803, + "numberOfSessions": 1, + "description": "BCPT Create PO with N Lines", + "minimumUserDelay": 100, + "maximumUserDelay": 1000, + "delayBetweenIterations": 5, + "delayType": "Fixed", + "runInForeground": false, + "parameters": "Lines=10" + }, + { + "codeunitID": 50805, + "numberOfSessions": 1, + "description": "BCPT Create SQ with N Lines", + "minimumUserDelay": 100, + "maximumUserDelay": 1000, + "delayBetweenIterations": 5, + "delayType": "Fixed", + "runInForeground": false, + "parameters": "Lines=10" + }, + { + "codeunitID": 50804, + "numberOfSessions": 1, + "description": "BCPT Create SO with N Lines", + "minimumUserDelay": 100, + "maximumUserDelay": 1000, + "delayBetweenIterations": 5, + "delayType": "Fixed", + "runInForeground": false, + "parameters": "Lines=10" + } + ] +} + diff --git a/Peg Board PerformanceTest/src/BCPTAdjustCostItemEntries.Codeunit.al b/Peg Board PerformanceTest/src/BCPTAdjustCostItemEntries.Codeunit.al new file mode 100644 index 0000000..65150fc --- /dev/null +++ b/Peg Board PerformanceTest/src/BCPTAdjustCostItemEntries.Codeunit.al @@ -0,0 +1,21 @@ +namespace System.Test.Tooling; + +using Microsoft.Inventory.Costing; + +codeunit 50823 "BCPT Adjust Cost Item Entries" +{ + trigger OnRun() + begin + AdjusCostItemEntries(); + end; + + local procedure AdjusCostItemEntries() + var + AdjustCostItemEntries: Report "Adjust Cost - Item Entries"; + begin + //Adjust and post to GL + AdjustCostItemEntries.SetPostToGL(true); + AdjustCostItemEntries.UseRequestPage(false); + AdjustCostItemEntries.Run(); + end; +} diff --git a/Peg Board PerformanceTest/src/BCPTCalculatePlanWorksheet.Codeunit.al b/Peg Board PerformanceTest/src/BCPTCalculatePlanWorksheet.Codeunit.al new file mode 100644 index 0000000..d0110a6 --- /dev/null +++ b/Peg Board PerformanceTest/src/BCPTCalculatePlanWorksheet.Codeunit.al @@ -0,0 +1,25 @@ +namespace System.Test.Tooling; + +using Microsoft.Manufacturing.Planning; + +codeunit 50824 "BCPT Calculate Plan Worksheet" +{ + trigger OnRun() + begin + CalculatePlan(); + end; + + local procedure CalculatePlan() + var + CalculatePlanPlanWksh: Report "Calculate Plan - Plan. Wksh."; + StartingDate: Date; + EndingDate: Date; + begin + //Start Calculate regenerative plan of the current month + StartingDate := CalcDate('<-CM>', WorkDate()); + EndingDate := CalcDate('', WorkDate()); + CalculatePlanPlanWksh.UseRequestPage(false); + CalculatePlanPlanWksh.InitializeRequest(StartingDate, EndingDate, true); + CalculatePlanPlanWksh.Run(); + end; +} diff --git a/Peg Board PerformanceTest/src/BCPTCreateCustomer.Codeunit.al b/Peg Board PerformanceTest/src/BCPTCreateCustomer.Codeunit.al new file mode 100644 index 0000000..9c6967d --- /dev/null +++ b/Peg Board PerformanceTest/src/BCPTCreateCustomer.Codeunit.al @@ -0,0 +1,154 @@ +namespace System.Test.Tooling; + +using System.Tooling; +using Microsoft.Sales.Setup; +using Microsoft.Foundation.NoSeries; +using Microsoft.Sales.Customer; +using Microsoft.CRM.BusinessRelation; +using Microsoft.Finance.GeneralLedger.Setup; +using Microsoft.Finance.VAT.Setup; +using Microsoft.Foundation.PaymentTerms; +using Microsoft.Bank.BankAccount; + +codeunit 50826 "BCPT Create Customer" implements "BCPT Test Param. Provider" +{ + trigger OnRun() + begin + InitTest(); + CreateCustomer(); + end; + + var + BCPTTestContext: Codeunit "BCPT Test Context"; + CustomerTemplateToUse: Code[20]; + CustomerTemplateParamLbl: Label 'Customer Template'; + ParamValidationErr: Label 'Parameter is not defined in the correct format. The expected format is "%1"', Comment = '%1 = Default Parameter'; + + local procedure InitTest() + var + SalesReceivablesSetup: Record "Sales & Receivables Setup"; + NoSeriesLine: Record "No. Series Line"; + RecordModified: Boolean; + begin + SalesReceivablesSetup.Get(); + SalesReceivablesSetup.TestField("Customer Nos."); + NoSeriesLine.SetRange("Series Code", SalesReceivablesSetup."Customer Nos."); + NoSeriesLine.FindSet(true); + repeat + if NoSeriesLine."Ending No." <> '' then begin + NoSeriesLine."Ending No." := ''; + NoSeriesLine.Validate(Implementation, NoSeriesLine.Implementation::Sequence); + NoSeriesLine.Modify(true); + RecordModified := true; + end; + until NoSeriesLine.Next() = 0; + + if RecordModified then + Commit(); //Commit to avoid deadlocks + + if Evaluate(CustomerTemplateToUse, BCPTTestContext.GetParameter(CustomerTemplateParamLbl)) then; + end; + + local procedure CreateCustomer() + var + Customer: Record Customer; + CustomerTempl: Record "Customer Templ."; + CustContUpdate: Codeunit "CustCont-Update"; + CustomerTemplMgt: Codeunit "Customer Templ. Mgt."; + begin + Clear(Customer); + Customer.Insert(true); + Customer.Validate(Name, Customer."No."); + + if CustomerTemplateToUse <> '' then begin + CustomerTempl.Get(CustomerTemplateToUse); + CustomerTemplMgt.ApplyCustomerTemplate(Customer, CustomerTempl) + end else begin + Customer.Validate("Gen. Bus. Posting Group", LookUpGenBusPostingGroup()); + Customer.Validate("VAT Bus. Posting Group", FindVATPostingSetup()); + Customer.Validate("Customer Posting Group", FindCustomerPostingGroup()); + Customer.Validate("Payment Terms Code", FindPaymentTermsCode()); + Customer.Validate("Payment Method Code", FindPaymentMethod()); + Customer.Modify(true); + end; + Commit(); //Commit to avoid deadlocks + CustContUpdate.OnModify(Customer); + + OnAfterCreateCustomer(Customer); + Commit(); //Commit to avoid deadlocks + end; + + local procedure LookUpGenBusPostingGroup(): Code[20] + var + GeneralPostingSetup: Record "General Posting Setup"; + begin + GeneralPostingSetup.Reset(); + GeneralPostingSetup.SetFilter("Gen. Prod. Posting Group", '<>%1', ''); + GeneralPostingSetup.SetFilter("Purch. Account", '<>%1', ''); + if GeneralPostingSetup.FindFirst() then + exit(GeneralPostingSetup."Gen. Bus. Posting Group"); + end; + + local procedure FindCustomerPostingGroup(): Code[20] + var + CustomerPostingGroup: Record "Customer Posting Group"; + begin + CustomerPostingGroup.SetFilter("Receivables Account", '<>%1', ''); + if CustomerPostingGroup.FindFirst() then + exit(CustomerPostingGroup.Code); + end; + + local procedure FindVATPostingSetup(): Code[20] + var + VATPostingSetup: Record "VAT Posting Setup"; + begin + VATPostingSetup.SetFilter("VAT Prod. Posting Group", '<>%1', ''); + VATPostingSetup.SetFilter("VAT %", '<>%1', 0); + VATPostingSetup.SetRange("VAT Calculation Type", VATPostingSetup."VAT Calculation Type"::"Normal VAT"); + VATPostingSetup.SetFilter("Sales VAT Account", '<>%1', ''); + if VATPostingSetup.FindFirst() then + exit(VATPostingSetup."VAT Bus. Posting Group"); + end; + + local procedure FindPaymentTermsCode(): Code[10] + var + PaymentTerms: Record "Payment Terms"; + DateFormular_0D: DateFormula; + begin + Evaluate(DateFormular_0D, '<0D>'); + + if PaymentTerms.FieldActive("Due Date Calculation") then + PaymentTerms.SetRange("Due Date Calculation", DateFormular_0D); + if PaymentTerms.FindFirst() then + exit(PaymentTerms.Code); + end; + + local procedure FindPaymentMethod(): Code[10] + var + PaymentMethod: Record "Payment Method"; + begin + PaymentMethod.SetRange("Bal. Account No.", ''); + if PaymentMethod.FindFirst() then + exit(PaymentMethod.Code) + end; + + procedure GetDefaultParameters(): Text[1000] + begin + exit(CopyStr(CustomerTemplateParamLbl + '=', 1, 1000)); + end; + + procedure ValidateParameters(Parameters: Text[1000]) + begin + if StrPos(Parameters, CustomerTemplateParamLbl) > 0 then begin + Parameters := DelStr(Parameters, 1, StrLen(CustomerTemplateParamLbl + '=')); + if Evaluate(CustomerTemplateToUse, Parameters) then + exit; + end; + Error(ParamValidationErr, GetDefaultParameters()); + end; + + [IntegrationEvent(false, false)] + local procedure OnAfterCreateCustomer(var Customer: Record Customer) + begin + end; +} diff --git a/Peg Board PerformanceTest/src/BCPTCreateItem.Codeunit.al b/Peg Board PerformanceTest/src/BCPTCreateItem.Codeunit.al new file mode 100644 index 0000000..60444e1 --- /dev/null +++ b/Peg Board PerformanceTest/src/BCPTCreateItem.Codeunit.al @@ -0,0 +1,113 @@ +namespace System.Test.Tooling; + +using Microsoft.Inventory.Setup; +using Microsoft.Foundation.NoSeries; +using Microsoft.Inventory.Item; +using Microsoft.Foundation.UOM; +using Microsoft.Finance.GeneralLedger.Setup; +using Microsoft.Finance.VAT.Setup; + +codeunit 50827 "BCPT Create Item" +{ + trigger OnRun() + begin + InitTest(); + CreateItem(); + end; + + local procedure InitTest(); + var + InventorySetup: Record "Inventory Setup"; + NoSeriesLine: Record "No. Series Line"; + RecordModified: Boolean; + begin + InventorySetup.Get(); + InventorySetup.TestField("Item Nos."); + NoSeriesLine.SetRange("Series Code", InventorySetup."Item Nos."); + NoSeriesLine.FindSet(true); + repeat + if NoSeriesLine."Ending No." <> '' then begin + NoSeriesLine."Ending No." := ''; + NoSeriesLine.Validate(Implementation, NoSeriesLine.Implementation::Sequence); + NoSeriesLine.Modify(true); + RecordModified := true; + end; + until NoSeriesLine.Next() = 0; + + if RecordModified then + Commit(); //Commit to avoid deadlocks + end; + + procedure CreateItem() + var + Item: Record Item; + ItemUnitOfMeasure: Record "Item Unit of Measure"; + begin + Clear(Item); + Item.Insert(true); + + CreateItemUnitOfMeasureCode(Item."No.", ItemUnitOfMeasure); + + Item.Validate(Description, Item."No."); + Item.Validate("Base Unit of Measure", ItemUnitOfMeasure.Code); + Item.Validate("Gen. Prod. Posting Group", LookUpGenProdPostingGroup()); + Item.Validate("Inventory Posting Group", FindInventoryPostingSetup()); + Item.Validate("VAT Prod. Posting Group", FindVATPostingSetup()); + Item.Modify(true); + Commit(); //Commit to avoid deadlocks + + OnAfterCreateItem(Item); + end; + + local procedure CreateItemUnitOfMeasureCode(ItemNo: Code[20]; var ItemUnitOfMeasure: Record "Item Unit of Measure") + var + UnitOfMeasure: Record "Unit of Measure"; + begin + UnitOfMeasure.Reset(); + if UnitOfMeasure.FindFirst() then + ItemUnitOfMeasure.Init(); + ItemUnitOfMeasure.Validate("Item No.", ItemNo); + ItemUnitOfMeasure.Validate(Code, UnitOfMeasure.Code); + ItemUnitOfMeasure.Validate("Qty. per Unit of Measure", 1); + ItemUnitOfMeasure.Insert(true); + end; + + local procedure LookUpGenProdPostingGroup(): Code[20] + var + GeneralPostingSetup: Record "General Posting Setup"; + begin + GeneralPostingSetup.Reset(); + GeneralPostingSetup.SetFilter("Gen. Prod. Posting Group", '<>%1', ''); + GeneralPostingSetup.SetFilter("Purch. Account", '<>%1', ''); + if GeneralPostingSetup.FindFirst() then + exit(GeneralPostingSetup."Gen. Prod. Posting Group"); + end; + + local procedure FindInventoryPostingSetup(): Code[20] + var + InventoryPostingSetup: Record "Inventory Posting Setup"; + begin + InventoryPostingSetup.Reset(); + InventoryPostingSetup.SetFilter("Inventory Account", '<>%1', ''); + InventoryPostingSetup.SetFilter("Location Code", '%1', ''); + if InventoryPostingSetup.FindFirst() then + exit(InventoryPostingSetup."Invt. Posting Group Code"); + end; + + local procedure FindVATPostingSetup(): Code[20] + var + VATPostingSetup: Record "VAT Posting Setup"; + begin + VATPostingSetup.SetFilter("VAT Prod. Posting Group", '<>%1', ''); + VATPostingSetup.SetFilter("VAT %", '<>%1', 0); + VATPostingSetup.SetRange("VAT Calculation Type", VATPostingSetup."VAT Calculation Type"::"Normal VAT"); + if VATPostingSetup.FindFirst() then + exit(VATPostingSetup."VAT Prod. Posting Group"); + end; + + [IntegrationEvent(false, false)] + local procedure OnAfterCreateItem(var Item: Record Item) + begin + end; +} + diff --git a/Peg Board PerformanceTest/src/BCPTCreatePOWithNLines.Codeunit.al b/Peg Board PerformanceTest/src/BCPTCreatePOWithNLines.Codeunit.al new file mode 100644 index 0000000..6424d65 --- /dev/null +++ b/Peg Board PerformanceTest/src/BCPTCreatePOWithNLines.Codeunit.al @@ -0,0 +1,123 @@ +namespace System.Test.Tooling; + +using Microsoft.Foundation.NoSeries; +using Microsoft.Inventory.Item; +using Microsoft.Purchases.Document; +using Microsoft.Purchases.Setup; +using Microsoft.Purchases.Vendor; +using System.Tooling; + +codeunit 50803 "BCPT Create PO with N Lines" implements "BCPT Test Param. Provider" +{ + SingleInstance = true; + + trigger OnRun(); + begin + if not IsInitialized then begin + InitTest(); + IsInitialized := true; + end; + CreatePurchaseOrder(GlobalBCPTTestContext); + end; + + var + GlobalBCPTTestContext: Codeunit "BCPT Test Context"; + IsInitialized: Boolean; + NoOfLinesParamLbl: Label 'Lines'; + ParamValidationErr: Label 'Parameter is not defined in the correct format. The expected format is "%1"', Comment = '%1 = a string'; + NoOfLinesToCreate: Integer; + + + local procedure InitTest(); + var + PurchaseSetup: Record "Purchases & Payables Setup"; + NoSeriesLine: Record "No. Series Line"; + RecordModified: Boolean; + begin + PurchaseSetup.Get(); + PurchaseSetup.TestField("Order Nos."); + NoSeriesLine.SetRange("Series Code", PurchaseSetup."Order Nos."); + NoSeriesLine.FindSet(true); + repeat + if NoSeriesLine."Ending No." <> '' then begin + NoSeriesLine."Ending No." := ''; + NoSeriesLine.Validate(Implementation, Enum::"No. Series Implementation"::Sequence); + NoSeriesLine.Modify(true); + RecordModified := true; + end; + until NoSeriesLine.Next() = 0; + + if RecordModified then + Commit(); + + if Evaluate(NoOfLinesToCreate, GlobalBCPTTestContext.GetParameter(NoOfLinesParamLbl)) then; + end; + + local procedure CreatePurchaseOrder(var BCPTTestContext: Codeunit "BCPT Test Context") + var + Vendor: Record Vendor; + Item: Record Item; + PurchaseHeader: Record "Purchase Header"; + PurchaseLine: Record "Purchase Line"; + i: Integer; + begin + if not Vendor.get('10000') then + Vendor.FindFirst(); + if not Item.get('70000') then + Item.FindFirst(); + if NoOfLinesToCreate < 0 then + NoOfLinesToCreate := 0; + if NoOfLinesToCreate > 10000 then + NoOfLinesToCreate := 10000; + BCPTTestContext.StartScenario('Add Order'); + PurchaseHeader.init(); + PurchaseHeader."Document Type" := PurchaseHeader."Document Type"::Order; + PurchaseHeader.Insert(true); + BCPTTestContext.EndScenario('Add Order'); + BCPTTestContext.UserWait(); + BCPTTestContext.StartScenario('Enter Account No.'); + PurchaseHeader.Validate("Buy-from Vendor No.", Vendor."No."); + PurchaseHeader.Modify(true); + Commit(); + BCPTTestContext.EndScenario('Enter Account No.'); + BCPTTestContext.UserWait(); + PurchaseLine."Document Type" := PurchaseHeader."Document Type"; + PurchaseLine."Document No." := PurchaseHeader."No."; + for i := 1 to NoOfLinesToCreate do begin + PurchaseLine."Line No." += 10000; + PurchaseLine.Init(); + PurchaseLine.Validate(Type, PurchaseLine.Type::Item); + PurchaseLine.Insert(true); + BCPTTestContext.UserWait(); + if i = 10 then + BCPTTestContext.StartScenario('Enter Line Item No.'); + PurchaseLine.Validate("No.", Item."No."); + if i = 10 then + BCPTTestContext.EndScenario('Enter Line Item No.'); + BCPTTestContext.UserWait(); + if i = 10 then + BCPTTestContext.StartScenario('Enter Line Quantity'); + PurchaseLine.Validate(Quantity, 1); + if i = 10 then + BCPTTestContext.EndScenario('Enter Line Quantity'); + PurchaseLine.Modify(true); + Commit(); + BCPTTestContext.UserWait(); + end; + end; + + procedure GetDefaultParameters(): Text[1000] + begin + exit(copystr(NoOfLinesParamLbl + '=' + Format(10), 1, 1000)); + end; + + procedure ValidateParameters(Parameters: Text[1000]) + begin + if StrPos(Parameters, NoOfLinesParamLbl) > 0 then begin + Parameters := DelStr(Parameters, 1, StrLen(NoOfLinesParamLbl + '=')); + if Evaluate(NoOfLinesToCreate, Parameters) then + exit; + end; + Error(ParamValidationErr, GetDefaultParameters()); + end; +} diff --git a/Peg Board PerformanceTest/src/BCPTCreateSOWithNLines.Codeunit.al b/Peg Board PerformanceTest/src/BCPTCreateSOWithNLines.Codeunit.al new file mode 100644 index 0000000..4306456 --- /dev/null +++ b/Peg Board PerformanceTest/src/BCPTCreateSOWithNLines.Codeunit.al @@ -0,0 +1,127 @@ +namespace System.Test.Tooling; + +using Microsoft.Foundation.NoSeries; +using Microsoft.Inventory.Item; +using Microsoft.Sales.Customer; +using Microsoft.Sales.Document; +using Microsoft.Sales.Setup; +using System.Tooling; + +codeunit 50804 "BCPT Create SO with N Lines" implements "BCPT Test Param. Provider" +{ + SingleInstance = true; + + trigger OnRun(); + begin + if not IsInitialized then begin + InitTest(); + IsInitialized := true; + end; + CreateSalesOrder(GlobalBCPTTestContext); + end; + + var + GlobalBCPTTestContext: Codeunit "BCPT Test Context"; + IsInitialized: Boolean; + NoOfLinesToCreate: Integer; + NoOfLinesParamLbl: Label 'Lines'; + ParamValidationErr: Label 'Parameter is not defined in the correct format. The expected format is "%1"', Comment = '%1 = a string'; + + local procedure InitTest(); + var + SalesSetup: Record "Sales & Receivables Setup"; + NoSeriesLine: Record "No. Series Line"; + RecordModified: Boolean; + begin + SalesSetup.Get(); + SalesSetup.TestField("Order Nos."); + NoSeriesLine.SetRange("Series Code", SalesSetup."Order Nos."); + NoSeriesLine.FindSet(true); + repeat + if NoSeriesLine."Ending No." <> '' then begin + NoSeriesLine."Ending No." := ''; + NoSeriesLine.Validate(Implementation, Enum::"No. Series Implementation"::Sequence); + NoSeriesLine.Modify(true); + RecordModified := true; + end; + until NoSeriesLine.Next() = 0; + + if RecordModified then + Commit(); + + if Evaluate(NoOfLinesToCreate, GlobalBCPTTestContext.GetParameter(NoOfLinesParamLbl)) then; + end; + + local procedure CreateSalesOrder(var BCPTTestContext: Codeunit "BCPT Test Context") + var + Customer: Record Customer; + Item: Record Item; + SalesHeader: Record "Sales Header"; + SalesLine: Record "Sales Line"; + i: Integer; + begin + if not Customer.get('10000') then + Customer.FindFirst(); + if not item.get('70000') then + Item.FindSet(); + if NoOfLinesToCreate < 0 then + NoOfLinesToCreate := 0; + if NoOfLinesToCreate > 10000 then + NoOfLinesToCreate := 10000; + BCPTTestContext.StartScenario('Add Order'); + SalesHeader.Init(); + SalesHeader."Document Type" := SalesHeader."Document Type"::Order; + SalesHeader.Insert(true); + Commit(); + BCPTTestContext.EndScenario('Add Order'); + BCPTTestContext.UserWait(); + BCPTTestContext.StartScenario('Enter Account No.'); + SalesHeader.Validate("Sell-to Customer No.", Customer."No."); + SalesHeader.Modify(true); + Commit(); + BCPTTestContext.EndScenario('Enter Account No.'); + BCPTTestContext.UserWait(); + SalesLine."Document Type" := SalesHeader."Document Type"; + SalesLine."Document No." := SalesHeader."No."; + for i := 1 to NoOfLinesToCreate do begin + SalesLine."Line No." += 10000; + SalesLine.Init(); + SalesLine.Validate(Type, SalesLine.Type::Item); + SalesLine.Insert(true); + BCPTTestContext.UserWait(); + if i = 1 then + BCPTTestContext.StartScenario('Enter Line Item No.'); + SalesLine.Validate("No.", Item."No."); + if i = 1 then + BCPTTestContext.EndScenario('Enter Line Item No.'); + BCPTTestContext.UserWait(); + if i = 1 then + BCPTTestContext.StartScenario('Enter Line Quantity'); + SalesLine.Validate(Quantity, 1); + SalesLine.Modify(true); + if i = 1 then + BCPTTestContext.EndScenario('Enter Line Quantity'); + BCPTTestContext.UserWait(); + if i mod 2 = 0 then + if Item.Next() = 0 then +#pragma warning disable AA0181, AA0175 + Item.FindSet(); +#pragma warning restore AA0181, AA0175 + end; + end; + + procedure GetDefaultParameters(): Text[1000] + begin + exit(copystr(NoOfLinesParamLbl + '=' + Format(10), 1, 1000)); + end; + + procedure ValidateParameters(Parameters: Text[1000]) + begin + if StrPos(Parameters, NoOfLinesParamLbl) > 0 then begin + Parameters := DelStr(Parameters, 1, StrLen(NoOfLinesParamLbl + '=')); + if Evaluate(NoOfLinesToCreate, Parameters) then + exit; + end; + Error(ParamValidationErr, GetDefaultParameters()); + end; +} diff --git a/Peg Board PerformanceTest/src/BCPTCreateSQWithNLines.Codeunit.al b/Peg Board PerformanceTest/src/BCPTCreateSQWithNLines.Codeunit.al new file mode 100644 index 0000000..4c5e90b --- /dev/null +++ b/Peg Board PerformanceTest/src/BCPTCreateSQWithNLines.Codeunit.al @@ -0,0 +1,122 @@ +namespace System.Test.Tooling; + +using Microsoft.Foundation.NoSeries; +using Microsoft.Inventory.Item; +using Microsoft.Sales.Customer; +using Microsoft.Sales.Document; +using Microsoft.Sales.Setup; +using System.Tooling; + +codeunit 50805 "BCPT Create SQ with N Lines" implements "BCPT Test Param. Provider" +{ + SingleInstance = true; + + trigger OnRun(); + begin + if not IsInitialized then begin + InitTest(); + IsInitialized := true; + end; + CreateSalesQuote(GlobalBCPTTestContext); + end; + + var + GlobalBCPTTestContext: Codeunit "BCPT Test Context"; + IsInitialized: Boolean; + NoOfLinesToCreate: Integer; + NoOfLinesParamLbl: Label 'Lines'; + ParamValidationErr: Label 'Parameter is not defined in the correct format. The expected format is "%1"', Comment = '%1 is a string'; + + local procedure InitTest(); + var + SalesSetup: Record "Sales & Receivables Setup"; + NoSeriesLine: Record "No. Series Line"; + RecordModified: Boolean; + begin + SalesSetup.Get(); + SalesSetup.TestField("Quote Nos."); + NoSeriesLine.SetRange("Series Code", SalesSetup."Quote Nos."); + NoSeriesLine.FindSet(true); + repeat + if NoSeriesLine."Ending No." <> '' then begin + NoSeriesLine."Ending No." := ''; + NoSeriesLine.Validate(Implementation, Enum::"No. Series Implementation"::Sequence); + NoSeriesLine.Modify(true); + RecordModified := true; + end; + until NoSeriesLine.Next() = 0; + + if RecordModified then + Commit(); + + if Evaluate(NoOfLinesToCreate, GlobalBCPTTestContext.GetParameter(NoOfLinesParamLbl)) then; + end; + + local procedure CreateSalesQuote(var BCPTTestContext: Codeunit "BCPT Test Context") + var + Customer: Record Customer; + Item: Record Item; + SalesHeader: Record "Sales Header"; + SalesLine: Record "Sales Line"; + i: Integer; + begin + if not Customer.get('10000') then + Customer.FindFirst(); + if not item.get('70000') then + Item.FindFirst(); + if NoOfLinesToCreate < 0 then + NoOfLinesToCreate := 0; + if NoOfLinesToCreate > 10000 then + NoOfLinesToCreate := 10000; + BCPTTestContext.StartScenario('Add Order'); + SalesHeader.init(); + SalesHeader."Document Type" := SalesHeader."Document Type"::Quote; + SalesHeader.Insert(true); + BCPTTestContext.EndScenario('Add Order'); + Commit(); + BCPTTestContext.UserWait(); + BCPTTestContext.StartScenario('Enter Account No.'); + SalesHeader.Validate("Sell-to Customer No.", Customer."No."); + SalesHeader.Modify(true); + Commit(); + BCPTTestContext.EndScenario('Enter Account No.'); + BCPTTestContext.UserWait(); + SalesLine."Document Type" := SalesHeader."Document Type"; + SalesLine."Document No." := SalesHeader."No."; + for i := 1 to NoOfLinesToCreate do begin + SalesLine."Line No." += 10000; + SalesLine.Init(); + SalesLine.Validate(Type, SalesLine.Type::Item); + SalesLine.Insert(true); + BCPTTestContext.UserWait(); + if i = 10 then + BCPTTestContext.StartScenario('Enter Line Item No.'); + SalesLine.Validate("No.", Item."No."); + if i = 10 then + BCPTTestContext.EndScenario('Enter Line Item No.'); + BCPTTestContext.UserWait(); + if i = 10 then + BCPTTestContext.StartScenario('Enter Line Quantity'); + SalesLine.Validate(Quantity, 1); + SalesLine.Modify(true); + Commit(); + if i = 10 then + BCPTTestContext.EndScenario('Enter Line Quantity'); + end; + end; + + procedure GetDefaultParameters(): Text[1000] + begin + exit(copystr(NoOfLinesParamLbl + '=' + Format(10), 1, 1000)); + end; + + procedure ValidateParameters(Parameters: Text[1000]) + begin + if StrPos(Parameters, NoOfLinesParamLbl) > 0 then begin + Parameters := DelStr(Parameters, 1, StrLen(NoOfLinesParamLbl + '=')); + if Evaluate(NoOfLinesToCreate, Parameters) then + exit; + end; + Error(ParamValidationErr, GetDefaultParameters()); + end; +} diff --git a/Peg Board PerformanceTest/src/BCPTCreateVendor.Codeunit.al b/Peg Board PerformanceTest/src/BCPTCreateVendor.Codeunit.al new file mode 100644 index 0000000..9ccabde --- /dev/null +++ b/Peg Board PerformanceTest/src/BCPTCreateVendor.Codeunit.al @@ -0,0 +1,153 @@ +namespace System.Test.Tooling; + +using System.Tooling; +using Microsoft.Purchases.Setup; +using Microsoft.Foundation.NoSeries; +using Microsoft.Purchases.Vendor; +using Microsoft.CRM.BusinessRelation; +using Microsoft.Finance.GeneralLedger.Setup; +using Microsoft.Finance.VAT.Setup; +using Microsoft.Foundation.PaymentTerms; +using Microsoft.Bank.BankAccount; + +codeunit 50825 "BCPT Create Vendor" implements "BCPT Test Param. Provider" +{ + trigger OnRun() + begin + InitTest(); + CreateVendor(); + end; + + var + BCPTTestContext: Codeunit "BCPT Test Context"; + VendorTemplateToUse: Code[20]; + VendorTemplateParamLbl: Label 'Vendor Template'; + ParamValidationErr: Label 'Parameter is not defined in the correct format. The expected format is "%1"', Comment = '%1 = Default Parameter'; + + local procedure InitTest(); + var + PurchasesPayablesSetup: Record "Purchases & Payables Setup"; + NoSeriesLine: Record "No. Series Line"; + RecordModified: Boolean; + begin + PurchasesPayablesSetup.Get(); + PurchasesPayablesSetup.TestField("Vendor Nos."); + NoSeriesLine.SetRange("Series Code", PurchasesPayablesSetup."Vendor Nos."); + NoSeriesLine.FindSet(true); + repeat + if NoSeriesLine."Ending No." <> '' then begin + NoSeriesLine."Ending No." := ''; + NoSeriesLine.Validate(Implementation, NoSeriesLine.Implementation::Sequence); + NoSeriesLine.Modify(true); + RecordModified := true; + end; + until NoSeriesLine.Next() = 0; + + if RecordModified then + Commit(); //Commit to avoid deadlocks + + if Evaluate(VendorTemplateToUse, BCPTTestContext.GetParameter(VendorTemplateParamLbl)) then; + end; + + local procedure CreateVendor() + var + Vendor: Record Vendor; + VendorTempl: Record "Vendor Templ."; + VendContUpdate: Codeunit "VendCont-Update"; + VendorTemplMgt: Codeunit "Vendor Templ. Mgt."; + begin + Clear(Vendor); + Vendor.Insert(true); + Vendor.Validate(Name, Vendor."No."); + if VendorTemplateToUse <> '' then begin + VendorTempl.Get(VendorTemplateToUse); + VendorTemplMgt.ApplyVendorTemplate(Vendor, VendorTempl) + end else begin + Vendor.Validate("Gen. Bus. Posting Group", LookUpGenBusPostingGroup()); + Vendor.Validate("VAT Bus. Posting Group", FindVATPostingSetup()); + Vendor.Validate("Vendor Posting Group", FindVendorPostingGroup()); + Vendor.Validate("Payment Terms Code", FindPaymentTermsCode()); + Vendor.Validate("Payment Method Code", FindPaymentMethod()); + Vendor.Modify(true); + end; + Commit(); //Commit to avoid deadlocks + VendContUpdate.OnModify(Vendor); + + OnAfterCreateVendor(Vendor); + Commit(); //Commit to avoid deadlocks + end; + + local procedure LookUpGenBusPostingGroup(): Code[20] + var + GeneralPostingSetup: Record "General Posting Setup"; + begin + GeneralPostingSetup.Reset(); + GeneralPostingSetup.SetFilter("Gen. Prod. Posting Group", '<>%1', ''); + GeneralPostingSetup.SetFilter("Purch. Account", '<>%1', ''); + if GeneralPostingSetup.FindFirst() then + exit(GeneralPostingSetup."Gen. Bus. Posting Group"); + end; + + local procedure FindVendorPostingGroup(): Code[20] + var + VendorPostingGroup: Record "Vendor Posting Group"; + begin + VendorPostingGroup.SetFilter("Payables Account", '<>%1', ''); + if VendorPostingGroup.FindFirst() then + exit(VendorPostingGroup.Code); + end; + + local procedure FindVATPostingSetup(): Code[20] + var + VATPostingSetup: Record "VAT Posting Setup"; + begin + VATPostingSetup.SetFilter("VAT Prod. Posting Group", '<>%1', ''); + VATPostingSetup.SetFilter("VAT %", '<>%1', 0); + VATPostingSetup.SetRange("VAT Calculation Type", VATPostingSetup."VAT Calculation Type"::"Normal VAT"); + VATPostingSetup.SetFilter("Purchase VAT Account", '<>%1', ''); + if VATPostingSetup.FindFirst() then + exit(VATPostingSetup."VAT Bus. Posting Group"); + end; + + local procedure FindPaymentTermsCode(): Code[10] + var + PaymentTerms: Record "Payment Terms"; + DateFormular_0D: DateFormula; + begin + Evaluate(DateFormular_0D, '<0D>'); + + if PaymentTerms.FieldActive("Due Date Calculation") then + PaymentTerms.SetRange("Due Date Calculation", DateFormular_0D); + if PaymentTerms.FindFirst() then + exit(PaymentTerms.Code); + end; + + local procedure FindPaymentMethod(): Code[10] + var + PaymentMethod: Record "Payment Method"; + begin + PaymentMethod.SetRange("Bal. Account No.", ''); + if PaymentMethod.FindFirst() then + exit(PaymentMethod.Code) + end; + + procedure GetDefaultParameters(): Text[1000] + begin + exit(CopyStr(VendorTemplateParamLbl + '=', 1, 1000)); + end; + + procedure ValidateParameters(Parameters: Text[1000]) + begin + if StrPos(Parameters, VendorTemplateParamLbl) > 0 then begin + Parameters := DelStr(Parameters, 1, StrLen(VendorTemplateParamLbl + '=')); + if Evaluate(VendorTemplateToUse, Parameters) then + exit; + end; + Error(ParamValidationErr, GetDefaultParameters()); + end; + + [IntegrationEvent(false, false)] + local procedure OnAfterCreateVendor(var Vendor: Record Vendor) + begin + end; +} diff --git a/Peg Board PerformanceTest/src/BCPTDetailTrialBalReport.Codeunit.al b/Peg Board PerformanceTest/src/BCPTDetailTrialBalReport.Codeunit.al new file mode 100644 index 0000000..f110cec --- /dev/null +++ b/Peg Board PerformanceTest/src/BCPTDetailTrialBalReport.Codeunit.al @@ -0,0 +1,17 @@ +namespace System.Test.Tooling; + +using Microsoft.Finance.GeneralLedger.Reports; +using System.Utilities; + +codeunit 50807 "BCPT Detail Trial Bal. Report" +{ + trigger OnRun(); + var + DetailTrialBal: Report "Detail Trial Balance"; + TempBlob: Codeunit "Temp Blob"; + OutStr: OutStream; + begin + TempBlob.CreateOutstream(OutStr); + DetailTrialBal.SaveAs('', ReportFormat::Pdf, OutStr); + end; +} diff --git a/Peg Board PerformanceTest/src/BCPTMakeWebCall.Codeunit.al b/Peg Board PerformanceTest/src/BCPTMakeWebCall.Codeunit.al new file mode 100644 index 0000000..a55af0d --- /dev/null +++ b/Peg Board PerformanceTest/src/BCPTMakeWebCall.Codeunit.al @@ -0,0 +1,21 @@ +namespace System.Test.Tooling; + +codeunit 50808 "BCPT Make Web Call" +{ + SingleInstance = true; + + trigger OnRun(); + var + NewUrl: text; + RequestMessage: HttpRequestMessage; + ResponseMessage: HttpResponseMessage; + Client: HttpClient; + begin + NewUrl := 'https://www.microsoft.com'; + + RequestMessage.SetRequestUri(NewUrl); + RequestMessage.Method('GET'); + + Client.Send(RequestMessage, ResponseMessage); + end; +} diff --git a/Peg Board PerformanceTest/src/BCPTOpenChartOfAccounts.Codeunit.al b/Peg Board PerformanceTest/src/BCPTOpenChartOfAccounts.Codeunit.al new file mode 100644 index 0000000..adf11b0 --- /dev/null +++ b/Peg Board PerformanceTest/src/BCPTOpenChartOfAccounts.Codeunit.al @@ -0,0 +1,22 @@ +namespace System.Test.Tooling; + +using Microsoft.Finance.GeneralLedger.Account; + +codeunit 50809 "BCPT Open Chart of Accounts" +{ + // Test codeunits can only run in foreground (UI) + Subtype = Test; + + trigger OnRun(); + begin + end; + + [Test] + procedure OpenChartAccount() + var + ChartAccount: testpage "Chart of Accounts"; + begin + ChartAccount.OpenView(); + ChartAccount.Close(); + end; +} diff --git a/Peg Board PerformanceTest/src/BCPTOpenCustomerList.Codeunit.al b/Peg Board PerformanceTest/src/BCPTOpenCustomerList.Codeunit.al new file mode 100644 index 0000000..972befa --- /dev/null +++ b/Peg Board PerformanceTest/src/BCPTOpenCustomerList.Codeunit.al @@ -0,0 +1,22 @@ +namespace System.Test.Tooling; + +using Microsoft.Sales.Customer; + +codeunit 50810 "BCPT Open Customer List" +{ + // Test codeunits can only run in foreground (UI) + Subtype = Test; + + trigger OnRun(); + begin + end; + + [Test] + procedure OpenCustomerList() + var + CustomerList: testpage "Customer List"; + begin + CustomerList.OpenView(); + CustomerList.Close(); + end; +} diff --git a/Peg Board PerformanceTest/src/BCPTOpenItemList.Codeunit.al b/Peg Board PerformanceTest/src/BCPTOpenItemList.Codeunit.al new file mode 100644 index 0000000..85bd95c --- /dev/null +++ b/Peg Board PerformanceTest/src/BCPTOpenItemList.Codeunit.al @@ -0,0 +1,22 @@ +namespace System.Test.Tooling; + +using Microsoft.Inventory.Item; + +codeunit 50811 "BCPT Open Item List" +{ + // Test codeunits can only run in foreground (UI) + Subtype = Test; + + trigger OnRun(); + begin + end; + + [Test] + procedure OpenItemList() + var + ItemList: testpage "Item List"; + begin + ItemList.OpenView(); + ItemList.Close(); + end; +} diff --git a/Peg Board PerformanceTest/src/BCPTOpenPurchInvoiceList.Codeunit.al b/Peg Board PerformanceTest/src/BCPTOpenPurchInvoiceList.Codeunit.al new file mode 100644 index 0000000..a3a1acb --- /dev/null +++ b/Peg Board PerformanceTest/src/BCPTOpenPurchInvoiceList.Codeunit.al @@ -0,0 +1,22 @@ +namespace System.Test.Tooling; + +using Microsoft.Purchases.Document; + +codeunit 50812 "BCPT Open Purch. Invoice List" +{ + // Test codeunits can only run in foreground (UI) + Subtype = Test; + + trigger OnRun(); + begin + end; + + [Test] + procedure OpenPurchaseInvoices() + var + PurchaseInvoices: testpage "Purchase Invoices"; + begin + PurchaseInvoices.OpenView(); + PurchaseInvoices.Close(); + end; +} diff --git a/Peg Board PerformanceTest/src/BCPTOpenRoleCenterSOP.Codeunit.al b/Peg Board PerformanceTest/src/BCPTOpenRoleCenterSOP.Codeunit.al new file mode 100644 index 0000000..4f0181a --- /dev/null +++ b/Peg Board PerformanceTest/src/BCPTOpenRoleCenterSOP.Codeunit.al @@ -0,0 +1,17 @@ +namespace System.Test.Tooling; + +using Microsoft.Sales.RoleCenters; + +codeunit 50813 "BCPT Open RoleCenter SOP" +{ + // Test codeunits can only run in foreground (UI) + Subtype = Test; + + trigger OnRun(); + var + SOPRC: testpage "SO Processor Activities"; + begin + SOPRC.OpenView(); + SOPRC.Close(); + end; +} diff --git a/Peg Board PerformanceTest/src/BCPTOpenSalesInvoiceList.Codeunit.al b/Peg Board PerformanceTest/src/BCPTOpenSalesInvoiceList.Codeunit.al new file mode 100644 index 0000000..a94a393 --- /dev/null +++ b/Peg Board PerformanceTest/src/BCPTOpenSalesInvoiceList.Codeunit.al @@ -0,0 +1,22 @@ +namespace System.Test.Tooling; + +using Microsoft.Sales.Document; + +codeunit 50814 "BCPT Open Sales Invoice List" +{ + // Test codeunits can only run in foreground (UI) + Subtype = Test; + + trigger OnRun(); + begin + end; + + [Test] + procedure OpenSalesInvoiceList() + var + SalesInvoiceList: testpage "Sales Invoice List"; + begin + SalesInvoiceList.OpenView(); + SalesInvoiceList.Close(); + end; +} diff --git a/Peg Board PerformanceTest/src/BCPTOpenVendorList.Codeunit.al b/Peg Board PerformanceTest/src/BCPTOpenVendorList.Codeunit.al new file mode 100644 index 0000000..4da17e8 --- /dev/null +++ b/Peg Board PerformanceTest/src/BCPTOpenVendorList.Codeunit.al @@ -0,0 +1,22 @@ +namespace System.Test.Tooling; + +using Microsoft.Purchases.Vendor; + +codeunit 50815 "BCPT Open Vendor List" +{ + // Test codeunits can only run in foreground (UI) + Subtype = Test; + + trigger OnRun(); + begin + end; + + [Test] + procedure OpenVendorList() + var + VendorList: testpage "Vendor List"; + begin + VendorList.OpenView(); + VendorList.Close(); + end; +} diff --git a/Peg Board PerformanceTest/src/BCPTPostGLEntries.Codeunit.al b/Peg Board PerformanceTest/src/BCPTPostGLEntries.Codeunit.al new file mode 100644 index 0000000..b6cbe56 --- /dev/null +++ b/Peg Board PerformanceTest/src/BCPTPostGLEntries.Codeunit.al @@ -0,0 +1,141 @@ +namespace System.Test.Tooling; + +using Microsoft.Finance.GeneralLedger.Account; +using Microsoft.Finance.GeneralLedger.Journal; +using Microsoft.Finance.GeneralLedger.Posting; +using Microsoft.Foundation.NoSeries; +using System.Tooling; + +codeunit 50821 "BCPT Post G/L Entries" +{ + SingleInstance = true; + + trigger OnRun(); + begin + PostGeneralJournal(); + end; + + procedure PostGeneralJournal() + var + GenJournalLine: Record "Gen. Journal Line"; + BCPTTestContext: Codeunit "BCPT Test Context"; + begin + // Setup: Create General Journal + BCPTTestContext.StartScenario('Create General Journal Line'); + CreateGeneralJournalLine(GenJournalLine); + BCPTTestContext.EndScenario('Create General Journal Line'); + + // Exercise: Post General Journal. + BCPTTestContext.StartScenario('Post General Journal Lines'); + PostGeneralJournalLine(GenJournalLine."Journal Template Name", GenJournalLine."Journal Batch Name"); + BCPTTestContext.EndScenario('Post General Journal Lines'); + end; + + local procedure CreateGeneralJournalLine(var GenJournalLine: Record "Gen. Journal Line") + var + GenJournalBatch: Record "Gen. Journal Batch"; + begin + SelectGeneralJournal(GenJournalBatch); + + CreateGeneralJournalLine( + GenJournalLine, GenJournalBatch."Journal Template Name", + GenJournalBatch.Name); + end; + + procedure CreateGeneralJournalLine(var GenJournalLine: Record "Gen. Journal Line"; JournalTemplateName: Code[10]; JournalBatchName: Code[10]) + var + GenJournalBatch: Record "Gen. Journal Batch"; + begin + if not GenJournalBatch.Get(JournalTemplateName, JournalBatchName) then begin + GenJournalBatch.Init(); + GenJournalBatch.Validate("Journal Template Name", JournalTemplateName); + GenJournalBatch.SetupNewBatch(); + GenJournalBatch.Validate(Name, JournalBatchName); + GenJournalBatch.Validate(Description, JournalBatchName + ' journal'); + GenJournalBatch.Insert(true); + end; + CreateGeneralJnlLine(GenJournalLine, GenJournalBatch, JournalTemplateName, JournalBatchName); + end; + + procedure CreateGeneralJnlLine(var GenJournalLine: Record "Gen. Journal Line"; GenJournalBatch: Record "Gen. Journal Batch"; JournalTemplateName: Code[10]; JournalBatchName: Code[10]) + var + NoSeries: Record "No. Series"; + NoSeriesSingle: Codeunit "No. Series"; + DocumentNo: Code[20]; + begin + Clear(GenJournalLine); + GenJournalLine.DeleteAll(); + //Debit amount + GenJournalLine.Init(); + GenJournalLine.Validate("Journal Template Name", JournalTemplateName); + GenJournalLine.Validate("Journal Batch Name", JournalBatchName); + GenJournalLine.Validate("Line No.", 10000); + GenJournalLine.Insert(true); + GenJournalLine.Validate("Posting Date", WorkDate()); + if NoSeries.Get(GenJournalBatch."No. Series") then + DocumentNo := NoSeriesSingle.GetNextNo(GenJournalBatch."No. Series", GenJournalLine."Posting Date", false); + GenJournalLine.Validate("Document No.", DocumentNo); + GenJournalLine.Validate("Account Type", GenJournalLine."Account Type"::"G/L Account"); + GenJournalLine.Validate("Account No.", SelectRandomGLAccount()); + GenJournalLine.Validate("Debit Amount", 1000); + GenJournalLine.Modify(true); + + //Credit amount + GenJournalLine.Init(); + GenJournalLine.Validate("Journal Template Name", JournalTemplateName); + GenJournalLine.Validate("Journal Batch Name", JournalBatchName); + GenJournalLine.Validate("Line No.", 20000); + GenJournalLine.Insert(true); + GenJournalLine.Validate("Posting Date", WorkDate()); + GenJournalLine.Validate("Document No.", DocumentNo); + GenJournalLine.Validate("Account Type", GenJournalLine."Account Type"::"G/L Account"); + GenJournalLine.Validate("Account No.", SelectRandomGLAccount()); + GenJournalLine.Validate("Credit Amount", 1000); + GenJournalLine.Modify(true); + end; + + local procedure SelectGeneralJournal(var GenJournalBatch: Record "Gen. Journal Batch") + var + GenJournalTemplate: Record "Gen. Journal Template"; + begin + SelectGeneralJournalTemplateName(GenJournalTemplate, GenJournalTemplate.Type::General); + SelectGeneralJournalBatchName(GenJournalBatch, GenJournalTemplate.Type::General, GenJournalTemplate.Name); + end; + + local procedure PostGeneralJournalLine(JournalTemplateName: Text[10]; JournalBatchName: Text[10]) + var + GenJournalLine: Record "Gen. Journal Line"; + begin + GenJournalLine.Init(); + GenJournalLine.Validate("Journal Template Name", JournalTemplateName); + GenJournalLine.Validate("Journal Batch Name", JournalBatchName); + CODEUNIT.Run(CODEUNIT::"Gen. Jnl.-Post", GenJournalLine); + end; + + local procedure SelectGeneralJournalTemplateName(var GenJournalTemplate: Record "Gen. Journal Template"; GenJournalTemplateType: Enum "Gen. Journal Template Type") + begin + // Find General Journal Template for the given Template Type. + GenJournalTemplate.SetRange(Type, GenJournalTemplateType); + GenJournalTemplate.SetRange(Recurring, false); + if GenJournalTemplate.FindFirst() then; + end; + + local procedure SelectGeneralJournalBatchName(var GenJournalBatch: Record "Gen. Journal Batch"; GenJournalTemplateType: Enum "Gen. Journal Template Type"; GenJournalTemplateName: Code[10]) + begin + // Find Name for Batch Name. + GenJournalBatch.SetRange("Template Type", GenJournalTemplateType); + GenJournalBatch.SetRange("Journal Template Name", GenJournalTemplateName); + if GenJournalBatch.FindFirst() then; + end; + + local procedure SelectRandomGLAccount(): Code[20] + var + GLAccount: Record "G/L Account"; + begin + GLAccount.SetRange("Account Type", GLAccount."Account Type"::Posting); + GLAccount.SetRange("Direct Posting", true); + GLAccount.SetFilter("Gen. Bus. Posting Group", '<>%1', ''); + GLAccount.Next(SessionId() mod GLAccount.Count()); + exit(GLAccount."No."); + end; +} diff --git a/Peg Board PerformanceTest/src/BCPTPostItemJournal.Codeunit.al b/Peg Board PerformanceTest/src/BCPTPostItemJournal.Codeunit.al new file mode 100644 index 0000000..5e89c05 --- /dev/null +++ b/Peg Board PerformanceTest/src/BCPTPostItemJournal.Codeunit.al @@ -0,0 +1,124 @@ +namespace System.Test.Tooling; + +using Microsoft.Foundation.NoSeries; +using Microsoft.Inventory.Item; +using Microsoft.Inventory.Journal; +using Microsoft.Inventory.Ledger; +using Microsoft.Inventory.Posting; + +codeunit 50820 "BCPT Post Item Journal" +{ + SingleInstance = true; + + trigger OnRun(); + begin + PostItemJournal(); + end; + + procedure PostItemJournal() + var + ItemJournalLine: Record "Item Journal Line"; + begin + // Setup: Create Item Journal with Entry Type Positive Adjustment. + CreateItemJournal(ItemJournalLine); + + // Exercise: Post Item Journal. + PostItemJournalLine(ItemJournalLine."Journal Template Name", ItemJournalLine."Journal Batch Name"); + end; + + local procedure CreateItemJournal(var ItemJournalLine: Record "Item Journal Line") + var + Item: Record Item; + begin + if not Item.get('70000') then + Item.FindFirst(); + + CreateItemJournalLine(ItemJournalLine, Item."No."); + end; + + local procedure CreateItemJournalLine(var ItemJournalLine: Record "Item Journal Line"; ItemNo: Code[20]) + var + ItemJournalBatch: Record "Item Journal Batch"; + begin + SelectItemJournal(ItemJournalBatch); + CreateItemJournalLine( + ItemJournalLine, ItemJournalBatch."Journal Template Name", + ItemJournalBatch.Name, ItemJournalLine."Entry Type"::"Positive Adjmt.", ItemNo, 10); + end; + + procedure CreateItemJournalLine(var ItemJournalLine: Record "Item Journal Line"; JournalTemplateName: Code[10]; JournalBatchName: Code[10]; EntryType: Enum "Item Ledger Entry Type"; ItemNo: Text[20]; NewQuantity: Decimal) + var + ItemJournalBatch: Record "Item Journal Batch"; + begin + if not ItemJournalBatch.Get(JournalTemplateName, JournalBatchName) then begin + ItemJournalBatch.Init(); + ItemJournalBatch.Validate("Journal Template Name", JournalTemplateName); + ItemJournalBatch.SetupNewBatch(); + ItemJournalBatch.Validate(Name, JournalBatchName); + ItemJournalBatch.Validate(Description, JournalBatchName + ' journal'); + ItemJournalBatch.Insert(true); + end; + CreateItemJnlLineWithNoItem(ItemJournalLine, ItemJournalBatch, JournalTemplateName, JournalBatchName, EntryType); + ItemJournalLine.Validate("Item No.", ItemNo); + ItemJournalLine.Validate(Quantity, NewQuantity); + ItemJournalLine.Modify(true); + end; + + procedure CreateItemJnlLineWithNoItem(var ItemJournalLine: Record "Item Journal Line"; ItemJournalBatch: Record "Item Journal Batch"; JournalTemplateName: Code[10]; JournalBatchName: Code[10]; EntryType: Enum "Item Ledger Entry Type") + var + NoSeries: Record "No. Series"; + NoSeriesSingle: Codeunit "No. Series"; + RecRef: RecordRef; + DocumentNo: Code[20]; + begin + Clear(ItemJournalLine); + ItemJournalLine.Init(); + ItemJournalLine.Validate("Journal Template Name", JournalTemplateName); + ItemJournalLine.Validate("Journal Batch Name", JournalBatchName); + RecRef.GetTable(ItemJournalLine); + ItemJournalLine.Validate("Line No.", 10000); + ItemJournalLine.Insert(true); + ItemJournalLine.Validate("Posting Date", WorkDate()); + ItemJournalLine.Validate("Entry Type", EntryType); + if NoSeries.Get(ItemJournalBatch."No. Series") then + DocumentNo := NoSeriesSingle.GetNextNo(ItemJournalBatch."No. Series", ItemJournalLine."Posting Date", false); + ItemJournalLine.Validate("Document No.", DocumentNo); + ItemJournalLine.Modify(true); + end; + + local procedure SelectItemJournal(var ItemJournalBatch: Record "Item Journal Batch") + var + ItemJournalTemplate: Record "Item Journal Template"; + begin + SelectItemJournalTemplateName(ItemJournalTemplate, ItemJournalTemplate.Type::Item); + SelectItemJournalBatchName(ItemJournalBatch, ItemJournalTemplate.Type::Item, ItemJournalTemplate.Name); + end; + + procedure PostItemJournalLine(JournalTemplateName: Text[10]; JournalBatchName: Text[10]) + var + ItemJournalLine: Record "Item Journal Line"; + begin + ItemJournalLine.Init(); + ItemJournalLine.Validate("Journal Template Name", JournalTemplateName); + ItemJournalLine.Validate("Journal Batch Name", JournalBatchName); + CODEUNIT.Run(CODEUNIT::"Item Jnl.-Post Batch", ItemJournalLine); + end; + + procedure SelectItemJournalTemplateName(var ItemJournalTemplate: Record "Item Journal Template"; ItemJournalTemplateType: Enum "Item Journal Template Type") + begin + // Find Item Journal Template for the given Template Type. + ItemJournalTemplate.SetRange(Type, ItemJournalTemplateType); + ItemJournalTemplate.SetRange(Recurring, false); + if ItemJournalTemplate.FindFirst() then; + end; + + procedure SelectItemJournalBatchName(var ItemJournalBatch: Record "Item Journal Batch"; ItemJournalBatchTemplateType: Enum "Item Journal Template Type"; ItemJournalTemplateName: Code[10]) + begin + // Find Name for Batch Name. + ItemJournalBatch.SetRange("Template Type", ItemJournalBatchTemplateType); + ItemJournalBatch.SetRange("Journal Template Name", ItemJournalTemplateName); + + // If Item Journal Batch not found then create it. + if ItemJournalBatch.FindFirst() then; + end; +} diff --git a/Peg Board PerformanceTest/src/BCPTPostPurchInv.Codeunit.al b/Peg Board PerformanceTest/src/BCPTPostPurchInv.Codeunit.al new file mode 100644 index 0000000..0f08434 --- /dev/null +++ b/Peg Board PerformanceTest/src/BCPTPostPurchInv.Codeunit.al @@ -0,0 +1,157 @@ +namespace System.Test.Tooling; + +using Microsoft.Foundation.NoSeries; +using Microsoft.Inventory.Item; +using Microsoft.Purchases.Document; +using Microsoft.Purchases.Posting; +using Microsoft.Purchases.Setup; +using Microsoft.Purchases.Vendor; +using System.Tooling; + +codeunit 50822 "BCPT Post Purch. Inv." implements "BCPT Test Param. Provider" +{ + SingleInstance = true; + + trigger OnRun(); + begin + if not IsInitialized then begin + InitTest(); + IsInitialized := true; + end; + + CreateAndPostPurchaseInvoice(); + end; + + var + GlobalBCPTTestContext: Codeunit "BCPT Test Context"; + IsInitialized: Boolean; + NoOfLinesParamLbl: Label 'Lines'; + ParamValidationErr: Label 'Parameter is not defined in the correct format. The expected format is "%1"', comment = '%1 = Parameter name'; + NoOfLinesToCreate: Integer; + + local procedure InitTest(); + var + PurchasesPayablesSetup: Record "Purchases & Payables Setup"; + NoSeriesLine: Record "No. Series Line"; + RecordModified: Boolean; + begin + PurchasesPayablesSetup.Get(); + PurchasesPayablesSetup.TestField("Invoice Nos."); + if PurchasesPayablesSetup."Ext. Doc. No. Mandatory" then begin + PurchasesPayablesSetup."Ext. Doc. No. Mandatory" := false; + PurchasesPayablesSetup.Modify(); + RecordModified := true; + end; + + NoSeriesLine.SetRange("Series Code", PurchasesPayablesSetup."Invoice Nos."); + NoSeriesLine.FindSet(true); + repeat + if NoSeriesLine."Ending No." <> '' then begin + NoSeriesLine."Ending No." := ''; + NoSeriesLine.Validate(Implementation, Enum::"No. Series Implementation"::Sequence); + NoSeriesLine.Modify(true); + RecordModified := true; + end; + until NoSeriesLine.Next() = 0; + + if RecordModified then + Commit(); + + if Evaluate(NoOfLinesToCreate, GlobalBCPTTestContext.GetParameter(NoOfLinesParamLbl)) then; + end; + + procedure CreateAndPostPurchaseInvoice() + var + PurchaseHeader: Record "Purchase Header"; + VendorNo: Code[20]; + begin + if NoOfLinesToCreate < 0 then + NoOfLinesToCreate := 0; + if NoOfLinesToCreate > 10000 then + NoOfLinesToCreate := 10000; + + //Find a random vendor + VendorNo := SelectRandomVendor(); + + GlobalBCPTTestContext.StartScenario('Create Purchase Invoice'); + CreatePurchaseInvoiceForVendorNo(PurchaseHeader, VendorNo); + GlobalBCPTTestContext.EndScenario('Create Purchase Invoice'); + + GlobalBCPTTestContext.StartScenario('Post Purchase Invoice'); + CODEUNIT.Run(CODEUNIT::"Purch.-Post (Yes/No)", PurchaseHeader); + GlobalBCPTTestContext.EndScenario('Post Purchase Invoice'); + end; + + local procedure SelectRandomVendor(): Code[20] + var + Vendor: Record Vendor; + begin + Vendor.SetRange(Blocked, Vendor.Blocked::" "); + Vendor.Next(SessionId() mod Vendor.Count()); + exit(Vendor."No."); + end; + + local procedure CreatePurchaseInvoiceForVendorNo(var PurchaseHeader: Record "Purchase Header"; VendorNo: Code[20]) + var + PurchaseLine: Record "Purchase Line"; + i: Integer; + LineNo: Integer; + begin + CreatePurchHeader(PurchaseHeader, PurchaseHeader."Document Type"::Invoice, VendorNo); + LineNo := 1000; + for i := 1 to NoOfLinesToCreate do begin + CreatePurchaseLine(PurchaseLine, PurchaseHeader, LineNo); + LineNo := LineNo + 1000; + end; + end; + + procedure CreatePurchHeader(var PurchaseHeader: Record "Purchase Header"; DocumentType: Enum "Purchase Document Type"; BuyfromVendorNo: Code[20]) + begin + Clear(PurchaseHeader); + PurchaseHeader.Validate("Document Type", DocumentType); + PurchaseHeader.Insert(true); + PurchaseHeader.Validate("Buy-from Vendor No.", BuyfromVendorNo); + PurchaseHeader.Modify(true); + Commit(); + end; + + local procedure CreatePurchaseLine(var PurchaseLine: Record "Purchase Line"; PurchaseHeader: Record "Purchase Header"; LineNo: Integer) + begin + PurchaseLine.Init(); + PurchaseLine.Validate("Document Type", PurchaseHeader."Document Type"); + PurchaseLine.Validate("Document No.", PurchaseHeader."No."); + PurchaseLine.Validate("Line No.", LineNo); + PurchaseLine.Insert(true); + Commit(); + + PurchaseLine.Validate(Type, PurchaseLine.Type::Item); + PurchaseLine.Validate("No.", SelectRandomItem()); + PurchaseLine.Validate(Quantity, 1); + PurchaseLine.Modify(true); + Commit(); + end; + + local procedure SelectRandomItem(): Code[20] + var + Item: Record Item; + begin + Item.SetRange(Blocked, false); + Item.Next(SessionId() mod Item.Count()); + exit(Item."No."); + end; + + procedure GetDefaultParameters(): Text[1000] + begin + exit(copystr(NoOfLinesParamLbl + '=' + Format(10), 1, 1000)); + end; + + procedure ValidateParameters(Parameters: Text[1000]) + begin + if StrPos(Parameters, NoOfLinesParamLbl) > 0 then begin + Parameters := DelStr(Parameters, 1, StrLen(NoOfLinesParamLbl + '=')); + if Evaluate(NoOfLinesToCreate, Parameters) then + exit; + end; + Error(ParamValidationErr, GetDefaultParameters()); + end; +} diff --git a/Peg Board PerformanceTest/src/BCPTPostSalesWithNLines.Codeunit.al b/Peg Board PerformanceTest/src/BCPTPostSalesWithNLines.Codeunit.al new file mode 100644 index 0000000..916f9fb --- /dev/null +++ b/Peg Board PerformanceTest/src/BCPTPostSalesWithNLines.Codeunit.al @@ -0,0 +1,145 @@ +namespace System.Test.Tooling; + +using Microsoft.Foundation.NoSeries; +using Microsoft.Inventory.Item; +using Microsoft.Sales.Document; +using Microsoft.Sales.Customer; +using Microsoft.Sales.Posting; +using Microsoft.Sales.Setup; +using System.Tooling; + +codeunit 50818 "BCPT Post Sales with N Lines" implements "BCPT Test Param. Provider" +{ + SingleInstance = true; + + trigger OnRun(); + var + SalesHeader: Record "Sales Header"; + SalesSetup: Record "Sales & Receivables Setup"; + SalesPost: Codeunit "Sales-Post"; + SalesPostViaJobQueue: Codeunit "Sales Post via Job Queue"; + SalesHeaderId: Guid; + begin + if not IsInitialized then begin + InitTest(); + IsInitialized := true; + end; + SalesHeaderId := CreateSalesOrder(GlobalBCPTTestContext); + SalesHeader.GetBySystemId(SalesHeaderId); + SalesHeader.Validate(Ship, true); + SalesHeader.Validate(Invoice, true); + + SalesSetup.Get(); + if SalesSetup."Post with Job Queue" then + SalesPostViaJobQueue.EnqueueSalesDoc(SalesHeader) + else + SalesPost.Run(SalesHeader); + end; + + var + GlobalBCPTTestContext: Codeunit "BCPT Test Context"; + IsInitialized: Boolean; + NoOfLinesToCreate: Integer; + NoOfLinesParamLbl: Label 'Lines'; + ParamValidationErr: Label 'Parameter is not defined in the correct format. The expected format is "%1"', Comment = '%1 is a string'; + + local procedure InitTest(); + var + SalesSetup: Record "Sales & Receivables Setup"; + NoSeriesLine: Record "No. Series Line"; + RecordModified: Boolean; + begin + SalesSetup.Get(); + SalesSetup.TestField("Order Nos."); + NoSeriesLine.SetRange("Series Code", SalesSetup."Order Nos."); + NoSeriesLine.FindSet(true); + repeat + if NoSeriesLine."Ending No." <> '' then begin + NoSeriesLine."Ending No." := ''; + NoSeriesLine.Validate(Implementation, Enum::"No. Series Implementation"::Sequence); + NoSeriesLine.Modify(true); + RecordModified := true; + end; + until NoSeriesLine.Next() = 0; + + if RecordModified then + Commit(); + + if Evaluate(NoOfLinesToCreate, GlobalBCPTTestContext.GetParameter(NoOfLinesParamLbl)) then; + end; + + local procedure CreateSalesOrder(var BCPTTestContext: Codeunit "BCPT Test Context"): Guid + var + Customer: Record Customer; + Item: Record Item; + SalesHeader: Record "Sales Header"; + SalesLine: Record "Sales Line"; + i: Integer; + begin + if not Customer.get('10000') then + Customer.FindFirst(); + if not item.get('70000') then + Item.FindSet(); + if NoOfLinesToCreate < 0 then + NoOfLinesToCreate := 0; + if NoOfLinesToCreate > 10000 then + NoOfLinesToCreate := 10000; + BCPTTestContext.StartScenario('Add Order'); + SalesHeader.Init(); + SalesHeader."Document Type" := SalesHeader."Document Type"::Order; + SalesHeader.Insert(true); + Commit(); + BCPTTestContext.EndScenario('Add Order'); + BCPTTestContext.UserWait(); + BCPTTestContext.StartScenario('Enter Account No.'); + SalesHeader.Validate("Sell-to Customer No.", Customer."No."); + SalesHeader.Modify(true); + Commit(); + BCPTTestContext.EndScenario('Enter Account No.'); + BCPTTestContext.UserWait(); + SalesLine."Document Type" := SalesHeader."Document Type"; + SalesLine."Document No." := SalesHeader."No."; + for i := 1 to NoOfLinesToCreate do begin + SalesLine."Line No." += 10000; + SalesLine.Init(); + SalesLine.Validate(Type, SalesLine.Type::Item); + SalesLine.Insert(true); + BCPTTestContext.UserWait(); + if i = 1 then + BCPTTestContext.StartScenario('Enter Line Item No.'); + SalesLine.Validate("No.", Item."No."); + if i = 1 then + BCPTTestContext.EndScenario('Enter Line Item No.'); + BCPTTestContext.UserWait(); + if i = 1 then + BCPTTestContext.StartScenario('Enter Line Quantity'); + SalesLine.Validate(Quantity, 1); + SalesLine.Modify(true); + if i = 1 then + BCPTTestContext.EndScenario('Enter Line Quantity'); + BCPTTestContext.UserWait(); + if i mod 2 = 0 then + if Item.Next() = 0 then +#pragma warning disable AA0181, AA0175 + Item.FindSet(); +#pragma warning restore AA0181, AA0175 + end; + + exit(SalesHeader.SystemId); + end; + + procedure GetDefaultParameters(): Text[1000] + begin + exit(copystr(NoOfLinesParamLbl + '=' + Format(10), 1, 1000)); + end; + + procedure ValidateParameters(Parameters: Text[1000]) + begin + if StrPos(Parameters, NoOfLinesParamLbl) > 0 then begin + Parameters := DelStr(Parameters, 1, StrLen(NoOfLinesParamLbl + '=')); + if Evaluate(NoOfLinesToCreate, Parameters) then + exit; + end; + Error(ParamValidationErr, GetDefaultParameters()); + end; +} diff --git a/Peg Board PerformanceTest/src/BCPTPurchPostWithNLines.Codeunit.al b/Peg Board PerformanceTest/src/BCPTPurchPostWithNLines.Codeunit.al new file mode 100644 index 0000000..5271c22 --- /dev/null +++ b/Peg Board PerformanceTest/src/BCPTPurchPostWithNLines.Codeunit.al @@ -0,0 +1,140 @@ +namespace System.Test.Tooling; + +using Microsoft.Foundation.NoSeries; +using Microsoft.Inventory.Item; +using Microsoft.Purchases.Document; +using Microsoft.Purchases.Posting; +using Microsoft.Purchases.Setup; +using Microsoft.Purchases.Vendor; +using System.Tooling; + +codeunit 50819 "BCPT Purch. Post with N Lines" implements "BCPT Test Param. Provider" +{ + SingleInstance = true; + + trigger OnRun(); + var + PurchHeader: Record "Purchase Header"; + PurchSetup: Record "Purchases & Payables Setup"; + PurchPost: Codeunit "Purch.-Post"; + PurchasePostViaJobQueue: Codeunit "Purchase Post Via Job Queue"; + PurchHeaderId: Guid; + begin + if not IsInitialized then begin + InitTest(); + IsInitialized := true; + end; + PurchHeaderId := CreatePurchaseOrder(GlobalBCPTTestContext); + PurchHeader.GetBySystemId(PurchHeaderId); + PurchHeader.Validate(Receive, true); + PurchHeader.Validate(Invoice, true); + PurchHeader.Validate("Vendor Invoice No.", PurchHeader."No."); + + PurchSetup.Get(); + if PurchSetup."Post with Job Queue" then + PurchasePostViaJobQueue.EnqueuePurchDoc(PurchHeader) + else + PurchPost.Run(PurchHeader); + end; + + var + GlobalBCPTTestContext: Codeunit "BCPT Test Context"; + IsInitialized: Boolean; + NoOfLinesParamLbl: Label 'Lines'; + ParamValidationErr: Label 'Parameter is not defined in the correct format. The expected format is "%1"', Comment = '%1 = a string'; + NoOfLinesToCreate: Integer; + + local procedure InitTest(); + var + PurchaseSetup: Record "Purchases & Payables Setup"; + NoSeriesLine: Record "No. Series Line"; + RecordModified: Boolean; + begin + PurchaseSetup.Get(); + PurchaseSetup.TestField("Order Nos."); + NoSeriesLine.SetRange("Series Code", PurchaseSetup."Order Nos."); + NoSeriesLine.FindSet(true); + repeat + if NoSeriesLine."Ending No." <> '' then begin + NoSeriesLine."Ending No." := ''; + NoSeriesLine.Validate(Implementation, Enum::"No. Series Implementation"::Sequence); + NoSeriesLine.Modify(true); + RecordModified := true; + end; + until NoSeriesLine.Next() = 0; + + if RecordModified then + Commit(); + + if Evaluate(NoOfLinesToCreate, GlobalBCPTTestContext.GetParameter(NoOfLinesParamLbl)) then; + end; + + local procedure CreatePurchaseOrder(var BCPTTestContext: Codeunit "BCPT Test Context"): Guid + var + Vendor: Record Vendor; + Item: Record Item; + PurchaseHeader: Record "Purchase Header"; + PurchaseLine: Record "Purchase Line"; + i: Integer; + begin + if not Vendor.get('10000') then + Vendor.FindFirst(); + if not Item.get('70000') then + Item.FindFirst(); + if NoOfLinesToCreate < 0 then + NoOfLinesToCreate := 0; + if NoOfLinesToCreate > 10000 then + NoOfLinesToCreate := 10000; + BCPTTestContext.StartScenario('Add Order'); + PurchaseHeader.init(); + PurchaseHeader."Document Type" := PurchaseHeader."Document Type"::Order; + PurchaseHeader.Insert(true); + BCPTTestContext.EndScenario('Add Order'); + BCPTTestContext.UserWait(); + BCPTTestContext.StartScenario('Enter Account No.'); + PurchaseHeader.Validate("Buy-from Vendor No.", Vendor."No."); + PurchaseHeader.Modify(true); + Commit(); + BCPTTestContext.EndScenario('Enter Account No.'); + BCPTTestContext.UserWait(); + PurchaseLine."Document Type" := PurchaseHeader."Document Type"; + PurchaseLine."Document No." := PurchaseHeader."No."; + for i := 1 to NoOfLinesToCreate do begin + PurchaseLine."Line No." += 10000; + PurchaseLine.Init(); + PurchaseLine.Validate(Type, PurchaseLine.Type::Item); + PurchaseLine.Insert(true); + BCPTTestContext.UserWait(); + if i = 10 then + BCPTTestContext.StartScenario('Enter Line Item No.'); + PurchaseLine.Validate("No.", Item."No."); + if i = 10 then + BCPTTestContext.EndScenario('Enter Line Item No.'); + BCPTTestContext.UserWait(); + if i = 10 then + BCPTTestContext.StartScenario('Enter Line Quantity'); + PurchaseLine.Validate(Quantity, 1); + if i = 10 then + BCPTTestContext.EndScenario('Enter Line Quantity'); + PurchaseLine.Modify(true); + Commit(); + BCPTTestContext.UserWait(); + end; + exit(PurchaseHeader.SystemId); + end; + + procedure GetDefaultParameters(): Text[1000] + begin + exit(copystr(NoOfLinesParamLbl + '=' + Format(10), 1, 1000)); + end; + + procedure ValidateParameters(Parameters: Text[1000]) + begin + if StrPos(Parameters, NoOfLinesParamLbl) > 0 then begin + Parameters := DelStr(Parameters, 1, StrLen(NoOfLinesParamLbl + '=')); + if Evaluate(NoOfLinesToCreate, Parameters) then + exit; + end; + Error(ParamValidationErr, GetDefaultParameters()); + end; +} diff --git a/Peg Board PerformanceTest/src/BCPTSQLPing.Codeunit.al b/Peg Board PerformanceTest/src/BCPTSQLPing.Codeunit.al new file mode 100644 index 0000000..8656cb7 --- /dev/null +++ b/Peg Board PerformanceTest/src/BCPTSQLPing.Codeunit.al @@ -0,0 +1,20 @@ +namespace System.Test.Tooling; + +using Microsoft.Finance.GeneralLedger.Setup; + +codeunit 50817 "BCPT SQL Ping" +{ + trigger OnRun(); + var + i: Integer; + begin + SelectLatestVersion(); // bypass the NST cache + for i := 1 to 100 do begin + SelectLatestVersion(); // bypass the NST cache + GLsetup.Get(); + end; + end; + + var + GLsetup: Record "General Ledger Setup"; +} diff --git a/Peg Board PerformanceTest/src/BCPTScheduleJobQueue.codeunit.al b/Peg Board PerformanceTest/src/BCPTScheduleJobQueue.codeunit.al new file mode 100644 index 0000000..459d4df --- /dev/null +++ b/Peg Board PerformanceTest/src/BCPTScheduleJobQueue.codeunit.al @@ -0,0 +1,95 @@ +namespace System.Test.Tooling; + +using System.Threading; +using System.Tooling; + +codeunit 50832 "BCPT Schedule Job Queue" implements "BCPT Test Param. Provider" +{ + SingleInstance = true; + + var + GlobalBCPTTestContext: Codeunit "BCPT Test Context"; + CodeUnitNo: Integer; + CodeUnitNoLbl: Label 'CodeUnit_No'; + CategoryCode: code[10]; + CategoryLbl: label 'Category'; + + trigger OnRun() + var + JobQueueEntry: Record "Job Queue Entry"; + i: Integer; + begin + ValidateParameters(CopyStr(GlobalBCPTTestContext.GetParameters(), 1, 1000)); + + JobQueueEntry.Init(); + JobQueueEntry."Object Type to Run" := JobQueueEntry."Object Type to Run"::Codeunit; + JobQueueEntry."Object ID to Run" := CodeUnitNo; + JobQueueEntry."Job Queue Category Code" := CategoryCode; + for i := 1 to 5 do begin + Clear(JobQueueEntry.ID); + JobQueueEntry."Entry No." := 0; + Codeunit.Run(Codeunit::"Job Queue - Enqueue", JobQueueEntry); + JobQueueEntry.Description := Format(JobQueueEntry."Entry No.") + ' - ' + Format(i); + JobQueueEntry.Modify(); + end; + end; + + procedure GetDefaultParameters(): Text[1000] + begin + exit(copystr( + CodeunitNoLbl + '=' + Format(Codeunit::"BCPT Sleep 1s") + ', ' + + CategoryLbl + '=' + 'DOCPOST' + , 1, 1000)); + end; + + procedure ValidateParameters(Parameters: Text[1000]) + var + JobQueueCategory: Record "Job Queue Category"; + dict: Dictionary of [Text, Text]; + parm: Text; + UnkownParameterErr: label 'Unknown parameter: %1', Comment = '%1 is any unknown user input.'; + begin + if Parameters = '' then + exit; + ParameterStringToDictionary(Parameters, dict); + foreach parm in dict.Keys do + if not (UpperCase(parm) in [UpperCase(CodeunitNoLbl), UpperCase(CategoryLbl)]) then + error(UnkownParameterErr, parm); + + if dict.ContainsKey(CodeunitNoLbl) then begin + parm := dict.Get(CodeunitNoLbl); + Evaluate(CodeUnitNo, parm); + end; + + if dict.ContainsKey(CategoryLbl) then begin + CategoryCode := CopyStr(dict.Get(CategoryLbl), 1, 10); + JobQueueCategory.Get(CategoryCode); + end; + end; + + local procedure ParameterStringToDictionary(Params: Text; var dict: Dictionary of [Text, Text]) + var + i: Integer; + p: Integer; + KeyVal: Text; + NoOfParams: Integer; + begin + clear(dict); + if Params = '' then + exit; + + NoOfParams := StrLen(Params) - strlen(DelChr(Params, '=', ',')) + 1; + + for i := 1 to NoOfParams do begin + if NoOfParams = 1 then + KeyVal := Params + else + KeyVal := SelectStr(i, Params); + p := StrPos(KeyVal, '='); + if p > 0 then + dict.Add(DelChr(CopyStr(KeyVal, 1, p - 1), '<>', ' '), DelChr(CopyStr(KeyVal, p + 1), '<>', ' ')) + else + dict.Add(DelChr(KeyVal, '<>', ' '), ''); + end; + end; +} diff --git a/Peg Board PerformanceTest/src/BCPTSleep1s.Codeunit.al b/Peg Board PerformanceTest/src/BCPTSleep1s.Codeunit.al new file mode 100644 index 0000000..9da00e1 --- /dev/null +++ b/Peg Board PerformanceTest/src/BCPTSleep1s.Codeunit.al @@ -0,0 +1,9 @@ +namespace System.Test.Tooling; + +codeunit 50816 "BCPT Sleep 1s" +{ + trigger OnRun(); + begin + Sleep(1000); + end; +} diff --git a/Peg Board PerformanceTest/src/BCPTSleep1sAndError.codeunit.al b/Peg Board PerformanceTest/src/BCPTSleep1sAndError.codeunit.al new file mode 100644 index 0000000..5285110 --- /dev/null +++ b/Peg Board PerformanceTest/src/BCPTSleep1sAndError.codeunit.al @@ -0,0 +1,11 @@ +namespace System.Test.Tooling; + +codeunit 50833 "BCPT Sleep 1s and Error" +{ + trigger OnRun() + begin + Sleep(1000); + error('something happened') + end; + +} diff --git a/Peg Board PerformanceTest/src/BCPTSleepXSeconds.Codeunit.al b/Peg Board PerformanceTest/src/BCPTSleepXSeconds.Codeunit.al new file mode 100644 index 0000000..46d9de8 --- /dev/null +++ b/Peg Board PerformanceTest/src/BCPTSleepXSeconds.Codeunit.al @@ -0,0 +1,18 @@ +namespace System.Test.Tooling; +using System.Threading; + +codeunit 50830 "BCPT Sleep X seconds" +{ + TableNo = "Job Queue Entry"; + + trigger OnRun(); + var + NoOfSeconds: Integer; + begin + NoOfSeconds := 1; + if Rec."Parameter String" <> '' then + if not Evaluate(NoOfSeconds, Rec."Parameter String") then + NoOfSeconds := 1; + Sleep(1000 * NoOfSeconds); + end; +} diff --git a/Peg Board PerformanceTest/src/BCPTSleepXSecondsJQ.Codeunit.al b/Peg Board PerformanceTest/src/BCPTSleepXSecondsJQ.Codeunit.al new file mode 100644 index 0000000..7dc6a69 --- /dev/null +++ b/Peg Board PerformanceTest/src/BCPTSleepXSecondsJQ.Codeunit.al @@ -0,0 +1,42 @@ +namespace System.Test.Tooling; + +using System.Threading; +using System.Tooling; + +codeunit 50831 "BCPT Sleep X seconds JQ" implements "BCPT Test Param. Provider" +{ + var + GlobalBCPTTestContext: Codeunit "BCPT Test Context"; + ParamValidationErr: Label 'Parameter is not defined in the correct format. The expected format is "%1"', Comment = '%1 = a string'; + NoOfSecondsLbl: label 'NoOfSeconds'; + NoOfSeconds: Integer; + CategoryLbl: label 'CategoryCode'; + Category: Code[10]; + + trigger OnRun(); + var + JobQueueEntry: Record "Job Queue Entry"; + begin + if Evaluate(NoOfSeconds, GlobalBCPTTestContext.GetParameter(NoOfSecondsLbl)) then; + if Evaluate(Category, GlobalBCPTTestContext.GetParameter(CategoryLbl)) then; + + JobQueueEntry.Init(); + JobQueueEntry."Object Type to Run" := JobQueueEntry."Object Type to Run"::Codeunit; + JobQueueEntry.Validate("Object ID to Run", Codeunit::"BCPT Sleep X seconds"); + JobQueueEntry."Job Queue Category Code" := Category; + JobQueueEntry."Parameter String" := format(NoOfSeconds); + JobQueueEntry."Priority Within Category" := JobQueueEntry."Priority Within Category"::High; + Codeunit.run(Codeunit::"Job Queue - Enqueue", JobQueueEntry); + end; + + procedure GetDefaultParameters(): Text[1000] + begin + exit(copystr(NoOfSecondsLbl + '=' + Format(10) + ',' + CategoryLbl + '=', 1, 1000)); + end; + + procedure ValidateParameters(Parameters: Text[1000]) + begin + if not (Evaluate(NoOfSeconds, GlobalBCPTTestContext.GetParameter(NoOfSecondsLbl)) and Evaluate(Category, GlobalBCPTTestContext.GetParameter(CategoryLbl))) then + Error(ParamValidationErr, GetDefaultParameters()); + end; +} diff --git a/Peg Board PerformanceTest/src/BCPTWarehouseReceipt.codeunit.al b/Peg Board PerformanceTest/src/BCPTWarehouseReceipt.codeunit.al new file mode 100644 index 0000000..6f57120 --- /dev/null +++ b/Peg Board PerformanceTest/src/BCPTWarehouseReceipt.codeunit.al @@ -0,0 +1,145 @@ +namespace System.Test.Tooling; +using Microsoft.Inventory.Location; +using Microsoft.Inventory.Item; +using Microsoft.Purchases.Document; +using Microsoft.Purchases.Vendor; +using Microsoft.Warehouse.Request; +using Microsoft.Warehouse.Setup; +using System.Tooling; +using Microsoft.Warehouse.Document; +using Microsoft.Warehouse.Activity; + +codeunit 149202 "BCPT Warehouse Receipt" +{ + SingleInstance = true; + + var + WarehouseEmployee: Record "Warehouse Employee"; + LibraryWarehouse: Codeunit "Library - Warehouse"; + GlobalLastItemNo: Code[20]; + + trigger OnRun() + var + Location: Record Location; + PurchaseHeader: Record "Purchase Header"; + BCPTTestContext: Codeunit "BCPT Test Context"; + WarehouseReceiptNo: Code[20]; + begin + BCPTTestContext.StartScenario('Init'); + if not Location.Get('WHITE') then + Location.FindFirst(); + LibraryWarehouse.CreateWarehouseEmployee(WarehouseEmployee, Location.Code, true); + BCPTTestContext.EndScenario('Init'); + BCPTTestContext.UserWait(); + + BCPTTestContext.StartScenario('CreatePurchaseOrder'); + CreatePurchaseOrder(PurchaseHeader, Location.Code, 10, GlobalLastItemNo); + BCPTTestContext.EndScenario('CreatePurchaseOrder'); + BCPTTestContext.UserWait(); + + BCPTTestContext.StartScenario('CreateWarehouseReceipt'); + WarehouseReceiptNo := CreateWarehouseReceipt(PurchaseHeader); + BCPTTestContext.EndScenario('CreateWarehouseReceipt'); + BCPTTestContext.UserWait(); + + BCPTTestContext.StartScenario('PostWarehouseReceipt'); + PostWarehouseReceipt(WarehouseReceiptNo); + BCPTTestContext.EndScenario('PostWarehouseReceipt'); + BCPTTestContext.UserWait(); + + BCPTTestContext.StartScenario('RegisterPutAway'); + RegisterPutAway(PurchaseHeader."No."); + BCPTTestContext.EndScenario('RegisterPutAway'); + BCPTTestContext.UserWait(); + end; + + local procedure CreatePurchaseOrder(var PurchaseHeader: Record "Purchase Header"; LocationCode: Code[10]; NoOfLines: Integer; var LastItemNo: Code[20]) + var + Vendor: Record Vendor; + Item: Record Item; + PurchaseLine: Record "Purchase Line"; + i: integer; + begin + if not Vendor.Get('10000') then + Vendor.FindFirst(); + PurchaseHeader.Init(); + PurchaseHeader."Document Type" := PurchaseHeader."Document Type"::Order; + PurchaseHeader.Insert(true); + Commit(); + PurchaseHeader.Validate("Buy-from Vendor No.", Vendor."No."); + PurchaseHeader.Validate("Vendor Invoice No.", PurchaseHeader."No."); + PurchaseHeader."Location Code" := LocationCode; + PurchaseHeader.Modify(); + Item.SetRange(Type, Item.Type::Inventory); + Item.FilterGroup(2); + Item.SetFilter("No.", '<>%1', 'GL0*'); // omit the test items + Item.FilterGroup(2); + // Item.SetFilter("Item Tracking Code", '%1', ''); // not recognized by the compiler???? + Item.SetLoadFields("No.", "Item Tracking Code"); + if LastItemNo <> '' then + Item.SetFilter("No.", '>%1', LastItemNo); + Item.FindSet(); + i := 0; + while i < NoOfLines do begin + if Item."Item Tracking Code" = '' then begin // workaround + i += 1; + PurchaseLine.init(); + PurchaseLine."Document No." := PurchaseHeader."No."; + PurchaseLine."Document Type" := PurchaseHeader."Document Type"; + PurchaseLine."Line No." := i * 10000; + PurchaseLine.Validate(Type, PurchaseLine.Type::Item); + PurchaseLine.Validate("No.", Item."No."); + PurchaseLine.Validate("Location Code", LocationCode); + PurchaseLine.Validate(Quantity, 1); + PurchaseLine.Validate("Direct Unit Cost", 1); + PurchaseLine.Insert(true); + end; + if i < NoOfLines then + if Item.Next() = 0 then begin + Item.SetRange("No."); + Item.FindSet(); + end; + end; + if i = 0 then + if Item.Next() = 0 then; // to make codecop happy + LastItemNo := Item."No."; + end; + + local procedure CreateWarehouseReceipt(var PurchaseHeader: Record "Purchase Header"): Code[20] + var + WhseReceiptLine: Record "Warehouse Receipt Line"; + GetSourceDocInbound: Codeunit "Get Source Doc. Inbound"; + begin + PurchaseHeader.PerformManualRelease(); + GetSourceDocInbound.CreateFromPurchOrderHideDialog(PurchaseHeader); + Commit(); + WhseReceiptLine.ReadIsolation(IsolationLevel::ReadCommitted); + WhseReceiptLine.SetRange("Source Document", WhseReceiptLine."Source Document"::"Purchase Order"); + WhseReceiptLine.SetRange("Source No.", PurchaseHeader."No."); + WhseReceiptLine.SetLoadFields("No."); + WhseReceiptLine.FindFirst(); + exit(WhseReceiptLine."No."); + end; + + local procedure PostWarehouseReceipt(WarehouseReceiptNo: Code[20]) + var + WhseReceiptLine: Record "Warehouse Receipt Line"; + begin + WhseReceiptLine.SetRange("No.", WarehouseReceiptNo); + WhseReceiptLine.FindFirst(); + CODEUNIT.Run(CODEUNIT::"Whse.-Post Receipt", WhseReceiptLine); + end; + + + local procedure RegisterPutAway(PurchaseOrderNo: Code[20]) + var + WhseActivLine: Record "Warehouse Activity Line"; + WhseActRegister: Codeunit "Whse.-Activity-Register"; + begin + WhseActivLine.SetRange("Activity Type", "Warehouse Activity Type"::"Put-away"); + WhseActivLine.SetRange("Source Document", WhseActivLine."Source Document"::"Purchase Order"); + WhseActivLine.SetRange("Source No.", PurchaseOrderNo); + if WhseActivLine.FindFirst() then + WhseActRegister.Run(WhseActivLine); + end; +} diff --git a/Peg Board PerformanceTest/src/BCPTWarehouseTasks.codeunit.al b/Peg Board PerformanceTest/src/BCPTWarehouseTasks.codeunit.al new file mode 100644 index 0000000..dadc701 --- /dev/null +++ b/Peg Board PerformanceTest/src/BCPTWarehouseTasks.codeunit.al @@ -0,0 +1,613 @@ +namespace System.Test.Tooling; +using Microsoft.Inventory.Transfer; +using Microsoft.Inventory.Location; +using Microsoft.Warehouse.Setup; +using Microsoft.Inventory.Item; +using Microsoft.Warehouse.Document; +using Microsoft.Purchases.Vendor; +using Microsoft.Inventory.Setup; +using Microsoft.Warehouse.Activity; +using Microsoft.Sales.Document; +using Microsoft.Purchases.Document; +using Microsoft.Warehouse.Structure; +using Microsoft.Inventory.Journal; +using Microsoft.Foundation.NoSeries; +using System.Tooling; +using Microsoft.CRM.Contact; +using Microsoft.CRM.Duplicates; + +codeunit 149201 "BCPT Warehouse Tasks" +{ + SingleInstance = true; + + var + ItemJournalBatch: Record "Item Journal Batch"; + WarehouseEmployee: Record "Warehouse Employee"; + LocationBlue: Record Location; + LocationGreen: Record Location; + LocationOrange: Record Location; + LocationOrange2: Record Location; + LocationOrange3: Record Location; + LocationWhite: Record Location; + LocationRed: Record Location; + LocationPink: Record Location; + LocationIntransit: Record Location; + LibraryWarehouse: Codeunit "Library - Warehouse"; + LibrarySales: Codeunit "Library - Sales"; + LibraryPurchase: Codeunit "Library - Purchase"; + LibraryInventory: Codeunit "Library - Inventory"; + isInitialized: Boolean; + + trigger OnRun() + var + BCPTTestContext: Codeunit "BCPT Test Context"; + begin + BCPTTestContext.StartScenario('TransferWhseShipment'); + TransferWhseShipment(); + BCPTTestContext.EndScenario('TransferWhseShipment'); + BCPTTestContext.UserWait(); + + BCPTTestContext.StartScenario('TransferWhseCreatePick'); + TransferWhseCreatePick(); + BCPTTestContext.EndScenario('TransferWhseCreatePick'); + BCPTTestContext.UserWait(); + + BCPTTestContext.StartScenario('TransferWhseReceipt'); + TransferWhseReceipt(); + BCPTTestContext.EndScenario('TransferWhseReceipt'); + BCPTTestContext.UserWait(); + + BCPTTestContext.StartScenario('WhseCreateSalesOrder'); + WhseCreateSalesOrder(); + BCPTTestContext.EndScenario('WhseCreateSalesOrder'); + BCPTTestContext.UserWait(); + + BCPTTestContext.StartScenario('SalesWhseShipment'); + SalesWhseShipment(); + BCPTTestContext.EndScenario('SalesWhseShipment'); + BCPTTestContext.UserWait(); + + BCPTTestContext.StartScenario('SalesCreatePick'); + SalesCreatePick(); + BCPTTestContext.EndScenario('SalesCreatePick'); + BCPTTestContext.UserWait(); + + BCPTTestContext.StartScenario('SalesRegisterPickPostShipment'); + SalesRegisterPickPostShipment(); + BCPTTestContext.EndScenario('SalesRegisterPickPostShipment'); + BCPTTestContext.UserWait(); + + BCPTTestContext.StartScenario('WhseCreatePurchaseOrder'); + WhseCreatePurchaseOrder(); + BCPTTestContext.EndScenario('WhseCreatePurchaseOrder'); + BCPTTestContext.UserWait(); + + BCPTTestContext.StartScenario('PurchaseWarehouseReceipt'); + PurchaseWarehouseReceipt(); + BCPTTestContext.EndScenario('PurchaseWarehouseReceipt'); + BCPTTestContext.UserWait(); + + BCPTTestContext.StartScenario('PurchasePutAway'); + PurchasePutAway(); + BCPTTestContext.EndScenario('PurchasePutAway'); + BCPTTestContext.UserWait(); + + BCPTTestContext.StartScenario('PurchaseChangeBinAndRegister'); + PurchaseChangeBinAndRegister(); + BCPTTestContext.EndScenario('PurchaseChangeBinAndRegister'); + BCPTTestContext.UserWait(); + + BCPTTestContext.StartScenario('ReceiveTransferOrder'); + ReceiveTransferOrder(); + BCPTTestContext.EndScenario('ReceiveTransferOrder'); + BCPTTestContext.UserWait(); + end; + + local procedure TransferWhseShipment() + var + Item: Record Item; + TransferHeader: Record "Transfer Header"; + TransferLine: Record "Transfer Line"; + begin + // Setup : Create Item, Transfer Order. + Initialize(); + CreateItemAddInventory(Item, LocationOrange.Code, 1); // Value required for Bin Index. + CreateAndRealeaseTransferOrder( + TransferHeader, TransferLine, Item."No.", LocationOrange.Code, LocationOrange2.Code, LocationIntransit.Code); + + // Exercise: Create Warehouse Shipment from Transfer Order. + LibraryWarehouse.CreateWhseShipmentFromTO(TransferHeader); + end; + + local procedure TransferWhseCreatePick() + var + Item: Record Item; + TransferHeader: Record "Transfer Header"; + TransferLine: Record "Transfer Line"; + begin + // Setup : Create Item, Transfer Order, Create Warehouse Shipment from Transfer Order and change bin code on Shipment Line. + Initialize(); + CreateItemAddInventory(Item, LocationOrange.Code, 1); // Value required for Bin Index. + CreateAndRealeaseTransferOrder(TransferHeader, TransferLine, Item."No.", LocationOrange.Code, LocationOrange2.Code, LocationIntransit.Code); + WhseShipFromTOWithNewBinCode(TransferHeader); + end; + + local procedure TransferWhseReceipt() + var + Item: Record Item; + TransferHeader: Record "Transfer Header"; + TransferLine: Record "Transfer Line"; + WarehouseShipmentHeader: Record "Warehouse Shipment Header"; + WarehouseActivityHeader: Record "Warehouse Activity Header"; + begin + // Setup : Create Item, Transfer Order, Create Warehouse Shipment from Transfer Order and change bin code on Shipment Line and Post + // Warehouse Shipment. + Initialize(); + CreateItemAddInventory(Item, LocationOrange.Code, 1); // Value required for Bin Index. + CreateAndRealeaseTransferOrder( + TransferHeader, TransferLine, Item."No.", LocationOrange.Code, LocationOrange2.Code, LocationIntransit.Code); + WhseShipFromTOWithNewBinCode(TransferHeader); + RegisterWarehouseActivity(TransferHeader."No.", WarehouseActivityHeader.Type::Pick); + LibraryWarehouse.PostWhseShipment(WarehouseShipmentHeader, true); + + // Exercise: Create Warehouse Receipt from Transfer Order. + LibraryWarehouse.CreateWhseReceiptFromTO(TransferHeader); + end; + + local procedure RegisterWarehouseActivity(SourceNo: Code[20]; Type: Enum "Warehouse Activity Type") + var + WarehouseActivityHeader: Record "Warehouse Activity Header"; + begin + WarehouseActivityHeader.SetRange(Type, Type); + WarehouseActivityHeader.SetRange("No.", FindWarehouseActivityNo(SourceNo, Type)); + if WarehouseActivityHeader.FindFirst() then + LibraryWarehouse.RegisterWhseActivity(WarehouseActivityHeader); + end; + + local procedure WhseCreateSalesOrder() + var + SalesHeader: Record "Sales Header"; + SalesLine: Record "Sales Line"; + Item: Record Item; + BinCode: Code[20]; + begin + // Setup : Create Item, Bin Content for the item. + Initialize(); + BinCode := CreateItemAddInventory(Item, LocationOrange.Code, 1); // Value required for Bin Index. + + // Exercise. + CreateSalesOrder(SalesHeader, SalesLine, LocationOrange.Code, Item."No.", 5, WorkDate()); + + // Verify: Check that Bin Code is same as Default Bin Code. + SalesLine.TestField("Bin Code", BinCode); + end; + + local procedure SalesWhseShipment() + var + SalesHeader: Record "Sales Header"; + SalesLine: Record "Sales Line"; + Item: Record Item; + begin + // Setup : Create Item, Bin Content for the Item and Create and Release Sales Order. + Initialize(); + CreateItemAddInventory(Item, LocationOrange.Code, 1); // Value required for Bin Index. + CreateSalesOrder(SalesHeader, SalesLine, LocationOrange.Code, Item."No.", 5, WorkDate()); + LibrarySales.ReleaseSalesDocument(SalesHeader); + + // Exercise. + LibraryWarehouse.CreateWhseShipmentFromSO(SalesHeader); + end; + + local procedure SalesCreatePick() + var + SalesHeader: Record "Sales Header"; + SalesLine: Record "Sales Line"; + Item: Record Item; + begin + // Setup : Create Item, Bin Content for the Item and Create and Release Sales Order, Create Warehouse Shipment. + Initialize(); + CreateItemAddInventory(Item, LocationOrange.Code, 1); // Value required for Bin Index. + CreateSalesOrder(SalesHeader, SalesLine, LocationOrange.Code, Item."No.", 5, WorkDate()); + LibrarySales.ReleaseSalesDocument(SalesHeader); + WhseShipFromSOWithNewBinCode(SalesHeader); + end; + + local procedure SalesRegisterPickPostShipment() + var + SalesHeader: Record "Sales Header"; + SalesLine: Record "Sales Line"; + Item: Record Item; + WarehouseShipmentHeader: Record "Warehouse Shipment Header"; + WarehouseActivityHeader: Record "Warehouse Activity Header"; + begin + // Setup : Create Item, Bin Content for the Item and Create and Release Sales Order, Create Warehouse Shipment, Create And + // Register Pick. + Initialize(); + CreateItemAddInventory(Item, LocationOrange.Code, 1); // Value required for Bin Index. + CreateSalesOrder(SalesHeader, SalesLine, LocationOrange.Code, Item."No.", 5, WorkDate()); + LibrarySales.ReleaseSalesDocument(SalesHeader); + WhseShipFromSOWithNewBinCode(SalesHeader); + RegisterWarehouseActivity(SalesHeader."No.", WarehouseActivityHeader.Type::Pick); + + // Exercise. + LibraryWarehouse.PostWhseShipment(WarehouseShipmentHeader, true); + end; + + local procedure WhseCreatePurchaseOrder() + var + PurchaseHeader: Record "Purchase Header"; + PurchaseLine: Record "Purchase Line"; + Item: Record Item; + BinCode: Code[20]; + begin + // Setup : Create Item, Bin Content for the item. + Initialize(); + BinCode := CreateItemAddInventory(Item, LocationOrange.Code, 1); // Value required for Bin Index. + + // Exercise. + CreatePurchaseOrder(PurchaseHeader, PurchaseLine, LocationOrange.Code, Item."No."); + + // Verify: Check that Bin Code is same as Default Bin Code. + PurchaseLine.TestField("Bin Code", BinCode); + end; + + local procedure PurchaseWarehouseReceipt() + var + PurchaseHeader: Record "Purchase Header"; + PurchaseLine: Record "Purchase Line"; + Item: Record Item; + begin + // Setup : Create Item, Bin Content for the Item and Create and Release Sales Order. + Initialize(); + CreateItemAddInventory(Item, LocationOrange.Code, 1); // Value required for Bin Index. + + CreatePurchaseOrder(PurchaseHeader, PurchaseLine, LocationOrange.Code, Item."No."); + LibraryPurchase.ReleasePurchaseDocument(PurchaseHeader); + + // Exercise: + LibraryWarehouse.CreateWhseReceiptFromPO(PurchaseHeader); + end; + + local procedure PurchasePutAway() + var + PurchaseHeader: Record "Purchase Header"; + PurchaseLine: Record "Purchase Line"; + WarehouseReceiptLine: Record "Warehouse Receipt Line"; + Item: Record Item; + begin + // Setup : Create Item, Bin Content for the Item and Create and Release Sales Order. + Initialize(); + CreateItemAddInventory(Item, LocationOrange.Code, 1); // Value required for Bin Index. + + CreatePurchaseOrder(PurchaseHeader, PurchaseLine, LocationOrange.Code, Item."No."); + LibraryPurchase.ReleasePurchaseDocument(PurchaseHeader); + LibraryWarehouse.CreateWhseReceiptFromPO(PurchaseHeader); + + // Exercise: + PostWarehouseReceipt(WarehouseReceiptLine."Source Document"::"Purchase Order", PurchaseHeader."No."); + end; + + local procedure PostWarehouseReceipt(SourceDocument: Enum "Warehouse Activity Source Document"; SourceNo: Code[20]) + var + WarehouseReceiptHeader: Record "Warehouse Receipt Header"; + begin + WarehouseReceiptHeader.Get(FindWarehouseReceiptNo(SourceDocument, SourceNo)); + LibraryWarehouse.PostWhseReceipt(WarehouseReceiptHeader); + end; + + local procedure PurchaseChangeBinAndRegister() + var + PurchaseHeader: Record "Purchase Header"; + PurchaseLine: Record "Purchase Line"; + WarehouseActivityLine: Record "Warehouse Activity Line"; + WarehouseReceiptLine: Record "Warehouse Receipt Line"; + Item: Record Item; + BinCode2: Code[20]; + begin + // Setup : Create Item, Bin Content for the Item and Create and Release Sales Order. + Initialize(); + CreateItemAddInventory(Item, LocationOrange.Code, 1); // Value required for Bin Index. + CreatePurchaseOrder(PurchaseHeader, PurchaseLine, LocationOrange.Code, Item."No."); + LibraryPurchase.ReleasePurchaseDocument(PurchaseHeader); + LibraryWarehouse.CreateWhseReceiptFromPO(PurchaseHeader); + PostWarehouseReceipt(WarehouseReceiptLine."Source Document"::"Purchase Order", PurchaseHeader."No."); + + // Exercise: Change Bin Code on Put Away Line and Register Put Away. + ChangeBinCodeOnActivityLine(BinCode2, PurchaseHeader."No.", LocationOrange.Code); + RegisterWarehouseActivity(PurchaseHeader."No.", WarehouseActivityLine."Activity Type"::"Put-away"); + end; + + local procedure ChangeBinCodeOnActivityLine(var BinCode: Code[20]; SourceNo: Code[20]; LocationCode: Code[10]) + var + Bin: Record Bin; + WarehouseActivityLine: Record "Warehouse Activity Line"; + begin + LibraryWarehouse.FindBin(Bin, LocationCode, '', 2); + BinCode := Bin.Code; + FindWhseActivityLine( + WarehouseActivityLine, WarehouseActivityLine."Activity Type"::"Put-away", LocationCode, SourceNo, + WarehouseActivityLine."Action Type"::Place); + WarehouseActivityLine.Validate("Bin Code", BinCode); + WarehouseActivityLine.Modify(true); + Commit(); + end; + + local procedure ReceiveTransferOrder() + begin + Initialize(); + TransferOrderWithShipmentAndReceipt(); + Commit(); + end; + + local procedure WhseShipFromTOWithNewBinCode(TransferHeader: Record "Transfer Header") + begin + LibraryWarehouse.CreateWhseShipmentFromTO(TransferHeader); + Commit(); + end; + + local procedure TransferOrderWithShipmentAndReceipt() + var + Item: Record Item; + TransferHeader: Record "Transfer Header"; + TransferLine: Record "Transfer Line"; + WarehouseActivityHeader: Record "Warehouse Activity Header"; + WarehouseActivityLine: Record "Warehouse Activity Line"; + WarehouseShipmentHeader: Record "Warehouse Shipment Header"; + begin + // Setup : Create Item, Transfer Order, Create Warehouse Shipment from Transfer Order and Post Warehouse Shipment. + CreateItemAddInventory(Item, LocationOrange.Code, 1); // Value required for Bin Index. + Commit(); + LibraryWarehouse.CreateTransferHeader(TransferHeader, LocationOrange.Code, LocationBlue.Code, LocationIntransit.Code); + LibraryWarehouse.CreateTransferLine(TransferHeader, TransferLine, Item."No.", 50); + Commit(); + LibraryWarehouse.ReleaseTransferOrder(TransferHeader); + Commit(); + WhseShipFromTOWithNewBinCode(TransferHeader); + Commit(); + FindWhseActivityLine( + WarehouseActivityLine, WarehouseActivityLine."Activity Type"::Pick, LocationOrange.Code, TransferHeader."No.", + WarehouseActivityLine."Action Type"::Take); + RegisterWarehouseActivity(TransferHeader."No.", WarehouseActivityHeader.Type::Pick); + Commit(); + + PostWarehouseShipment(WarehouseShipmentHeader."No."); + Commit(); + end; + + local procedure PostWarehouseShipment(No: Code[20]) + var + WarehouseShipmentHeader: Record "Warehouse Shipment Header"; + begin + if WarehouseShipmentHeader.Get(No) then + LibraryWarehouse.PostWhseShipment(WarehouseShipmentHeader, false); + Commit(); + end; + + local procedure CreateItem(var Item: Record Item) + var + Vendor: Record Vendor; + begin + if not Vendor.Get('10000') then + Vendor.FindFirst(); + LibraryInventory.CreateItem(Item); + Item.Validate("Reorder Quantity", 50); // Value Required. + Item.Validate("Vendor No.", Vendor."No."); + Item.Modify(true); + Commit(); + end; + + local procedure CreatePurchaseOrder(var PurchaseHeader: Record "Purchase Header"; var PurchaseLine: Record "Purchase Line"; LocationCode: Code[10]; ItemNo: Code[20]) + var + i: Integer; + begin + // Create Purchase Order with One Item Line. Random values used are not important for test. + LibraryPurchase.CreatePurchHeader(PurchaseHeader, PurchaseHeader."Document Type"::Order, ''); + for i := 1 to 50 do + LibraryPurchase.CreatePurchaseLine(PurchaseLine, PurchaseHeader, PurchaseLine.Type::Item, ItemNo, 1); + PurchaseLine.Validate("Location Code", LocationCode); + PurchaseLine.Modify(true); + Commit(); + end; + + local procedure CreateItemAddInventory(var Item: Record Item; LocationCode: Code[10]; BinIndex: Integer): Code[20] + var + Bin: Record Bin; + begin + LibraryWarehouse.FindBin(Bin, LocationCode, '', BinIndex); + CreateItem(Item); + Commit(); + UpdateItemInventory(Item."No.", LocationCode, Bin.Code, 1); + Commit(); + exit(Bin.Code); + end; + + local procedure UpdateItemInventory(ItemNo: Code[20]; LocationCode: Code[10]; BinCode: Code[20]; Quantity: Decimal) + var + ItemJournalLine: Record "Item Journal Line"; + InventorySetup: Record "Inventory Setup"; + begin + InventorySetup.LockTable(); + InventorySetup.Get(); // semaphore + LibraryInventory.CreateItemJournalLine( + ItemJournalLine, ItemJournalBatch."Journal Template Name", ItemJournalBatch.Name, + ItemJournalLine."Entry Type"::"Positive Adjmt.", ItemNo, Quantity); + ItemJournalLine.Validate("Location Code", LocationCode); + ItemJournalLine.Validate("Bin Code", BinCode); + ItemJournalLine.Modify(true); + LibraryInventory.PostItemJournalLine(ItemJournalBatch."Journal Template Name", ItemJournalBatch.Name); + Commit(); + end; + + local procedure CreateAndRealeaseTransferOrder(var TransferHeader: Record "Transfer Header"; var TransferLine: Record "Transfer Line"; ItemNo: Code[20]; FromLocationCode: Code[10]; ToLocationCode: Code[10]; IntransitLocationCode: Code[10]) + var + ToBin: Record Bin; + i: Integer; + begin + LibraryWarehouse.FindBin(ToBin, ToLocationCode, '', 1); + LibraryWarehouse.CreateTransferHeader(TransferHeader, FromLocationCode, ToLocationCode, IntransitLocationCode); + for i := 1 to 50 do begin + LibraryWarehouse.CreateTransferLine(TransferHeader, TransferLine, ItemNo, 1); + TransferLine.Validate("Transfer-To Bin Code", ToBin.Code); + TransferLine.Modify(true); + end; + Commit(); + + LibraryWarehouse.ReleaseTransferOrder(TransferHeader); + Commit(); + end; + + local procedure FindWarehouseActivityNo(SourceNo: Code[20]; ActivityType: Enum "Warehouse Activity Type"): Code[20] + var + WarehouseActivityLine: Record "Warehouse Activity Line"; + begin + WarehouseActivityLine.SetRange("Source No.", SourceNo); + WarehouseActivityLine.SetRange("Activity Type", ActivityType); + if WarehouseActivityLine.FindFirst() then + exit(WarehouseActivityLine."No."); + exit(''); + end; + + local procedure FindWarehouseReceiptNo(SourceDocument: Enum "Warehouse Activity Source Document"; SourceNo: Code[20]): Code[20] + var + WarehouseReceiptLine: Record "Warehouse Receipt Line"; + begin + WarehouseReceiptLine.SetRange("Source Document", SourceDocument); + WarehouseReceiptLine.SetRange("Source No.", SourceNo); + if WarehouseReceiptLine.FindFirst() then; + exit(WarehouseReceiptLine."No."); + end; + + local procedure WhseShipFromSOWithNewBinCode(SalesHeader: Record "Sales Header") + begin + LibraryWarehouse.CreateWhseShipmentFromSO(SalesHeader); + Commit(); + end; + + local procedure FindWhseActivityLine(var WarehouseActivityLine: Record "Warehouse Activity Line"; ActivityType: Enum "Warehouse Activity Type"; LocationCode: Code[10]; SourceNo: Code[20]; ActionType: Enum "Warehouse Action Type") + begin + WarehouseActivityLine.SetRange("Activity Type", ActivityType); + WarehouseActivityLine.SetRange("Location Code", LocationCode); + WarehouseActivityLine.SetRange("No.", FindWarehouseActivityNo(SourceNo, ActivityType)); + WarehouseActivityLine.SetRange("Action Type", ActionType); + if WarehouseActivityLine.FindSet() then; + end; + + local procedure CreateSalesOrder(var SalesHeader: Record "Sales Header"; var SalesLine: Record "Sales Line"; LocationCode: Code[10]; ItemNo: Code[20]; Quantity: Decimal; ShipmentDate: Date) + begin + // Random values used are not important for test. + LibrarySales.CreateSalesDocumentWithItem( + SalesHeader, SalesLine, SalesHeader."Document Type"::Order, '', ItemNo, Quantity, LocationCode, ShipmentDate); + Commit(); + end; + + local procedure GetGlobalNoSeriesCode(): Code[20] + var + NoSeries: Record "No. Series"; + NoSeriesLine: Record "No. Series Line"; + NewCode: Code[20]; + begin + // Init, get the global no series + NewCode := CopyStr('GLOBAL' + Format(SessionId()), 1, 20); + if not NoSeries.Get(NewCode) then begin + NoSeries.Init(); + NoSeries.Validate(Code, NewCode); + NoSeries.Validate("Default Nos.", true); + NoSeries.Validate("Manual Nos.", true); + NoSeries.Insert(true); + CreateNoSeriesLine(NoSeriesLine, NoSeries.Code, '', ''); + Commit(); + end; + + exit(NoSeries.Code) + end; + + local procedure CreateNoSeriesLine(var NoSeriesLine: Record "No. Series Line"; SeriesCode: Code[20]; StartingNo: Code[20]; EndingNo: Code[20]) + var + RecRef: RecordRef; + begin + NoSeriesLine.Init(); + NoSeriesLine.Validate("Series Code", SeriesCode); + RecRef.GetTable(NoSeriesLine); + NoSeriesLine.Validate("Line No.", 10000); + + if StartingNo = '' then + NoSeriesLine.Validate("Starting No.", PadStr(InsStr(SeriesCode, '00000000', 3), 10)) + else + NoSeriesLine.Validate("Starting No.", StartingNo); + + if EndingNo = '' then + NoSeriesLine.Validate("Ending No.", PadStr(InsStr(SeriesCode, '99999999', 3), 10)) + else + NoSeriesLine.Validate("Ending No.", EndingNo); + NoSeriesLine.Validate(Implementation, NoSeriesLine.Implementation::Sequence); + + NoSeriesLine.Insert(true); + Commit(); + end; + + local procedure ItemJournalSetup() + var + ItemJournalTemplate: Record "Item Journal Template"; + begin + LibraryInventory.SelectItemJournalTemplateName(ItemJournalTemplate, ItemJournalTemplate.Type::Item); + LibraryInventory.SelectItemJournalBatchName(ItemJournalBatch, ItemJournalTemplate.Type::Item, ItemJournalTemplate.Name); + if ItemJournalBatch.Delete() then; + ItemJournalBatch.Name := CopyStr(Format(SessionId()), 1, 10); + ItemJournalBatch.Validate("No. Series", GetGlobalNoSeriesCode()); + ItemJournalBatch.Insert(true); + Commit(); + end; + + local procedure CreateFullWarehouseSetup(var Location: Record Location) + begin + LibraryWarehouse.CreateFullWMSLocation(Location, 2); // Value used for number of bin per zone. + Commit(); + end; + + local procedure CreateLocationSetup() + begin + CreateFullWarehouseSetup(LocationWhite); // Location: White. + LibraryWarehouse.CreateWarehouseEmployee(WarehouseEmployee, LocationWhite.Code, true); + LibraryWarehouse.CreateLocationWMS(LocationGreen, false, true, true, true, true); // Location: Green. + LibraryWarehouse.CreateLocationWMS(LocationBlue, false, false, false, false, false); // Location: Blue. + LibraryWarehouse.CreateLocationWMS(LocationOrange, true, true, true, true, true); // Location: Orange. + LibraryWarehouse.CreateWarehouseEmployee(WarehouseEmployee, LocationOrange.Code, false); + LibraryWarehouse.CreateLocationWMS(LocationOrange2, true, true, true, true, true); // Location: Orange2. + LibraryWarehouse.CreateLocationWMS(LocationOrange3, true, true, false, true, true); // Location: Orange. + LibraryWarehouse.CreateLocationWMS(LocationRed, false, false, false, true, true); // Location: Red. + LibraryWarehouse.CreateLocationWMS(LocationPink, true, false, true, true, true); // Location: Orange. + LibraryWarehouse.CreateInTransitLocation(LocationIntransit); + + LibraryWarehouse.CreateNumberOfBins(LocationOrange.Code, '', '', 3, false); // 2 is required as minimun number of Bin must be 2. + LibraryWarehouse.CreateNumberOfBins(LocationOrange2.Code, '', '', 3, false); + LibraryWarehouse.CreateNumberOfBins(LocationOrange3.Code, '', '', 3, false); + LibraryWarehouse.CreateNumberOfBins(LocationPink.Code, '', '', 3, false); + end; + + local procedure Initialize() + var + WarehouseSetup: Record "Warehouse Setup"; + LibraryERMCountryData: Codeunit "Library - ERM Country Data"; + begin + if isInitialized then + exit; + LibraryERMCountryData.CreateVATData(); + LibraryERMCountryData.CreateGeneralPostingSetupData(); + LibraryERMCountryData.UpdateGeneralPostingSetup(); + LibraryERMCountryData.UpdatePurchasesPayablesSetup(); + CreateLocationSetup(); + ItemJournalSetup(); + WarehouseSetup.Get(); + WarehouseSetup.Validate("Receipt Posting Policy", WarehouseSetup."Receipt Posting Policy"::"Posting errors are not processed"); + WarehouseSetup.Validate("Shipment Posting Policy", WarehouseSetup."Shipment Posting Policy"::"Posting errors are not processed"); + WarehouseSetup.Modify(); + isInitialized := true; + Commit(); + end; + + [EventSubscriber(ObjectType::Codeunit, Codeunit::DuplicateManagement, 'OnMakeContIndex', '', true, true)] + local procedure OnMakeContIndex(var Contact: Record Contact; var IsHandled: Boolean) + begin + Ishandled := true; + end; +} diff --git a/Peg Board PerformanceTest/src/TestCodeunitsWithParams.EnumExt.al b/Peg Board PerformanceTest/src/TestCodeunitsWithParams.EnumExt.al new file mode 100644 index 0000000..6be407f --- /dev/null +++ b/Peg Board PerformanceTest/src/TestCodeunitsWithParams.EnumExt.al @@ -0,0 +1,47 @@ +namespace System.Test.Tooling; + +using System.Tooling; + +enumextension 50800 "Test Codeunits with Params" extends "BCPT Test Param. Enum" +{ + value(50803; "50803") + { + Implementation = "BCPT Test Param. Provider" = "BCPT Create PO with N Lines"; + } + value(50804; "50804") + { + Implementation = "BCPT Test Param. Provider" = "BCPT Create SO with N Lines"; + } + value(50805; "50805") + { + Implementation = "BCPT Test Param. Provider" = "BCPT Create SQ with N Lines"; + } + value(50818; "50818") + { + Implementation = "BCPT Test Param. Provider" = "BCPT Post Sales with N Lines"; + } + value(50819; "50819") + { + Implementation = "BCPT Test Param. Provider" = "BCPT Purch. Post with N Lines"; + } + value(50822; "50822") + { + Implementation = "BCPT Test Param. Provider" = "BCPT Post Purch. Inv."; + } + value(50825; "50825") + { + Implementation = "BCPT Test Param. Provider" = "BCPT Create Vendor"; + } + value(50826; "50826") + { + Implementation = "BCPT Test Param. Provider" = "BCPT Create Customer"; + } + value(50831; "50831") + { + Implementation = "BCPT Test Param. Provider" = "BCPT Sleep X seconds JQ"; + } + value(50832; "50832") + { + Implementation = "BCPT Test Param. Provider" = "BCPT Schedule Job Queue"; + } +} diff --git a/al.code-workspace b/al.code-workspace index 68bc215..194bd45 100644 --- a/al.code-workspace +++ b/al.code-workspace @@ -1,14 +1,17 @@ { - "folders": [ - { - "path": ".AL-Go" - }, - { - "path": "Peg Board" - }, - { - "path": "Peg Board Test" - } - ], - "settings": {} -} \ No newline at end of file + "folders": [ + { + "path": ".AL-Go" + }, + { + "path": "Peg Board" + }, + { + "path": "Peg Board Test" + }, + { + "path": "Peg Board PerformanceTest" + } + ], + "settings": {} +}