-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample-5-testing-trigger.sql
49 lines (33 loc) · 1.06 KB
/
example-5-testing-trigger.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* Example 6
* Testing a trigger
*
*
*/
-- (Show Trigger definition)
IF OBJECT_ID('[tSQLtDemo].[Test WorkOrder INSERT triggers TransactionHistory record]','P') IS NOT NULL
BEGIN
DROP PROCEDURE [tSQLtDemo].[Test WorkOrder INSERT triggers TransactionHistory record]
END
GO
CREATE PROCEDURE [tSQLtDemo].[Test WorkOrder INSERT triggers TransactionHistory record] AS
BEGIN
-- Table on which trigger defined
exec tSQLt.FakeTable 'Production.WorkOrder'
-- Trigger predicate table
exec tSQLt.FakeTable 'Production.TransactionHistory'
exec tSQLt.ApplyTrigger 'Production.WorkOrder', 'iWorkOrder'
INSERT INTO Production.WorkOrder (ProductID, WorkOrderID, OrderQty)
VALUES (1, 2, 3)
select ProductID, ReferenceOrderID, Quantity
INTO #Actual
from Production.TransactionHistory
-- Get type info for expected table, no records
select top 0 *
into #Expected
from #Actual
INSERT INTO #Expected VALUES (1, 2, 3)
EXEC tSQLt.AssertEqualsTable '#Expected', '#Actual'
END
GO
exec tSQLt.Run '[tSQLtDemo].[Test WorkOrder INSERT triggers TransactionHistory record]'