Auotmated testing and event subscriber

We have an extension with the following event subscriber
[EventSubscriber(Objecttype::Table, Database::“Sales Line”, ‘OnAfterDeleteEvent’, ‘’, false, false)]

When we run the extension normally everything works, but when we do the following in a test codeunit

SalesLine.Delete(true);

The quantity is 0 in the sales line in OnAfterDelete Event

This only happens when running a test codeunit

We isolated the issue to this code in the SalesLine.dal (line 3000 and something)


        // In case we have roundings on VAT or Sales Tax, we should update some other line
        if (Type <> Type::" ") and ("Line No." <> 0) and ("Attached to Line No." = 0) and ("Job Contract Entry No." = 0) and
           (Quantity <> 0) and (Amount <> 0) and (Amount <> "Amount Including VAT") and not StatusCheckSuspended
        then begin
            Quantity := 0;
            "Quantity (Base)" := 0;
            "Qty. to Invoice" := 0;
            "Qty. to Invoice (Base)" := 0;
            "Line Discount Amount" := 0;
            "Inv. Discount Amount" := 0;
            "Inv. Disc. Amount to Invoice" := 0;
            UpdateAmounts();
        end;
		

We had similar issues with Qty modifications and were able to work aorund this with TestPages:

SalesOrderSubform.OpenEdit();
SalesOrderSubform.GoToKey(SalesDocTypeEnum::"Order", SalesHeader."No.", SalesLineNo);
SalesOrderSubform.Quantity.SetValue(10);
SalesOrderSubform.OK.Invoke(); 

Unfortunately, there doesn’t seem to be a method in the SalesOrderSubfrom test page to delete a line

Anyone else seeing this or suggest any workaounds