I'm having difficulties unit testing certain concepts like a context. Let's say I'm having the following use case;
The purchase_order (PO) contains purchase_order_line's (POL). When the PO has the status ‘done’, the user or api cannot insert or update PO lines for that PO. I've disabled this using a trigger, i.e.
if exists (
select 1
from inserted i -- purchase_order_line
join purchase_order po
on po.purchase_order_id = i.purchase_order_id
where po.status = 'done'
)
begin
-- abort etc, cancel insert/update for purchase_order_line.
end
I have attached a layout and a context concepts for both the PO and POL's.
I want to unit test the behaviour for in example the context or layout of a purchase_order_line, that certain tasks / buttons are disabled. This can be done via unit test or via process tests.
If I do this via unit tests I have to create a Data set. When I do this and I execute the unit test, the data set creation fails: Due to the trigger i'm not able to both insert a purchase_order with status ‘done’ and a purchase_order_line.
Question is: How to deal with triggers in data sets? Can they be temporarily disabled?
An alternative is to create a process test, but that lack's the presence of data sets and should not replace the simplicity of an unit test.