60 lines
4.6 KiB
PowerShell
60 lines
4.6 KiB
PowerShell
# Offline UI/schema tests. No connection is opened and no database is modified.
|
|
$ErrorActionPreference = 'Stop'
|
|
Add-Type -AssemblyName System.Windows.Forms
|
|
Add-Type -AssemblyName System.Data
|
|
$assembly = [Reflection.Assembly]::LoadFrom((Join-Path $PSScriptRoot '../TBF/bin/Debug/SkeletonKeysImport-check.dll'))
|
|
$type = $assembly.GetType('TBF.Rig.BridgeComponents.GciBridge.UI.ConfiguredDatabaseForm')
|
|
$flags = [Reflection.BindingFlags]'Instance,NonPublic'
|
|
$resolve = $type.GetMethod('ResolveTable')
|
|
foreach ($case in @(
|
|
@('SELECT [Password] FROM [custom].[Keys] WHERE [PcbId] = QUERYPARAM', $false, '[custom].[Keys]'),
|
|
@('SELECT [ParameterName], [ParameterValue] FROM [dbo].[PreAdjustmentCalibrationParams] WHERE [MeterSize] = QUERYPARAM', $false, '[dbo].[PreAdjustmentCalibrationParams]'),
|
|
@('INSERT INTO [dbo].[Q3Calibration] ([PcbId]) VALUES (@PcbId)', $true, '[dbo].[Q3Calibration]')
|
|
)) {
|
|
if ($resolve.Invoke($null, @($case[0],$case[1])) -ne $case[2]) { throw 'Wrong configured target' }
|
|
}
|
|
foreach ($sql in @('SELECT * FROM dbo.Keys JOIN dbo.Other ON 1=1', 'SELECT * FROM OtherDb.dbo.Keys', 'EXEC dbo.SaveKeys', 'SELECT * FROM dbo.Keys; DELETE FROM dbo.Keys')) {
|
|
$rejected = $false
|
|
try { [void]$resolve.Invoke($null,@($sql,$false)) } catch { $rejected = $true }
|
|
if (-not $rejected) { throw 'Ambiguous SQL was accepted' }
|
|
}
|
|
$form = [Activator]::CreateInstance($type,@('Q3CalibrationWriter','Server=(localdb)\Test;Database=Test;Integrated Security=True','[dbo].[Q3Calibration]','Q3CalibrationWriter'))
|
|
try {
|
|
$eventKey = [Windows.Forms.Form].GetField('EVENT_SHOWN',[Reflection.BindingFlags]'Static,NonPublic').GetValue($null)
|
|
$events = [ComponentModel.Component].GetProperty('Events',[Reflection.BindingFlags]'Instance,NonPublic').GetValue($form,$null)
|
|
$events.RemoveHandler($eventKey,$events[$eventKey])
|
|
$data = New-Object Data.DataTable
|
|
[void]$data.Columns.Add('Id',[int]); [void]$data.Columns.Add('PcbId',[string]); [void]$data.Columns.Add('P1Cal',[decimal])
|
|
$data.PrimaryKey = [Data.DataColumn[]]@($data.Columns['Id'])
|
|
[void]$data.Rows.Add([object[]]@(1,'001234567',[decimal]1.25)); $data.AcceptChanges()
|
|
$type.GetField('original',$flags).SetValue($form,$data)
|
|
$copy = $data.Copy()
|
|
[void]$type.GetMethod('SetProposals',$flags).Invoke($form,(,$copy))
|
|
$form.ShowInTaskbar = $false; $form.Opacity = 0; $form.Show()
|
|
[Windows.Forms.Application]::DoEvents()
|
|
$copy.Rows[0]['P1Cal'] = [decimal]2.5
|
|
[void]$copy.Rows.Add([object[]]@(2,'001234568',[decimal]1.5))
|
|
[void]$type.GetMethod('ReviewChanges',$flags).Invoke($form,@())
|
|
$queue = $type.GetField('queue',$flags).GetValue($form)
|
|
if ($queue.Rows.Count -ne 2 -or $queue.Rows[0].Cells['Action'].Value -ne 'Update' -or $queue.Rows[1].Cells['Action'].Value -ne 'New') { throw 'New/update classification failed' }
|
|
$apply = $type.GetField('apply',$flags).GetValue($form)
|
|
$queue.ClearSelection(); $queue.Rows[0].Selected = $true
|
|
[void]$type.GetMethod('Decide',$flags).Invoke($form,@('Approved'))
|
|
if ($apply.Enabled) { throw 'Pending proposal did not block apply' }
|
|
$queue.ClearSelection(); $queue.Rows[1].Selected = $true
|
|
[void]$type.GetMethod('Decide',$flags).Invoke($form,@('Rejected'))
|
|
if (-not $apply.Enabled) { throw 'Reviewed subset was blocked' }
|
|
$copy.Rows[0]['P1Cal'] = [decimal]3
|
|
if ($apply.Enabled -or $null -ne $type.GetField('reviewed',$flags).GetValue($form)) { throw 'Edited data retained approval' }
|
|
$type.GetField('filter',$flags).GetValue($form).Text = '001234567'
|
|
if ($type.GetField('records',$flags).GetValue($form).Rows.Count -ne 1) { throw 'Automatic filtering failed' }
|
|
[void]$type.GetMethod('Report',$flags).Invoke($form,@('Conflict', $true))
|
|
if ($type.GetField('status',$flags).GetValue($form).ForeColor -ne [Drawing.Color]::Firebrick) { throw 'Errors are not red' }
|
|
$bitmap = New-Object Drawing.Bitmap($form.Width,$form.Height)
|
|
try { $form.DrawToBitmap($bitmap,(New-Object Drawing.Rectangle(0,0,$form.Width,$form.Height))); $bitmap.Save((Join-Path $PSScriptRoot '../TBF/bin/Debug/ConfiguredDatabaseManager-preview.png')) } finally { $bitmap.Dispose() }
|
|
$noKey = $data.Copy(); $noKey.PrimaryKey = [Data.DataColumn[]]@()
|
|
[void]$type.GetMethod('SetProposals',$flags).Invoke($form,(,$noKey))
|
|
if (-not $type.GetField('editor',$flags).GetValue($form).ReadOnly -or $type.GetField('check',$flags).GetValue($form).Enabled) { throw 'Table without a key permits writes' }
|
|
Write-Output 'PASS: configured targets, unsupported SQL rejection, new/update review, approval invalidation, automatic filtering, red errors and read-only tables without primary keys.'
|
|
} finally { $form.Dispose() }
|