Skip to content

Instantly share code, notes, and snippets.

@nohwnd
Created May 20, 2016 13:25
Show Gist options
  • Save nohwnd/c8e72858905c70f2558bfb1eefb403a9 to your computer and use it in GitHub Desktop.
Save nohwnd/c8e72858905c70f2558bfb1eefb403a9 to your computer and use it in GitHub Desktop.
Faking call to external static method in Pester
add-type -TypeDefinition @"
using System;
public static class KeyboardEventTestUtil {
public static string keybd_event(byte bVk, byte bScan, UInt32 dwFlags, System.UIntPtr dwExtraInfo) {
return string.Format("{0}:{1}:{2}:{3}", bVk,bScan,dwFlags,dwExtraInfo);
}
}
"@
describe "t" {
it "b" {
[KeyboardEventTestUtil]::keybd_event(1,1,1,[UIntPtr]::Zero) | should be "1:1:1:0"
}
}
@nohwnd
Copy link
Author

nohwnd commented May 20, 2016

You can get the signature of the method by importing it from the user32.dll and calling it without () and then modifying it a bit to make it compatible with C#. Also the original is void our method returns string, so we can assert.

Linkback: https://twitter.com/Bjompen/status/733638792347717636

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment