param( [Parameter(Mandatory = $true)][string]$ConfigPath, [Parameter(Mandatory = $true)][ValidateSet('Seed','SuppressSecond','Check')][string]$Mode ) $ErrorActionPreference = 'Stop' . (Join-Path $PSScriptRoot 'mail-common.ps1') $context = Get-MailContext $ConfigPath $db = Open-MailDatabase $context try { if ($Mode -eq 'Seed') { foreach ($address in @('one@example.invalid','two@example.invalid','three@example.invalid','blocked@example.invalid')) { $command = $db.CreateCommand() $command.CommandText = "INSERT INTO [Contact] ([EmailOriginal],[EmailKey],[BusinessName],[SourceReference],[Country],[EligibilityBasis],[CreatedAtUtc]) VALUES (?,?,?,?,?,?,?)" foreach ($value in @($address,$address,'Example Business','https://example.invalid/listing','US','public_listing')) { $null = $command.Parameters.Add('text', [System.Data.OleDb.OleDbType]::VarWChar, 254) $command.Parameters[$command.Parameters.Count - 1].Value = $value } $null = $command.Parameters.Add('created', [System.Data.OleDb.OleDbType]::Date) $command.Parameters[6].Value = [DateTime]::UtcNow $null = $command.ExecuteNonQuery() } } if ($Mode -in @('Seed','SuppressSecond')) { $address = if ($Mode -eq 'Seed') { 'blocked@example.invalid' } else { 'two@example.invalid' } $command = $db.CreateCommand() $command.CommandText = 'INSERT INTO [Suppression] ([EmailKey],[Reason],[RecordedAtUtc]) VALUES (?,?,?)' $null = $command.Parameters.Add('email', [System.Data.OleDb.OleDbType]::VarWChar, 254) $command.Parameters[0].Value = $address $null = $command.Parameters.Add('reason', [System.Data.OleDb.OleDbType]::VarWChar, 40) $command.Parameters[1].Value = 'opt-out' $null = $command.Parameters.Add('recorded', [System.Data.OleDb.OleDbType]::Date) $command.Parameters[2].Value = [DateTime]::UtcNow $null = $command.ExecuteNonQuery() } if ($Mode -eq 'Check') { $command = $db.CreateCommand() $command.CommandText = "SELECT COUNT(*) FROM [Campaign] WHERE [Status]='approved_paused'" if ([int]$command.ExecuteScalar() -ne 1) { throw 'Expected one approved paused campaign' } $command.CommandText = "SELECT COUNT(*) FROM [Delivery] WHERE [Status]='pending'" if ([int]$command.ExecuteScalar() -ne 2) { throw 'Expected two pending deliveries' } $command.CommandText = 'SELECT COUNT(*) FROM [Attempt]' if ([int]$command.ExecuteScalar() -ne 0) { throw 'Internal test unexpectedly advanced the live attempt queue' } } } finally { $db.Dispose() }