Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save elincognito/7b65704bae8b4aa6a3ad to your computer and use it in GitHub Desktop.
Save elincognito/7b65704bae8b4aa6a3ad to your computer and use it in GitHub Desktop.
EXEC tSQLt.NewTestClass 'OAMTest';
GO
CREATE PROCEDURE OAMTest.[test that spAddresses_Insert inserts the proper values in the Address table]
AS
BEGIN
DECLARE @Id AS INT,
@UserId AS BIGINT = 1,
@AddressTypeId AS BIGINT = 2,
@Address AS NVARCHAR (256) = 'Quintas do Norte',
@CityId AS BIGINT = 3,
@DistrictId AS BIGINT = 4,
@ZipCode AS NVARCHAR (15) = '4710-311',
@Country AS NVARCHAR (50) = 'Portugal';
--Assemble: Fake the Address table to make sure it is empty and that constraints will not be a problem
EXEC tSQLt.FakeTable 'Addresses';
EXEC @Id = [dbo].[spAddresses_Insert] @UserId, @AddressTypeId, @Address, @CityId, @DistrictId, @ZipCode, @Country;
SELECT Id, UserId, AddressTypeId, Address, CityId, DistrictId, ZipCode, Country
INTO #Actual
FROM Addresses
--Assert: Create an #Expected temp table that has the same structure and the data we expect to have been inserted
SELECT TOP(1) *
INTO #Expected
FROM (SELECT @Id as Id,
@UserId as UserId,
@AddressTypeId as AddressTypeId,
@Address as [Address],
@CityId as CityId,
@DistrictId as DistrictId,
@ZipCode as ZipCode,
@Country as Country) as T;
-- Compare the data in the #Expected and Actual tables
EXEC tSQLt.AssertEqualsTable '#Expected', '#Actual';
END;
GO
EXEC tSQLT.runAll
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment