Skip to content

Commit 490c7cf

Browse files
committed
Add tests for parameter retrieval and simplify assertions
Introduced a new test method `GetParameterNegativeTest` in `GetParameterTests.cs` to verify the correct retrieval of parameter values across different scopes with encryption, utilizing a data-driven approach. Modified the `RegisterApplicationEncryptedParameterTest` in `RegisterParameterTests.cs` to simplify assertion logic by directly comparing the decrypted value of the parameter against the expected value "Bar Foo", removing unnecessary Base64 encoding checks.
1 parent 8b8f399 commit 490c7cf

2 files changed

Lines changed: 40 additions & 5 deletions

File tree

src/G4.UnitTests/Plugins.Common.Macros/GetParameterTests.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,43 @@ public void GetParameterPositiveTest(string scope)
7777
// Assert that the actual value (Base64 encoded) matches the expected value.
7878
Assert.AreEqual(expected: "Rm9vIEJhcg==", actual);
7979
}
80+
81+
[TestMethod(displayName: "Verify that the GetParameter plugin retrieves the correct " +
82+
"parameter value for different scopes with encryption.")]
83+
#region *** Data Set ***
84+
[DataRow("Session")]
85+
[DataRow("Application")]
86+
[DataRow("Process")]
87+
[DataRow("Machine")]
88+
[DataRow("User")]
89+
#endregion
90+
public void GetParameterNegativeTest(string scope)
91+
{
92+
// Define the rules for registering and retrieving the parameter.
93+
var rules = new[]
94+
{
95+
// Rule for registering the parameter with the specified scope.
96+
new ActionRuleModel
97+
{
98+
PluginName = "RegisterParameter",
99+
Argument = "{{$ --Name:MyParam --Value:Foo Bar --Scope:" + scope + " --EncryptionKey:g4}}",
100+
},
101+
// Rule for retrieving the parameter with the specified scope.
102+
new ActionRuleModel
103+
{
104+
PluginName = "RegisterParameter",
105+
Argument = "{{$ --Name:MyDecryptedParam --Value:{{$Get-Parameter --Name:MyParam --Scope:" + scope + " --EncryptionKey:g4}} --Scope:" + scope + "}}"
106+
}
107+
};
108+
109+
// Invoke the action rules and get the response.
110+
var response = Invoke(rules);
111+
112+
// Retrieve the actual value of the parameter from the response.
113+
var actual = response.GetParameterValue(parameterName: "MyDecryptedParam", scope);
114+
115+
// Assert that the actual value (Base64 encoded) matches the expected value.
116+
Assert.AreEqual(expected: "Rm9vIEJhcg==", actual);
117+
}
80118
}
81119
}

src/G4.UnitTests/Plugins.Common/RegisterParameterTests.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void RegisterApplicationParameterTest()
7575
Assert.IsTrue("Bar Foo".Equals(actual.ConvertFromBase64(), Comparison));
7676
}
7777

78-
[TestMethod(displayName: "Verify that the application parameter is registered " +
78+
[TestMethod(displayName: "Verify that the encrypted application parameter is registered " +
7979
"correctly with a specific environment name.")]
8080
public void RegisterApplicationEncryptedParameterTest()
8181
{
@@ -100,11 +100,8 @@ public void RegisterApplicationEncryptedParameterTest()
100100
parameterName: "MyParam",
101101
scope: "Application");
102102

103-
// Assert that the actual value (Base64 encoded) matches the expected value (Base64 encoded).
104-
Assert.IsTrue(actual.Equals("Bar Foo".Decrypt("g4").ConvertToBase64(), Comparison));
105-
106103
// Assert that the expected value matches the actual value (decoded from Base64).
107-
Assert.IsTrue("Bar Foo".Equals(actual.ConvertFromBase64(), Comparison));
104+
Assert.IsTrue("Bar Foo".Equals(actual.ConvertFromBase64().Decrypt("g4"), Comparison));
108105
}
109106

110107
[TestMethod(displayName: "Verify that the machine parameter is registered correctly.")]

0 commit comments

Comments
 (0)