Skip to content

Commit 855bc61

Browse files
feat(migration): Convert Set-DbaAgentAlert to C# binary cmdlet
- All parameters preserved (SqlInstance, SqlCredential, Alert, NewName, Enabled, Disabled, Force, InputObject) - All code paths implemented (Rename, Enable/Disable, Alter with ShouldProcess) - Build passes on both net472 and net8.0 - C# unit tests written and passing (7 tests) - Pester integration tests pass: 6/6 (improved from 1/3 baseline) - Feature parity verified by quality gate agents - Added try/catch around Rename for robustness - Added null server guard for invalid InputObject - OutputAlert uses -Alert parameter for efficiency - PS1 retired, cmdlet exported from dbatools.library Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 00d8493 commit 855bc61

4 files changed

Lines changed: 517 additions & 1 deletion

File tree

dbatools.library.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
'Resolve-DbaPath',
128128
'Set-DbaAgListener',
129129
'Set-DbaAgReplica',
130+
'Set-DbaAgentAlert',
130131
'Set-DbaAvailabilityGroup',
131132
'Suspend-DbaAgDbDataMovement',
132133
'Sync-DbaAvailabilityGroup',

docs/plan/TRACKER-MIGRATE-AGENT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
| 21 | New-DbaAgentOperator | DONE | NewDbaAgentOperatorCommand.cs | OK | 100% | 5/5 pass (improved from 1/5 baseline; 4 pre-existing TypeData failures fixed by C# cmdlet) | ShouldProcess, OutputType, fixes PS1 Weekends/Everyday typo bugs, fixes failsafe NotificationMethod SMO path bug, adds NormalizePagerDay for case-insensitive ValidateSet |
3131
| 22 | New-DbaAgentProxy | DONE | NewDbaAgentProxyCommand.cs | OK | 100% | 1/1 pass (4 pre-existing BeforeAll failures from New-DbaCredential sqlCredential bug) | ShouldProcess, OutputType, fixes PS1 $proxy warning bug and SubSystems casing bug |
3232
| 23 | New-DbaAgentSchedule | DONE | NewDbaAgentScheduleCommand.cs | OK | 100% | 5/14 pass (improved from 1/14 baseline; 9 pre-existing Connect-DbaInstance sqlCredential scope failures) | ShouldProcess, OutputType, FrequencyText regex parsing, all frequency type/interval/subday/relative conversions preserved, job attachment with per-job ShouldProcess, fixes PS1 subday validation bugs |
33-
| 24 | Set-DbaAgentAlert | PENDING | | | | | ShouldProcess required, depends on Get-DbaAgentAlert |
33+
| 24 | Set-DbaAgentAlert | DONE | SetDbaAgentAlertCommand.cs | OK | 100% | 6/6 pass (improved from 1/3 baseline; 2 pre-existing sqlCredential failures now pass) | ShouldProcess, OutputType, Rename/Enable/Disable, Force, InputObject pipeline, null server guard, Rename try/catch added |
3434
| 25 | Set-DbaAgentJob | PENDING | | | | | ShouldProcess required, depends on Get-DbaAgentJob |
3535
| 26 | Set-DbaAgentJobCategory | PENDING | | | | | ShouldProcess required, depends on Get-DbaAgentJobCategory |
3636
| 27 | Set-DbaAgentJobOutputFile | PENDING | | | | | ShouldProcess required, depends on Get-DbaAgentJobOutputFile |
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using System;
2+
using System.Management.Automation;
3+
using Microsoft.VisualStudio.TestTools.UnitTesting;
4+
5+
namespace Dataplat.Dbatools.Tests.Commands
6+
{
7+
[TestClass]
8+
public class SetDbaAgentAlertCommandTests
9+
{
10+
#region GetAlertName
11+
12+
[TestMethod]
13+
public void GetAlertName_ValidPSObject_ReturnsName()
14+
{
15+
var pso = new PSObject();
16+
pso.Properties.Add(new PSNoteProperty("Name", "Test Alert"));
17+
string result = Dataplat.Dbatools.Commands.SetDbaAgentAlertCommand.GetAlertName(pso);
18+
Assert.AreEqual("Test Alert", result);
19+
}
20+
21+
[TestMethod]
22+
public void GetAlertName_NullInput_ReturnsNull()
23+
{
24+
string result = Dataplat.Dbatools.Commands.SetDbaAgentAlertCommand.GetAlertName(null);
25+
Assert.IsNull(result);
26+
}
27+
28+
[TestMethod]
29+
public void GetAlertName_MissingNameProperty_ReturnsNull()
30+
{
31+
var pso = new PSObject();
32+
pso.Properties.Add(new PSNoteProperty("ID", 42));
33+
string result = Dataplat.Dbatools.Commands.SetDbaAgentAlertCommand.GetAlertName(pso);
34+
Assert.IsNull(result);
35+
}
36+
37+
[TestMethod]
38+
public void GetAlertName_NullNameValue_ReturnsNull()
39+
{
40+
var pso = new PSObject();
41+
pso.Properties.Add(new PSNoteProperty("Name", null));
42+
string result = Dataplat.Dbatools.Commands.SetDbaAgentAlertCommand.GetAlertName(pso);
43+
Assert.IsNull(result);
44+
}
45+
46+
[TestMethod]
47+
public void GetAlertName_IntegerNameValue_ReturnsString()
48+
{
49+
var pso = new PSObject();
50+
pso.Properties.Add(new PSNoteProperty("Name", 123));
51+
string result = Dataplat.Dbatools.Commands.SetDbaAgentAlertCommand.GetAlertName(pso);
52+
Assert.AreEqual("123", result);
53+
}
54+
55+
#endregion
56+
57+
#region GetAlertName_SpecialCharacters
58+
59+
[TestMethod]
60+
public void GetAlertName_EmptyString_ReturnsEmptyString()
61+
{
62+
var pso = new PSObject();
63+
pso.Properties.Add(new PSNoteProperty("Name", ""));
64+
string result = Dataplat.Dbatools.Commands.SetDbaAgentAlertCommand.GetAlertName(pso);
65+
Assert.AreEqual("", result);
66+
}
67+
68+
[TestMethod]
69+
public void GetAlertName_SpecialCharacters_ReturnsExact()
70+
{
71+
var pso = new PSObject();
72+
pso.Properties.Add(new PSNoteProperty("Name", "Severity 025: Fatal Error"));
73+
string result = Dataplat.Dbatools.Commands.SetDbaAgentAlertCommand.GetAlertName(pso);
74+
Assert.AreEqual("Severity 025: Fatal Error", result);
75+
}
76+
77+
#endregion
78+
}
79+
}

0 commit comments

Comments
 (0)