Skip to content

Commit 8ec4686

Browse files
feat(migration): Convert Set-DbaAgentJob to C# binary cmdlet
- All 20+ parameters preserved (Job, Schedule, ScheduleId, NewName, Enabled, Disabled, Description, StartStepId, Category, OwnerLogin, EventLogLevel, EmailLevel, NetsendLevel, PageLevel, EmailOperator, NetsendOperator, PageOperator, DeleteLevel, Force, InputObject) - All code paths implemented including notification level/operator validation, schedule attachment, category creation with Force, step ID validation, login/operator existence checks - ShouldProcess on Rename, AddSharedSchedule, category creation, and final Alter() - OutputType attribute added - Build passes on both net472 and net8.0 - C# unit tests written and passing (12 tests for ConvertCompletionLevel, GetJobName, GetJobPropertyString) - Pester integration tests pass (1/1 baseline maintained) - Feature parity verified by quality gate agents - Fixed copy-paste bug in PageLevel error message ("netsend" → "page") - PS1 retired, cmdlet exported from dbatools.library Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 855bc61 commit 8ec4686

4 files changed

Lines changed: 1248 additions & 1 deletion

File tree

dbatools.library.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
'Set-DbaAgListener',
129129
'Set-DbaAgReplica',
130130
'Set-DbaAgentAlert',
131+
'Set-DbaAgentJob',
131132
'Set-DbaAvailabilityGroup',
132133
'Suspend-DbaAgDbDataMovement',
133134
'Sync-DbaAvailabilityGroup',

docs/plan/TRACKER-MIGRATE-AGENT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
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 |
3333
| 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 |
34-
| 25 | Set-DbaAgentJob | PENDING | | | | | ShouldProcess required, depends on Get-DbaAgentJob |
34+
| 25 | Set-DbaAgentJob | DONE | SetDbaAgentJobCommand.cs | OK | 100% | 1/1 pass | ShouldProcess, OutputType, Force+Category creation, notification level/operator validation, Schedule/ScheduleId attachment, Rename/Enable/Disable/Description/StartStepId/OwnerLogin/DeleteLevel, InputObject pipeline, null server guard |
3535
| 26 | Set-DbaAgentJobCategory | PENDING | | | | | ShouldProcess required, depends on Get-DbaAgentJobCategory |
3636
| 27 | Set-DbaAgentJobOutputFile | PENDING | | | | | ShouldProcess required, depends on Get-DbaAgentJobOutputFile |
3737
| 28 | Set-DbaAgentJobOwner | PENDING | | | | | ShouldProcess required |
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
using System;
2+
using System.Management.Automation;
3+
using Microsoft.VisualStudio.TestTools.UnitTesting;
4+
using Dataplat.Dbatools.Commands;
5+
6+
namespace Dataplat.Dbatools.Tests.Commands
7+
{
8+
[TestClass]
9+
public class SetDbaAgentJobCommandTests
10+
{
11+
#region ConvertCompletionLevel
12+
13+
[TestMethod]
14+
public void ConvertCompletionLevel_IntValue_ReturnsAsIs()
15+
{
16+
Assert.AreEqual(0, SetDbaAgentJobCommand.ConvertCompletionLevel(0));
17+
Assert.AreEqual(1, SetDbaAgentJobCommand.ConvertCompletionLevel(1));
18+
Assert.AreEqual(2, SetDbaAgentJobCommand.ConvertCompletionLevel(2));
19+
Assert.AreEqual(3, SetDbaAgentJobCommand.ConvertCompletionLevel(3));
20+
}
21+
22+
[TestMethod]
23+
public void ConvertCompletionLevel_StringName_ReturnsCorrectInt()
24+
{
25+
Assert.AreEqual(0, SetDbaAgentJobCommand.ConvertCompletionLevel("Never"));
26+
Assert.AreEqual(1, SetDbaAgentJobCommand.ConvertCompletionLevel("OnSuccess"));
27+
Assert.AreEqual(2, SetDbaAgentJobCommand.ConvertCompletionLevel("OnFailure"));
28+
Assert.AreEqual(3, SetDbaAgentJobCommand.ConvertCompletionLevel("Always"));
29+
}
30+
31+
[TestMethod]
32+
public void ConvertCompletionLevel_NumericString_ReturnsCorrectInt()
33+
{
34+
Assert.AreEqual(0, SetDbaAgentJobCommand.ConvertCompletionLevel("0"));
35+
Assert.AreEqual(1, SetDbaAgentJobCommand.ConvertCompletionLevel("1"));
36+
Assert.AreEqual(2, SetDbaAgentJobCommand.ConvertCompletionLevel("2"));
37+
Assert.AreEqual(3, SetDbaAgentJobCommand.ConvertCompletionLevel("3"));
38+
}
39+
40+
[TestMethod]
41+
public void ConvertCompletionLevel_Null_ReturnsZero()
42+
{
43+
Assert.AreEqual(0, SetDbaAgentJobCommand.ConvertCompletionLevel(null));
44+
}
45+
46+
[TestMethod]
47+
public void ConvertCompletionLevel_UnknownString_ReturnsZero()
48+
{
49+
Assert.AreEqual(0, SetDbaAgentJobCommand.ConvertCompletionLevel("Invalid"));
50+
}
51+
52+
#endregion ConvertCompletionLevel
53+
54+
#region GetJobName
55+
56+
[TestMethod]
57+
public void GetJobName_WithNameProperty_ReturnsName()
58+
{
59+
PSObject obj = new PSObject();
60+
obj.Properties.Add(new PSNoteProperty("Name", "TestJob1"));
61+
Assert.AreEqual("TestJob1", SetDbaAgentJobCommand.GetJobName(obj));
62+
}
63+
64+
[TestMethod]
65+
public void GetJobName_Null_ReturnsNull()
66+
{
67+
Assert.IsNull(SetDbaAgentJobCommand.GetJobName(null));
68+
}
69+
70+
[TestMethod]
71+
public void GetJobName_NoNameProperty_ReturnsNull()
72+
{
73+
PSObject obj = new PSObject();
74+
obj.Properties.Add(new PSNoteProperty("Title", "Something"));
75+
Assert.IsNull(SetDbaAgentJobCommand.GetJobName(obj));
76+
}
77+
78+
#endregion GetJobName
79+
80+
#region GetJobPropertyString
81+
82+
[TestMethod]
83+
public void GetJobPropertyString_ExistingProperty_ReturnsValue()
84+
{
85+
PSObject obj = new PSObject();
86+
obj.Properties.Add(new PSNoteProperty("OperatorToEmail", "DBATeam"));
87+
Assert.AreEqual("DBATeam", SetDbaAgentJobCommand.GetJobPropertyString(obj, "OperatorToEmail"));
88+
}
89+
90+
[TestMethod]
91+
public void GetJobPropertyString_MissingProperty_ReturnsNull()
92+
{
93+
PSObject obj = new PSObject();
94+
Assert.IsNull(SetDbaAgentJobCommand.GetJobPropertyString(obj, "NonExistent"));
95+
}
96+
97+
[TestMethod]
98+
public void GetJobPropertyString_NullObject_ReturnsNull()
99+
{
100+
Assert.IsNull(SetDbaAgentJobCommand.GetJobPropertyString(null, "Name"));
101+
}
102+
103+
[TestMethod]
104+
public void GetJobPropertyString_NullValue_ReturnsNull()
105+
{
106+
PSObject obj = new PSObject();
107+
obj.Properties.Add(new PSNoteProperty("OperatorToEmail", null));
108+
Assert.IsNull(SetDbaAgentJobCommand.GetJobPropertyString(obj, "OperatorToEmail"));
109+
}
110+
111+
#endregion GetJobPropertyString
112+
}
113+
}

0 commit comments

Comments
 (0)