Skip to content

Commit 19ad8a8

Browse files
feat(migration): Convert Get-DbaAgentServer to C# binary cmdlet
- All parameters preserved (SqlInstance, SqlCredential, EnableException) - All code paths implemented including JobServer retrieval - JobHistoryIsEnabled implemented as live PSScriptProperty (matches PS1 behavior) - ComputerName, InstanceName, SqlInstance NoteProperties preserved - DefaultDisplayPropertySet with all 28 properties - Build passes on both net472 and net8.0 - C# unit tests written and passing (14 tests) - Pester integration tests pass (2/2, fixed pre-existing failure) - Feature parity verified - PS1 retired, cmdlet exported from dbatools.library Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5a775d4 commit 19ad8a8

4 files changed

Lines changed: 406 additions & 1 deletion

File tree

dbatools.library.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
'Get-DbaAgentOperator',
7070
'Get-DbaAgentProxy',
7171
'Get-DbaAgentSchedule',
72+
'Get-DbaAgentServer',
7273
'Get-DbaAgHadr',
7374
'Get-DbaAgListener',
7475
'Get-DbaAgReplica',

docs/plan/TRACKER-MIGRATE-AGENT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
| 9 | Get-DbaAgentOperator | DONE | GetDbaAgentOperatorCommand.cs | OK | 100% | 3/3 pass (fixed pre-existing 2 failures) | Read-only, no deps |
1919
| 10 | Get-DbaAgentProxy | DONE | GetDbaAgentProxyCommand.cs | OK | 100% | 1/1 pass (9 pre-existing failures) | Read-only, no deps |
2020
| 11 | Get-DbaAgentSchedule | DONE | GetDbaAgentScheduleCommand.cs | OK | 100% | 1/1 pass (10 pre-existing failures in BeforeAll) | Read-only, no deps |
21-
| 12 | Get-DbaAgentServer | PENDING | | | | | Read-only, no deps |
21+
| 12 | Get-DbaAgentServer | DONE | GetDbaAgentServerCommand.cs | OK | 100% | 2/2 pass (fixed pre-existing 1 failure) | Read-only, no deps |
2222
| 13 | Get-DbaRunningJob | PENDING | | | | | Read-only, no deps |
2323
| 14 | Test-DbaAgentJobOwner | PENDING | | | | | |
2424
| 15 | Find-DbaAgentJob | PENDING | | | | | |
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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 GetDbaAgentServerCommandTests
10+
{
11+
#region AddScriptProperty
12+
[TestMethod]
13+
public void AddScriptProperty_AddsPropertyToObject()
14+
{
15+
PSObject obj = new PSObject();
16+
obj.Properties.Add(new PSNoteProperty("MaximumHistoryRows", 1000));
17+
18+
GetDbaAgentServerCommand.AddScriptProperty(obj, "TestProp", "$true");
19+
20+
PSPropertyInfo prop = obj.Properties["TestProp"];
21+
Assert.IsNotNull(prop);
22+
Assert.IsTrue(prop is PSScriptProperty);
23+
}
24+
25+
[TestMethod]
26+
public void AddScriptProperty_NullObjectDoesNotThrow()
27+
{
28+
GetDbaAgentServerCommand.AddScriptProperty(null, "TestProp", "$true");
29+
}
30+
31+
[TestMethod]
32+
public void AddScriptProperty_ReplacesExistingProperty()
33+
{
34+
PSObject obj = new PSObject();
35+
obj.Properties.Add(new PSNoteProperty("TestProp", "oldvalue"));
36+
37+
GetDbaAgentServerCommand.AddScriptProperty(obj, "TestProp", "$true");
38+
39+
PSPropertyInfo prop = obj.Properties["TestProp"];
40+
Assert.IsNotNull(prop);
41+
Assert.IsTrue(prop is PSScriptProperty);
42+
}
43+
#endregion
44+
45+
#region AddOrSetProperty
46+
[TestMethod]
47+
public void AddOrSetProperty_AddsNewProperty()
48+
{
49+
PSObject obj = new PSObject();
50+
GetDbaAgentServerCommand.AddOrSetProperty(obj, "ComputerName", "sql01");
51+
52+
Assert.AreEqual("sql01", obj.Properties["ComputerName"].Value);
53+
}
54+
55+
[TestMethod]
56+
public void AddOrSetProperty_UpdatesExistingProperty()
57+
{
58+
PSObject obj = new PSObject();
59+
obj.Properties.Add(new PSNoteProperty("ComputerName", "old"));
60+
61+
GetDbaAgentServerCommand.AddOrSetProperty(obj, "ComputerName", "new");
62+
63+
Assert.AreEqual("new", obj.Properties["ComputerName"].Value);
64+
}
65+
66+
[TestMethod]
67+
public void AddOrSetProperty_NullObjectDoesNotThrow()
68+
{
69+
GetDbaAgentServerCommand.AddOrSetProperty(null, "Name", "value");
70+
}
71+
72+
[TestMethod]
73+
public void AddOrSetProperty_SetsNullValue()
74+
{
75+
PSObject obj = new PSObject();
76+
GetDbaAgentServerCommand.AddOrSetProperty(obj, "Prop", null);
77+
78+
Assert.IsNull(obj.Properties["Prop"].Value);
79+
}
80+
#endregion
81+
82+
#region SetDefaultDisplayPropertySet
83+
[TestMethod]
84+
public void SetDefaultDisplayPropertySet_AddsStandardMembers()
85+
{
86+
PSObject obj = new PSObject();
87+
obj.Properties.Add(new PSNoteProperty("Name", "Test"));
88+
obj.Properties.Add(new PSNoteProperty("ID", 1));
89+
90+
string[] props = new string[] { "Name", "ID" };
91+
GetDbaAgentServerCommand.SetDefaultDisplayPropertySet(obj, props);
92+
93+
PSMemberInfo member = obj.Members["PSStandardMembers"];
94+
Assert.IsNotNull(member);
95+
}
96+
97+
[TestMethod]
98+
public void SetDefaultDisplayPropertySet_NullObjectDoesNotThrow()
99+
{
100+
GetDbaAgentServerCommand.SetDefaultDisplayPropertySet(null, new string[] { "Name" });
101+
}
102+
103+
[TestMethod]
104+
public void SetDefaultDisplayPropertySet_NullPropertiesDoesNotThrow()
105+
{
106+
PSObject obj = new PSObject();
107+
GetDbaAgentServerCommand.SetDefaultDisplayPropertySet(obj, null);
108+
}
109+
#endregion
110+
111+
#region GetServerPropertySafe
112+
[TestMethod]
113+
public void GetServerPropertySafe_ReturnsPropertyValue()
114+
{
115+
PSObject obj = new PSObject();
116+
obj.Properties.Add(new PSNoteProperty("ComputerName", "sql01"));
117+
118+
string result = GetDbaAgentServerCommand.GetServerPropertySafe(obj, "ComputerName");
119+
120+
Assert.AreEqual("sql01", result);
121+
}
122+
123+
[TestMethod]
124+
public void GetServerPropertySafe_NullObjectReturnsNull()
125+
{
126+
string result = GetDbaAgentServerCommand.GetServerPropertySafe(null, "ComputerName");
127+
Assert.IsNull(result);
128+
}
129+
130+
[TestMethod]
131+
public void GetServerPropertySafe_MissingPropertyReturnsNull()
132+
{
133+
PSObject obj = new PSObject();
134+
obj.Properties.Add(new PSNoteProperty("Name", "sql01"));
135+
136+
string result = GetDbaAgentServerCommand.GetServerPropertySafe(obj, "ComputerName");
137+
Assert.IsNull(result);
138+
}
139+
140+
[TestMethod]
141+
public void GetServerPropertySafe_NullValueReturnsNull()
142+
{
143+
PSObject obj = new PSObject();
144+
obj.Properties.Add(new PSNoteProperty("Edition", null));
145+
146+
string result = GetDbaAgentServerCommand.GetServerPropertySafe(obj, "Edition");
147+
Assert.IsNull(result);
148+
}
149+
#endregion
150+
}
151+
}

0 commit comments

Comments
 (0)