-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
38 getdeviceproperties need setpropertyvalue method has an array over…
…load (#40) Changes WmiMethodParameters class to work with string arrays and WmiObjects.
- Loading branch information
1 parent
8ff653b
commit b00d4ed
Showing
13 changed files
with
206 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
namespace WmiLight.UnitTests | ||
{ | ||
[TestClass] | ||
public class Win32_PnPEntity | ||
{ | ||
[TestMethod] | ||
public void Win32_PnPEntity_GetDeviceProperties_Can_Be_Called_With_String_Array_Parameter() | ||
{ | ||
using (WmiConnection conncetion = new WmiConnection()) | ||
{ | ||
using (WmiMethod method = conncetion.GetMethod("Win32_PnPEntity", "GetDeviceProperties")) | ||
{ | ||
foreach (WmiObject pnpEntity in conncetion.CreateQuery("SELECT * FROM Win32_PnPEntity")) | ||
{ | ||
uint result = pnpEntity.ExecuteMethod<uint>(method, out WmiMethodParameters outParameters); | ||
|
||
Assert.AreEqual(0u, outParameters.GetPropertyValue<uint>("ReturnValue")); | ||
Assert.AreEqual(result, outParameters.GetPropertyValue<uint>("ReturnValue")); | ||
|
||
WmiObject[] allDeviceProperties = outParameters.GetPropertyValue<WmiObject[]>("deviceProperties"); | ||
|
||
if (allDeviceProperties.Length > 2) | ||
{ | ||
WmiMethodParameters inParameters = method.CreateInParameters(); | ||
|
||
inParameters.SetPropertyValue("devicePropertyKeys", allDeviceProperties.Take(2).Select(x => x.GetPropertyValue<string>("KeyName")).ToArray()); | ||
|
||
result = pnpEntity.ExecuteMethod<uint>(method, inParameters, out outParameters); | ||
|
||
Assert.AreEqual(0u, outParameters.GetPropertyValue<uint>("ReturnValue")); | ||
Assert.AreEqual(result, outParameters.GetPropertyValue<uint>("ReturnValue")); | ||
|
||
WmiObject[] requestedDeviceProperties = outParameters.GetPropertyValue<WmiObject[]>("deviceProperties"); | ||
|
||
// 2 properties expected | ||
Assert.AreEqual(2, requestedDeviceProperties.Length); | ||
|
||
return; | ||
} | ||
} | ||
|
||
// if no matching Win32_PnPEntity found | ||
Assert.Inconclusive(); | ||
} | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public void Win32_PnPEntity_GetDeviceProperties_Can_Be_Called_Null_Parameter() | ||
{ | ||
using (WmiConnection conncetion = new WmiConnection()) | ||
{ | ||
using (WmiMethod method = conncetion.GetMethod("Win32_PnPEntity", "GetDeviceProperties")) | ||
{ | ||
foreach (WmiObject pnpEntity in conncetion.CreateQuery("SELECT * FROM Win32_PnPEntity")) | ||
{ | ||
WmiMethodParameters inParameters = method.CreateInParameters(); | ||
|
||
inParameters.SetPropertyValue("devicePropertyKeys", null as string[]); | ||
|
||
uint result = pnpEntity.ExecuteMethod<uint>(method, inParameters, out WmiMethodParameters outParameters); | ||
|
||
Assert.AreEqual(0u, outParameters.GetPropertyValue<uint>("ReturnValue")); | ||
Assert.AreEqual(result, outParameters.GetPropertyValue<uint>("ReturnValue")); | ||
|
||
WmiObject[] allDeviceProperties = outParameters.GetPropertyValue<WmiObject[]>("deviceProperties"); | ||
|
||
Assert.IsTrue(allDeviceProperties.Length > 0); | ||
|
||
// Test done! | ||
return; | ||
} | ||
|
||
// if no matching Win32_PnPEntity found | ||
Assert.Inconclusive(); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.