Both concepts and practices for doing unit testing in Go, drawing from a wide range of sources. This is the written counterpart of the talk I gave at Go Northwest in August, 2018!
Practical Unit Tests (and TDD!) in PowerShell (November 5, 2014)
By the time you're using PowerShell to automate an increasing amount of the system administration, database maintenance, or application-lifecycle work, you'll probably need to automate the unit-testing of the PowerShell scripts themselves. This series introduces you to Pester, the leading test framework for PowerShell, and provides "tips from the trenches" on using it most effectively for unit tests (with a gentle prodding towards a TDD style).
Part 1: Getting Started with the Pester Framework Part 2: Mock Objects and Parameterized Test Cases Part 3: Validating Data and Call History
This article presents a wallchart (in two versions) that is a cookbook;
It includes an extensive recipe list for--and cross-reference between--XPath, CSS, and DOM, with attention for any Selenium considerations (since Selenium uses all three technologies). It is a useful reference for any of the separate technologies on its own merits, though!
Selenium is a powerful, flexible, yet easy-to-use web testing platform. This article illustrates how to stretch Selenium's boundaries with my open-source extension Selenium Sushi, providing both a support library and a .NET project framework, to make Selenium more useful and make you more productive. It lets you, among other things: retarget different browsers and different application servers without recompiling, handle file URLs automatically and, most importantly, convert a standard code file emitted by the IDE into a substantially smaller piece of source code.
Subtitled You"ve Been Doing Source Control Wrong... and How to Fix It,
this series discusses how you need to source control both your code and your database,
and how to do it in SQL Server Management Studio (with SQL Source Control),
Visual Studio (with SQL Connect and AnkhSVN), and your file system (with TortoiseSVN).
Part 1: Getting Started, October 9, 2012
Part 2: The Essential Operations, October 9, 2012
Part 3: The Unified Solution, October 9, 2012
Wallchart reference
PowerShell has a little known technique wherein you can provide defaults to cmdlets you use everyday--even system cmdlets. So you can do things like: always want to show help ina popup when you use Get-Help; always use -Confirm on cmdlets that accept it; specify a certain path parameter when you remote to a certain machine, etc.
Writing Cmdlets
PowerShell cmdlets can be written in PowerShell, of course, but sometimes needs dictate that you write them in C#. With just a bit of adjustment to your development perspective, it is rather straightforward to do that, particularly with this step-by-step guide.
Part 1: The Basics , February 19, 2016, shows how to get a working cmdlet written in C# in just 15 easy steps.
Part 2: Beyond the Basics, July 22, 2016, takes you to the next level, adding 5 more steps that provides some spit and polish to your cmdlets.
The PowerShell profile gives you a mechanism to configure your PowerShell environment with modules, functions, aliases, and variables upon startup so that by the time you get your first prompt, everything you use regularly is already loaded for you. The complication is that there is not just a single profile, but actually 4. No wait, 6. Well, possibly more than that...
Documenting PowerShell
A PowerShell master should know how to generate content for Get-Help from cmdlets written in PowerShell and cmdlets written in C#,
along with generating a web-based version of your module's complete API. The latest installment in this series shows the unified solution in a one-page wallchart.
Part 1: How To Document Your PowerShell Library, June 25, 2013, shows how to document a whole PowerShell library with the open-source DocTreeGenerator.
Part 2: Documenting Your PowerShell Binary Cmdlets, December 3, 2015,
explains how to document binary or compiled cmdlets--those written in C#--as easily as those written in PowerShell. This article introduces XmlDoc2CmdletDoc, an open-source utility that fills the much-needed gap.
Part 3: Unified Approach to Generating Documentation for PowerShell Cmdlets, April 22, 2016, brings together all the necessary components in a one-page wallchart/infographic.
Pipelining is an important technique for conserving memory, improving actual performance, and enhancing perceived performance. While PowerShell provides an ample supply of constructs for pipelining, it is all too easy to write code that simply does not pipeline at all.
PowerShell seems to have more than its fair share of geekiness when it comes to its lexicon of punctuation. What does $_ mean, or % {...} or @{...} or [...]::... etc.? I've gathered together all the symbols and punctuation into a convenient wallchart to make navigating the PowerShell universe easier.
Figure out your PowerShell recipe to emit a data table of anything you like (a list of files or processes, actual DB data, whatever) and feed that to MonitorFactory to generate a near-real-time monitor of your resource.
As simple as it sounds, the "how, when, and why" of using quotes in PowerShell--and what type of quotes to use--is not very well-known. Find out everything you need to know.
A Plethora of PowerShell Pitfalls
PowerShell can provide a tremendous boost in productivity for administrative-type tasks. However, as with any complex technology there are a variety of ways-some a lot more obvious than others-that you can cause problems for yourself without even realizing it.
Test your PowerShell wits with this quiz on common PowerShell practices that can sneak up on you and yield unexpected results.
Part 1: Pesky Parameter Problems, April 2, 2015
Part 2: A Portion of Potential Puzzles, May 12, 2015
Part 3: The WallChart, June 25, 2015, which brings together pitfalls from the above with those from a wide array of other sources so you have the best of the worst all in one place.
It's all about the data.
This series shows you how to work with line-oriented data (by line, by index, by filter), field-oriented data (fixed width, ragged right, variable width), string data (hash tables, property lists, ini files, json), excel data, and XML data (with either XPath or object accessors).
Part 1: File-Based Data, December 2, 2013
Part 2: XML, January 3, 2014
Practical PowerShell for SQL Server Developers and DBAs
This series gives you a running start at setting up and using PowerShell,
showing how easy it is to run queries with the sqlcmd equivalent in PowerShell
and how to navigate in "SQL Server space" just like you can in "file system space".
Part 1: Configuration and Queries, July 23, 2012
Part 2: Navigating and Working in SQL Server Space, August 15, 2012
Modules allow you to use standard libraries that extend PowerShell's functionality. They are easier to use than to create, but if you get the hang of creating them, your code will be more easily-maintained and re-usable.
For an experienced programmer to learn a new language can be a journey quite like Alice's in wonderland. Paradoxes, unexpected twists, blind tangents, bafflements and nice surprises. This examination of practices and pitfalls of functions yields some fascinating results.
When you are first learning PowerShell, it often seems to be an 'Alice through the looking-glass' world. Just the simple process of comparing and selecting strings can seem strangely obtuse. This handy wallchart illuminates everything you need to know.
Database
The Manual That Time Forgot
A primer on Red Gate's new foray into the MySql space, mirroring their outstanding products from SQL Server and Oracle:
I literally wrote the book on SqlDiffFramework--plus the application itself! This 150+ page user guide for SqlDiffFramework reveals everything you need to know to get the most out of comparing dissimilar data sources including SQL Server, Oracle, MySql, and any ODBC data source (e.g. Access, Excel, CSV, etc.).
By adding XML-based documentation capability to your SQL code, you can automatically extract tagged comments and format them into truly useful documentation.
Unlike other SQL documentation generators that document the schema and structure of a database,
this article discusses a tool to generate a true API for the procedures and functions in your database.
A Visual Lexicon of LINQ, http://www.simple-talk.com, April 25, 2017
This 3-part series brings illumination to the mysteries of LINQ in a highly digestible, easy-to-use set of reference material.
The main article enumerates every LINQ operator with not just a description but a visualization making it easy to grasp how the operator works.
The one-page wallchart dives deeper, providing the properties of every operator in a condensed table, identifying query or lambda syntax, where in a chain the operator may be placed, laziness (and not just deferred or immediate execution, but also to what degree of lazy!), time and space complexity, and a handful of optional properties.
Finally, for Powershell users, High Performance PowerShell with LINQ reveals the secret incantations necessary to use all the power of LINQ in your PowerShell code.
LINQ Debugging
LINQ has the capabilities of providing a great productivity boost. LINQ Chaining is particularly powerful magic, giving your code greater clarity and brevity. Using it, and debugging it, can be tricky without the right tools and techniques. This turned out to be a two-part series:
Part 1: LINQ Secrets Revealed: Chaining and Debugging, http://www.simple-talk.com, December 1, 2010
In this first part I talk about the standalone LINQPad utility, with its amazing Dump method, plus several techniques to use within Visual Studio, including a similar Dump method, and even using LINQPad's data visualization capability inside of Visual Studio.
Part 2: LINQ Debugging and Visualization, http://www.simple-talk.com, December 1, 2016
Part 2 finally reveals--exactly six years later!!--the new OzCode feature to truly visualize and debug LINQ effectively.
LINQ has the capabilities of providing a great productivity boost. LINQ Chaining is particularly powerful magic, giving your code greater clarity and brevity. Using it, and debugging it, can be tricky without the right tools and techniques. In this article I talk about the standalone LINQPad utility, with its amazing Dump method, plus several techniques to use within Visual Studio, including a similar Dump method, and even using LINQPad's data visualization capability inside of Visual Studio.
The traditional means for making a generic component that is customizable is the callback method. With LINQ one can do the same thing with just a bit more panache. I like to present my ideas grounded in specific, practical applications: in this case, I chose a file masking user control, allowing a user to filter a list of files from a directory by specifying one--or more--file masks and displaying a dynamic list of matching files.
I then add on top of that a thorough discussion--with sample projects!--for injecting additional, arbitrary constraints in the form of LINQ lambda expressions.
This article takes a fairly simple technique involving both LINQ-to-Objects and extension methods (both new concepts in C# 3.0) and uses it as the heart of two moderate complexity components that could themselves be immediately incorporated as building blocks in a production application. What is interesting is that the two components are quite different on the surface: one involves managing an application's external (file) resources; the other involves initializing choices in a context menu upon a right-click to open the menu. I present a thorough discussion of the LINQ and extension methods that comprise the key portions of the code.
One of the earliest-but still important-tenets of software engineering is the concept of reuse with "software building blocks". In the .NET framework, user controls are the quintessential building blocks, giving you a simple yet powerful way to encapsulate a set of visual components into a more complex one. This holds true both in the WinForms realm and the WPF realm.
What is not well known, nor particularly obvious, is that you can build hybrids, embedding WPF controls in a WinForms application or WinForms controls in a WPF application, using simple adapters. And you can do this either with your custom user controls, or with the set of the full set of .NET controls if the "other" technology has a control you need.
Typical prototypes take too long, cost too much, or achieve too little (or some combination of those). Think back to when you were designing and writing code before Visual Studio. And then, one day, you discovered the capabilities that Visual Studio provides. You could create WinForm applications by dragging and dropping controls from a toolbox and editing their properties! You could create and connect data sources; develop class diagrams; etc. Visual Studio was an earthshaking paradigm shift in design and development.
With the advent of SketchFlow the landscape for creating prototypes has changed. SketchFlow is new, not very well known, not even a standalone product. But it is earthshaking in a similar way.
WPF is simultaneously enticing and intimidating. It offers potential for amazing flexibility in UI design but there is a mountain of learning to climb. In this article I present a collection of little known but useful utility applications that can assist you as you learn and develop WPF code.
A collection of lesser known VS extensions to assist editing, documentation, and more.
Taming Sandcastle: A .NET Programmer's Guide to Documenting Your Code
The most effective way to document .NET code so that others can understand and use it is with XML Documentation and SandCastle. But the documentation for creating documentation is--quite ironically--hard to come by! This article and wallchart is a guide to the process and the pitfalls.
Taming Sandcastle article, September 13, 2010
Wallchart on Sandcastle Help File Builder, October 11, 2010
Taking XML Validation to the Next Level: Content Assembly Mechanism (CAM)
Use this XmlTransform application to generate sets of HTML pages, SQL documentation, or apply it to your own particular needs.
XmlTransform is a general-purpose XML transformer and validator that operates on an arbitrarily deep directory tree containing files you want to transform, optionally generating multi-level indices and adding navigational linkages.
How one visualizes a concept can greatly impact how well one understands it or, perhaps more importantly, how well one may communicate the concept to others.
In this case study I focus on Ant build files and show how different perspectives on the same code allow you to absorb more information faster, reduce errors, and provide intuitive methods to help you comprehend, modify, and test build targets.
Part 1 (of 3) of my series on the QueryPicker control: No matter how good your SQL skills are, walking into a new situation with unfamiliar databases is only going to make that task trickier; and most large companies - and many small ones, too - will have a heterogeneous database environment, unless you are very fortunate. Mixtures of SQL Server and Oracle are fairly common, and every database type will have different structures and different syntax to remember. This article describes a .NET control called a QueryPicker, a cross-platform query template solution to make life easier.
Part 2 (of 3) of my series on the QueryPicker control: This article presents the technical details on how to integrate the QueryPicker into applications both simple and complex. With screenshots and code samples, this has everything you need to build your own powerful SQL editor or query template explorer.
Part 3 (of 3) of my series on the QueryPicker control: For LINQ lovers, this provides a treatment of how the QueryPicker populates its TreeView from XML using LINQ to Objects, LINQ to XML, and LINQ to XSD.
.NET Building Blocks: Custom User Controls
Part 1 delves into the nitty gritty details required to create, test, use, inherit, install, and distribute .NET User Controls of all types.
Part 2 explores the differences between the various types of custom controls, and shows how to integrate your controls into Visual Studio and make them easy to use.
Part 1: Custom User Control Fundamentals, May 15, 2008
Part 2: Custom User Controls In Practice, July 9, 2008
This handy control provides a complete solution for interactive handling of database credentials, giving you everything you need to control how users input usernames and passwords, select servers, and choose connection types.
After I created a few different proprietary applications where I had to create a custom login form for each, I decided it was time to make one generic enough to be flexible and configurable with just a few lines to set properties.
By using a SyntaxHilightTextBox control, you can build an editor for the language of your choice that highlights keywords, quoted strings, and comments. The article further shows just one example (a VBScript interpreter) of how easy it is to build an IDE leveraging this control.
This article is different: you can read it backwards or forwards. If you have seen those old books-with two books literally pasted together back to back so that if you flip it over you have a different book to read-this article is like that.
It discusses tray applications in WinForms or WPF or both, with consideration of three techniques for mutual exclusion, and presents a tray application framework that you can put to immediate use.
It also presents--as a real-world example of the framework--a utility to switch your host file servers from development to staging to production with one click, called HostSwitcher.
So you can download either source or an installer for HostSwitcher.
If you've ever been frustrated trying to figure out how to intercept or assign specific keystrokes to specific controls, you'll be glad you found this article.
It reveals not only the fundamentals about how keystroke handling is exposed in the .NET framework, but also provides a handy Keystroke Sandbox to actually observe how keystrokes flow through an application, and concludes with a "cook book" detailing how to instrument your code for all the common key handling hooks.
Diagnostics, or program tracing, is a crucial-and often overlooked and underappreciated-component of application development.
It is useful not only during program development but even more so once your application is deployed. Ongoing maintenance costs are one of the largest segments of software's true cost, and well-instrumented diagnostics can reduce maintenance costs significantly.
Find out how to use a single DataGridView to display dynamic queries, adjusting columns automatically, and how to format individual cells exactly the way you want users to see them.
Visual Studio gives developers the extraordinary capability to build a database application with a working graphical user interface using just a few mouse clicks. Populating the DataGridView requires a round-trip to the database every time the underlying query needs to be refreshed. This article discusses a technique to eliminate that round-trip, dynamically updating the underlying query of a DataGridView virtually instantaneously. The perceived performance difference is dramatic (akin to the difference between browser-embedded JavaScript updating versus page refreshing from a web server).
The MSDN documentation includes a lot of material on persisting application settings in a Windows application. But like much documentation, it's primarily a reference rather than a practical implementation guide, giving the complex and intricate usage details of settings without giving a clear and concise discussion of typical simple uses--exactly what a large number of users will be interested in. This article attempts to provide some tips on implementation.
Input validation is something that every program needs, and every programmer dreads. Most developers craft hard-coded program logic to verify that a phone number consists of 7 or 10 digits; that an IP address consists of 4 octets; that a country name matches 1 of 193 choices, etc. While .NET 2.0 provides some support for streamlining input validation, it barely scratches the surface of automating and simplifying the input validation process.