I would like to combine RegisterExpectedError with additional Asserts.
I have a stored procedure to insert data into a table. Before executing the insert statement, a permission check is done (via a procedure call passing the user name). If a user does not have permission, then an error is thrown and the procedure returns
Apart from checking that the correct error is raised, I would also like to verify that the return status is 1 and that no inserts are performed into the table.
But due to the TRY CATCH mechanism, the ASSERTs are not executed.
How can I achieve this check?
ALTER PROCEDURE dbo.[uta_p_ins_zip_code#NoPermission_ThrowError]
DECLARE @status int
EXEC TST.Assert.RegisterExpectedError @ContextMessage = 'Throw error if user has no permission',
@ExpectedErrorMessage = 'No permission
to insert zip code'
-- Action: Run the sql object under test
EXEC @status = p_ins_zip_code @zip_code = N'12345',
@city = N'MyCity'
EXEC TST.Assert.Equals @ContextMessage = 'Return status should be 1.',
@ExpectedValue = 1,
@ActualValue = @status