PowerShell quickie – function to make your Mocks faster


In C#, writing unit tests is king, and Moq is the hotness we use to Mock objects and methods, like the MockObjects we get with Pester in PowerShell.

But one rough part of it is the syntax for Moq, which requires you to write a handler and specify each input argument, which can get pretty verbose and tiresome.

To ease this up, try this function, which will take a method signature and convert it into a sample Mock.Setup or Mock.Verify block, ready for testing

<#
.Synopsis
Creates your Moq.Setups for you!
.DESCRIPTION
Provide a method signature to receive an example of a basic, lazy Mock for the method
.EXAMPLE
$myMethodSignature = "
GetDeploymentStatus(
string someToken,
int someIntValue = 10,
bool someBoolValue = false,
TimeSpan delayLookup = default,
CancellationToken cancellationToken
)"
New-MoqMethodConfiguration $myMethodSignature
.Setup(m=>m.
GetDeploymentStatus(It.IsAny<string>(),It.IsAny<int>(),It.IsAny<bool>(),It.IsAny<TimeSpan>(),It.IsAny<CancellationToken>())).Returns…
.EXAMPLE
Another example of how to use this cmdlet
#>
Function New-MoqMethodConfiguration{
[CmdletBinding()]
param(
[String]
$methodSignature,
[Switch]
$Verify = $false
)
$outputs = New-Object System.Collections.ArrayList
$methodName = $methodSignature.Split('(')[0]
Write-Verbose "found method of name $methodName"
$parms= $methodSignature.Split('(')[1..10].Split("`n").Trim().Replace(')','')
Write-Verbose "found $($parms.Count) parameters"
ForEach($parm in $parms){
if($parm.Length -le 0){continue}
Write-Verbose "processing $parm "
$outputs.Add("It.IsAny<$($parm.Split()[0])>()") | Out-Null
}
$paramMatcher = $outputs -join ","
if ($Verify){
Write-output ".Verify(m=>m.$($methodName)($paramMatcher), Times.Once)"
}
else{
Write-output ".Setup(m=>m.$($methodName)($paramMatcher)).Returns…"
}
}

DIY Microsoft Teams On-Air Light!

Children. You love them. They in turn, run into your meetings all the time. Sometimes wearing pants.

Wouldn’t it be great to have a way to keep them informed of when Daddy or Mommy is in a meeting? Something nice and big and obvious that they can just totally ignore, right?

That’s why I sought to design my own perfect on-air light, to automatically turn on when I joined Teams Meetings.  Won’t you join me in this journey together, and you can build your own?

Banner graphic, says 'How-To guide, On-air light' and depicts a light with red letters that say 'ON-AIR', illuminated and hanging above a door frame

Why make one?

Great question, and if either of these describe you, you can probably just stop and buy one of the off the shelf products that answer this need.

  • I don’t have a closed door I can work behind.
  • It would be ok to just have something for my desk
  • I enjoy inflicting my children upon others

But if you do want to make your own…read on!

Continue reading

Joining Microsoft

Picture of the author in front of the Microsoft Logo sign in Redmond Washington on the microsoft campus

I have really loved these last three years with #BigBank #SpoilersItWasWellsFargoAllAlong and made some great friends and had some awesome experiences creating and sharing sessions at MMS with my friends I made along the way.

My career for the last ten years has been focused on automating, deploying, and managing Microsoft technologies. And now now, I’m going to get a chance to help work on them as well!

Starting May 18th, I am happily joining Microsoft’s Azure Compute team as a Developer. I’ll be remaining in Atlanta, and working from home for the foreseeable future.

What to Expect

This blog has always been a place for me to show you how I do it and I will continue to do the same thing, with my own same flavor and perspective. All thoughts and perspectives will be my own and will not be my employers.

I’ll update this blog in the coming weeks when I have tips to share about what I’ve been working on, or as post ideas strike me!

Progressive Automation Pt II – PowerShell GUIs

In our previous post in the series, we took a manual task and converted it into a script, but our users could only interface with it by ugly manual manipulation of a spreadsheet. And, while I think sheetOps (configuring and managing a Kubernetes cluster with a GoogleSheets doc!) are pretty cool we can probably do better.

So in this post, I’ll show how I would typically go about building a PowerShell WPF GUI from an existing automation that kind of works OK.

Continue reading

Quick Guide – Setting up Remote Management of your child’s PC

MANAGING YOUR

With everyone working remote now, it’s really helpful to have a method to remote control your kid’s computers, especially if they are hard to keep on task like mine.

So I wrote this short guide to help you get a handle. This guide expects you to have two computers, one for you, one for your kids to use.

Whoa I need a computer for the kids?

This guide is only going to cover PCs, not tablets.  Sorry.

If you need to buy one, this is what I’m now recommending.  Walmart has a new in-store brand of computers which is surprisingly great for the money, called their Motile line. It can do light to moderate gaming like Minecraft and Fortnite, and also handle video editing if you’ve got a budding YouTuber, as well as programming. And the best point? It’s user upgradable so you can add more RAM or get a bigger hard drive down the road.

walmartMotile

Motile 14″ AMD Laptop with Radeon 3 Graphics, 128 GB SSD and 4GB RAM

Linus Tech Tips did a great and funny video on this laptop too if you’re interested. 

/\ The above are not my affiliate links.

Note: a word about Remote Management

This method will setup Remote Viewing and control of your child’s computer

It is imperative that you treat your children with maturity, allow them breaks and make sure they know you can remote into their PC.

You don’t want to be stuck at home with kids who feel you’ve abused their trust by spying on them.  Only use these powers for good.

If you disagree with this, I don’t care so please keep that perspective to yourself. Continue reading