-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathFailTests.class.sql
More file actions
102 lines (83 loc) · 2.41 KB
/
Copy pathFailTests.class.sql
File metadata and controls
102 lines (83 loc) · 2.41 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
EXEC tSQLt.NewTestClass 'FailTests';
GO
CREATE PROCEDURE FailTests.[InvalidateTransaction]
AS
BEGIN
BEGIN TRY
DECLARE @i INT ;
SET @i = 'NAN';
END TRY
BEGIN CATCH
END CATCH;
END;
GO
CREATE PROC FailTests.[test Fail rolls back transaction if transaction is unable to be committed]
AS
BEGIN
DECLARE @ErrorMessage NVARCHAR(MAX);
SET @ErrorMessage = 'No Error Thrown';
EXEC FailTests.InvalidateTransaction;
BEGIN TRY
EXEC tSQLt.Fail 'Not really a failure - just seeing that fail works';
END TRY
BEGIN CATCH
SET @ErrorMessage = ERROR_MESSAGE();
END CATCH;
EXEC tSQLt.AssertEqualsString 'tSQLt.Failure', @ErrorMessage;
END;
GO
CREATE PROC FailTests.[test Fail does not change open tansaction count in case of XACT_STATE = -1]
AS
BEGIN
DECLARE @ErrorMessage NVARCHAR(MAX);
SET @ErrorMessage = 'No Error Thrown';
BEGIN TRAN;
EXEC FailTests.InvalidateTransaction;
BEGIN TRY
EXEC tSQLt.Fail 'Not really a failure - just seeing that fail works';
END TRY
BEGIN CATCH
SET @ErrorMessage = ERROR_MESSAGE();
END CATCH;
COMMIT;
EXEC tSQLt.AssertEqualsString 'tSQLt.Failure', @ErrorMessage;
END;
GO
CREATE PROC FailTests.[test Fail recreates savepoint if it has to clean up transactions]
AS
BEGIN
DECLARE @TranName NVARCHAR(MAX);
SELECT @TranName = TranName
FROM tSQLt.TestResult
WHERE Id = (SELECT MAX(Id) FROM tSQLt.TestResult);
EXEC FailTests.InvalidateTransaction;
BEGIN TRY
EXEC tSQLt.Fail 'Not really a failure - just seeing that fail works';
END TRY
BEGIN CATCH
END CATCH;
BEGIN TRY
ROLLBACK TRAN @TranName;
END TRY
BEGIN CATCH
EXEC tSQLt.Fail 'Expected to be able to rollback the named transaction';
END CATCH;
END;
GO
CREATE PROC FailTests.[test Fail gives info about cleanup work if transaction state is invalidated]
AS
BEGIN
EXEC FailTests.InvalidateTransaction;
BEGIN TRY
EXEC tSQLt.Fail 'Not really a failure - just seeing that fail works';
END TRY
BEGIN CATCH
END CATCH;
DECLARE @TestResultMessage NVARCHAR(MAX);
SELECT @TestResultMessage = Msg
FROM #TestMessage;
DECLARE @ExpectedMessage NVARCHAR(MAX);
SET @ExpectedMessage = '%Not really a failure - just seeing that fail works%'+CHAR(13)+CHAR(10)+'Warning: Uncommitable transaction detected!%'
EXEC tSQLt.AssertLike @ExpectedMessage, @TestResultMessage;
END;
GO