-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUnitTest_00_TestSetup.sql
More file actions
executable file
·225 lines (199 loc) · 5.87 KB
/
UnitTest_00_TestSetup.sql
File metadata and controls
executable file
·225 lines (199 loc) · 5.87 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
if object_id('dbo.UnitTest_PopulateDDL') is not null
begin
exec ('drop procedure dbo.UnitTest_PopulateDDL')
end
go
create procedure dbo.UnitTest_PopulateDDL
as
begin
delete from dbo.SyncConfig
where TargetTable in ('UnitTest_TargetTable1','UnitTest_TargetTable2')
insert into dbo.SyncConfig
([TargetDatabase]
,[TargetSchema]
,[TargetTable]
,[SourceDatabase]
,[SourceSchema]
,[SourceTable]
,[IsActive]
,[ProcessMode]
,[TableGroup]
,SurrogateKeyColumn
,SurrogateTable
,[PrimaryKeyColumns]
,[TargetActiveColumn]
,[TargetCreateDateColumn]
,[TargetUpdateDateColumn]
,[SourceUpdateDateColumn]
,[IsSourceCleanupAfterRun]
,IsSourceToLoadCopy
,IsDiff)
select
db_name() as TargetDatabase
,'dbo' as TargetSchema
,'UnitTest_TargetTable1' as TargetTable
,db_name() as SourceDatabase
,'dbo' as SourceSchema
,'UnitTest_SourceTable1' as SourceTable
,1 as IsActive
,'Type-1' as ProcessMode
,'UnitTest' as TableGroup
,'TargetTableID' as SurrogateKeyColumn
,'UnitTest_SKMap_TargetTable1' as SurrogateTable
,N'<columns>
<column name="PKColumn" />
</columns>' as PrimaryKeyColumns
,'UnitTestIsActive' as TargetActiveColumn
,'UnitTestCreateDate' as TargetCreateDateColumn
,'UnitTestUpdateDate' as TargetUpdateDateColumn
,'UnitTestStagingTime' as SourceUpdateDateColumn
,0 as IsSourceCleanupAfterRun
,1 as IsSourceToLoadCopy
,1 as IsDiff
insert into dbo.SyncConfig
([TargetDatabase]
,[TargetSchema]
,[TargetTable]
,[SourceDatabase]
,[SourceSchema]
,[SourceTable]
,[IsActive]
,[ProcessMode]
,[TableGroup]
,SurrogateKeyColumn
,SurrogateTable
,[PrimaryKeyColumns]
,[TargetBeginDateColumn]
,[TargetEndDateColumn]
,[TargetCreateDateColumn]
,[TargetUpdateDateColumn]
,[SourceUpdateDateColumn]
,[IsSourceCleanupAfterRun]
,IsSourceToLoadCopy
,IsDiff)
select
db_name() as TargetDatabase
,'dbo' as TargetSchema
,'UnitTest_TargetTable2' as TargetTable
,db_name() as SourceDatabase
,'dbo' as SourceSchema
,'UnitTest_SourceTable1' as SourceTable
,1 as IsActive
,'Type-2' as ProcessMode
,'UnitTest' as TableGroup
,'TargetTableID' as SurrogateKeyColumn
,'UnitTest_SKMap_TargetTable1' as SurrogateTable
,N'<columns>
<column name="PKColumn" />
</columns>' as PrimaryKeyColumns
,'UnitTestBeginDate' as TargetBeginDateColumn
,'UnitTestEndDate' as TargetEndDateColumn
,'UnitTestCreateDate' as TargetCreateDateColumn
,'UnitTestUpdateDate' as TargetUpdateDateColumn
,'UnitTestStagingTime' as SourceUpdateDateColumn
,0 as IsSourceCleanupAfterRun
,1 as IsSourceToLoadCopy
,1 as IsDiff
end
go
exec UnitTest_PopulateDDL
go
if object_id('dbo.UnitTest_SourceTable1') is not null
begin
exec ('drop table dbo.UnitTest_SourceTable1')
end
go
if object_id('dbo.UnitTest_TargetTable1') is not null
begin
exec ('drop table dbo.UnitTest_TargetTable1')
end
go
if object_id('dbo.UnitTest_SKMap_TargetTable1') is not null
begin
exec ('drop table dbo.UnitTest_SKMap_TargetTable1')
end
go
if object_id('dbo.UnitTest_TargetTable2') is not null
begin
exec ('drop table dbo.UnitTest_TargetTable2')
end
go
create table dbo.UnitTest_TargetTable1
(TargetTableID int not null
,PKColumn varchar(400) not null primary key clustered
,IntColumn int
,GuidColumn uniqueidentifier
,NvarcharColumn nvarchar(400)
,DateColumn datetime
,UnitTestStagingTime datetime not null default(getdate())
,UnitTestIsActive bit
,UnitTestCreateDate datetime
,UnitTestUpdateDate datetime
)
go
create table dbo.UnitTest_TargetTable2
(TargetTableID int not null
,PKColumn varchar(400) not null
,IntColumn int
,GuidColumn uniqueidentifier
,NvarcharColumn nvarchar(400)
,DateColumn datetime
,UnitTestStagingTime datetime not null
,UnitTestBeginDate datetime
,UnitTestEndDate datetime
,UnitTestCreateDate datetime
,UnitTestUpdateDate datetime
,constraint UnitTest_TargetTable2PK primary key clustered (TargetTableID, UnitTestBeginDate)
)
go
create table dbo.UnitTest_SourceTable1
(PKColumn varchar(400) not null primary key clustered
,IntColumn int
,GuidColumn uniqueidentifier
,NvarcharColumn nvarchar(400)
,DateColumn datetime
,UnitTestStagingTime datetime not null default(getdate())
)
go
create table dbo.UnitTest_SKMap_TargetTable1
(TargetTableID int not null
,PKColumn varchar(400) not null
,constraint UnitTest_SKMap_TargetTable1PK primary key clustered (TargetTableID)
)
go
; WITH Nbrs_3( n ) AS ( SELECT 1 UNION SELECT 0 ),
Nbrs_2( n ) AS ( SELECT 1 FROM Nbrs_3 n1 CROSS JOIN Nbrs_3 n2 ),
Nbrs_1( n ) AS ( SELECT 1 FROM Nbrs_2 n1 CROSS JOIN Nbrs_2 n2 ),
Nbrs_0( n ) AS ( SELECT 1 FROM Nbrs_1 n1 CROSS JOIN Nbrs_1 n2 ),
Nbrs ( n ) AS ( SELECT 1 FROM Nbrs_0 n1 CROSS JOIN Nbrs_0 n2 )
insert into dbo.UnitTest_SourceTable1
(PKColumn
,IntColumn
,GuidColumn
,NvarcharColumn
,DateColumn
,UnitTestStagingTime)
SELECT
PKColumn = cast(n as varchar) + cast(n as varchar)
,n as IntColumn
,newid() as GuidColumn
,NvarcharColumn = N'TestData='+cast(n as varchar) + cast(n as varchar)
,DateColumn = dateadd(ss,-1.0*n,getdate())
,UnitTestStagingTime = getdate()
FROM ( SELECT ROW_NUMBER() OVER (ORDER BY n)
FROM Nbrs ) D ( n )
WHERE n <= 500 ;
go
select case when count(*)=2 then 'Success' else 'Failure' end as Status
,'Make sure both unit test sync configs exist' as TestDescription
from dbo.SyncConfig
where TargetTable in ('UnitTest_TargetTable1','UnitTest_TargetTable2')
union all
select case when count(*)=4 then 'Success' else 'Failure' end as Status
,'Make sure 4 unit test tables exist' as TestDescription
from sys.tables t
where t.name in ('UnitTest_SourceTable1','UnitTest_SKMap_TargetTable1','UnitTest_TargetTable1','UnitTest_TargetTable2')
union all
select case when count(*)=500 then 'Success' else 'Failure' end as Status
,'Make sure source table has 500 rows' as TestDescription
from dbo.UnitTest_SourceTable1