--!
--! Remove the testing framework
--!
IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[DropClass]'), N'IsProcedure') = 1
	BEGIN
		EXEC [tSQLt].[DropClass] [tSQLt_test];
		EXEC [tSQLt].[DropClass] [tSQLtclr_test];
		EXEC [tSQLt].[DropClass] [tSQLtPrivate_test];
		EXEC [tSQLt].[DropClass] [tSQLt_testutil];
	END
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[CaptureOutput]'), N'IsProcedure') = 1
	DROP PROCEDURE [tSQLt].[CaptureOutput]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[SuppressOutput]'), N'IsProcedure') = 1
	DROP PROCEDURE [tSQLt].[SuppressOutput]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[CaptureOutputLog]'), N'IsUserTable') = 1
	DROP TABLE [tSQLt].[CaptureOutputLog]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[LogCapturedOutput]'), N'IsProcedure') = 1
	DROP PROCEDURE [tSQLt].[LogCapturedOutput]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[dbo].[InnerProcedure]'), N'IsProcedure') = 1
	DROP PROCEDURE [dbo].[InnerProcedure]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt_test].[Spyee Proc]'), N'IsProcedure') = 1
	DROP PROCEDURE [tSQLt_test].[Spyee Proc]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE [object_id] = OBJECT_ID(N'[tSQLt].[NewTestClass]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[NewTestClass]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[f_Num]'), N'IsInlineFunction') = 1
	DROP FUNCTION [tSQLt].[f_Num]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[private_getCleanObjectName]'), N'IsScalarFunction') = 1
	DROP FUNCTION [tSQLt].[private_getCleanObjectName]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[private_getCleanSchemaName]'), N'IsScalarFunction') = 1
	DROP FUNCTION [tSQLt].[private_getCleanSchemaName]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[private_GetQuotedFullName]'), N'IsScalarFunction') = 1
	DROP FUNCTION [tSQLt].[private_GetQuotedFullName]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[getFullTypeName]'), N'IsInlineFunction') = 1
	DROP FUNCTION [tSQLt].[getFullTypeName]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[TestCaseSummary]'), N'IsInlineFunction') = 1
	DROP FUNCTION [tSQLt].[TestCaseSummary]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[GetTestResultFormatter]'), N'IsScalarFunction') = 1
	DROP FUNCTION [tSQLt].[GetTestResultFormatter]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[private_getForeignKeyDefinition]'), N'IsInlineFunction') = 1
	DROP FUNCTION [tSQLt].[private_getForeignKeyDefinition]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[private_GetLastTestNameIfNotProvided]'), N'IsScalarFunction') = 1
	DROP FUNCTION [tSQLt].[private_GetLastTestNameIfNotProvided]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[private_getSchemaId]'), N'IsScalarFunction') = 1
	DROP FUNCTION [tSQLt].[private_getSchemaId]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[private_isTestClass]'), N'IsScalarFunction') = 1
	DROP FUNCTION [tSQLt].[private_isTestClass]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[private_resolveName]'), N'IsTableFunction') = 1
	DROP FUNCTION [tSQLt].[private_resolveName]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[private_resolveObjectName]'), N'IsTableFunction') = 1
	DROP FUNCTION [tSQLt].[private_resolveObjectName]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[private_resolveSchemaName]'), N'IsTableFunction') = 1
	DROP FUNCTION [tSQLt].[private_resolveSchemaName]
GO

IF OBJECT_ID(N'[tSQLt].[private_TestClasses]') > 0
	DROP VIEW [tSQLt].[private_TestClasses]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[SetFakeViewOff]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[SetFakeViewOff]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[private_SaveTestNameForSession]'), N'IsProcedure') = 1
	DROP PROCEDURE [tSQLt].[private_SaveTestNameForSession]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[private_SetFakeViewOff_SingleView]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[private_SetFakeViewOff_SingleView]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[SetFakeViewOn]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[SetFakeViewOn]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[private_SetFakeViewOn_SingleView]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[private_SetFakeViewOn_SingleView]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[ApplyConstraint]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[ApplyConstraint]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[AssertEqualsTable]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[AssertEqualsTable]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[TableCompare]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[TableCompare]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[FakeTable]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[FakeTable]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[private_RenameObjectToUniqueName]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[private_RenameObjectToUniqueName]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[StubRecord]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[StubRecord]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[AssertObjectExists]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[AssertObjectExists]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[AssertEqualsString]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[AssertEqualsString]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[AssertEquals]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[AssertEquals]
GO


IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[SpyProcedure]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[SpyProcedure]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[private_ValidateProcedureCanBeUsedWithSpyProcedure]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[private_ValidateProcedureCanBeUsedWithSpyProcedure]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[RunAll]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[RunAll]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[private_RunTestClass]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[private_RunTestClass]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[RunTestClass]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[RunTestClass]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[Run]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[Run]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[RunTestClassSummary]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[RunTestClassSummary]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[XmlResultFormatter]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[XmlResultFormatter]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[TableToText]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[TableToText]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[DefaultResultFormatter]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[DefaultResultFormatter]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[SetTestResultFormatter]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[SetTestResultFormatter]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[RunTest]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[RunTest]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[private_CleanTestResult]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[private_CleanTestResult]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[private_RunTest]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[private_RunTest]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[Fail]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[Fail]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[getNewTranName]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[getNewTranName]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[private_PrintXML]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[private_PrintXML]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[private_Print]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[private_Print]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[TestSystemProperty]'), N'IsUserTable') = 1
	DROP TABLE [tSQLt].[TestSystemProperty]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[Run_LastExecution]'), N'IsUserTable') = 1
	DROP TABLE [tSQLt].[Run_LastExecution]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[TestMessage]'), N'IsUserTable') = 1
	DROP TABLE [tSQLt].[TestMessage]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[TestResult]'), N'IsUserTable') = 1
	DROP TABLE [tSQLt].[TestResult]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[Exception]'), N'IsUserTable') = 1
	DROP TABLE [tSQLt].[Exception]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[ResultsetFilter]') AND type in (N'P', N'PC'))
DROP PROCEDURE [tSQLt].[ResultsetFilter]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[AssertResultSetsHaveSameMetaData]') AND type in (N'P', N'PC'))
DROP PROCEDURE [tSQLt].[AssertResultSetsHaveSameMetaData]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[NewConnection]'), N'IsProcedure') = 1
	DROP PROCEDURE [tSQLt].[NewConnection]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[DropClass]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [tSQLt].[DropClass]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[ResultsetFilter]'), N'IsProcedure') = 1
	DROP PROCEDURE [tSQLt].[ResultsetFilter]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[AssertResultSetsHaveSameMetaData]'), N'IsProcedure') = 1
	DROP PROCEDURE [tSQLt].[AssertResultSetsHaveSameMetaData]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[NewConnection]'), N'IsProcedure') = 1
	DROP PROCEDURE [tSQLt].[NewConnection]
GO

IF TYPE_ID('tSQLtPrivate') IS NOT NULL
	DROP TYPE [tSQLtPrivate]
GO

IF EXISTS (SELECT 1 FROM sys.assemblies WHERE name = 'tSQLtCLR')
    DROP ASSEMBLY tSQLtCLR;
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[Exception]'), N'IsUserTable') = 1
	DROP TABLE [tSQLt].[Exception]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[ExceptionHandler]'), N'IsProcedure') = 1
	DROP PROCEDURE [tSQLt].[ExceptionHandler]
GO


IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[tSQLt].[AssertTableExists]') AND type in (N'P', N'PC'))
DROP PROCEDURE [tSQLt].[AssertTableExists]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[AssertTableHasAnyUniqueKey]'), N'IsProcedure') = 1
	DROP PROCEDURE [tSQLt].[AssertTableHasAnyUniqueKey]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[AssertTableColumnCount]'), N'IsProcedure') = 1
	DROP PROCEDURE [tSQLt].[AssertTableColumnCount]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[AssertTableColumnExists]'), N'IsProcedure') = 1
	DROP PROCEDURE [tSQLt].[AssertTableColumnExists]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[AssertDefaultConstraintDefinition]'), N'IsProcedure') = 1
  DROP PROCEDURE [tSQLt].[AssertDefaultConstraintDefinition]
GO

IF OBJECTPROPERTY(OBJECT_ID(N'[tSQLt].[AssertPrimaryKeyDefinition]'), N'IsProcedure') = 1
  DROP PROCEDURE [tSQLt].[AssertPrimaryKeyDefinition]
GO



IF SCHEMA_ID('NameAndIdResolutionTests') > 0 DROP SCHEMA [NameAndIdResolutionTests];
GO

IF SCHEMA_ID('tSQLt_test') > 0 DROP SCHEMA [tSQLt_test];
GO

IF SCHEMA_ID('tSQLtclr_test') > 0 DROP SCHEMA [tSQLtclr_test];
GO

IF SCHEMA_ID('tSQLtPrivate_test') > 0 DROP SCHEMA [tSQLtPrivate_test];
GO

IF SCHEMA_ID('tSQLt_testutil') > 0 DROP SCHEMA [tSQLt_testutil];
GO

IF SCHEMA_ID('tSQLt') > 0 DROP SCHEMA [tSQLt];
GO


SET NOCOUNT OFF;
GO

