PaxDev

Latest Posts:

More Expressive Tests with Shouldly

There are a couple of key things all good Unit Tests should do:


Deploy iOS/Ionic/Cordova apps to the Simulator or a Device

How to deploy an Ionic/Cordova app to the iOS Simulator or an iOS device.


Create an Ionic mobile app with Angular and Cordova

Create an Angular 12 App using Ionic 6 and Cordova 10


Evergreen builds with Docker

In the second post in the getting started with Docker series we’ll look at using Docker to allow us to guarantee the tools and frameworks used to build and run an application even if we no longer have those tools installed on our current machine.


Running Docker containers

This is the first in a series of posts giving a high-level step-by-step view of getting started with Docker.


Create and install a local Root Certificate Authority on Windows

In order to avoid warning messages about self-signed certificates when developing web applications on a local machine you can create your own devlopment Root Certificate Authority.


Installing kubectl on Windows

NB This post assumes you are using Powershell. If not adjust for your shell of choice.


Levelling up Git with Aliases

Create a shortcut

To save yourself a bit of typing you can create a Git Alias for frequently used commands, e.g.


Powershell Functions

  • Create a function:
    Function SomeFunction {
        # Script ...
    }
    
  • Pass parameters
    param(
        [type1]$param1, 
        [type2]$param2
    )
    
    • Use as the first line of a function (after the opening curly brace) to pass params to a function
    • Use as the first line of a script to capture command line arguments
    • Normal parameters can be specified -paramName value
    • Use [switch]$someFlag=$false to allow a “flag” type switch -someFlag


Useful Links

Tools


Powershell Cheat Sheet

  • $_ - Current PowerShell object
  • % - ForEach-Object
  • & "SomeString (or var)" - Execute what is in the string or var, e.g.
     $MsBuild = "Path//To//MsBuild"
     & $MsBuild My.csproj /p:SomeOptions
    
  • $var = Read-Host "Prompt" - Get Input
  • > - Redirect operator
     Some-Command > out.txt # redirect output of Some-Command to file
     2>&1 # redirect error to success stream 
    
  • $null - Null
  • $true/$false - Boolean
  • -eq, -ne, -gt, -lt, -le, -ge - comparison operators Case-insensitive by default.
  • -and, -or, -xor, -not, ! - logical operators
  • -in, -notin, -contains, -notcontains - containment
  • $( ) - subexpression - evaluate the contents of the brackets
  • 1..5 - range operator
  • Get-Childitem -Path Env:* | Sort-Object Name - list out env vars
  • . some\script.ps1 - execute the contents of the script (the script path could contain variables)
  • $PSScriptRoot - the folder of the currently executing script
  • $MyInvocation - get the command that caused this invocation
    • $MyInvocation.PSCommandPath - the full path to the command for the current invocation
    • $MyInvocation.Line - gets the full text that caused the invocation
    • $MyInvocation.InvocationName - gets the command name to invoke the script. If executing as a script would be the script name
    • If($MyInvocation.Line.Length -gt $MyInvocationName.Length){
      $params = $MyInvocation.Line.Substring($MyInvocation.InvocationName.Length)
      }
      

      - get the full text after the script name if invoking script from command line

  • | Tee-Object - splits out the pipeline so you can “tap” the pipeline to pull out a variable or file and continue processing If it is the last part of the pipeline it will output to console.
    • | Tee-Object -Variable SomeVar - will split out the pipeline to $SomeVar.


Register Azure Deployment Agents

The PowerShell script provided on the Deployment Pool/Deployment Group Forms in Azure DevOps is very useful, but does not show all the command line switches to allow you to fully automated scripted deployment of Azure DevOps Agents


Conditional Workflow in Azure Release Pipeline

Imagine you have some pre-release checks you want to run in an Azure DevOps Release Pipeline. Depending on the result of the Pre-Release check you may wish to run a Manual Intervention task to approve or reject the release.


Working with Git Remote Origin

To list the current remote origin use


Powershell Strings

A single-quote delimited string will not expand variables:


Multiline variables in Azure DevOps

I was surprised to discover that you cannot write a multiline value to an Azure DevOps Pipeline Variable from a Powershell script.


Output a variable from Powershell to an Azure DevOps Pipeline

To set the value of a variable in Azure DevOps, you have a couple of options.


Mapping complex types with AutoMapper

When you need to go beyond a simple mapping from a source member of one type to a destination member of another type, AutoMapper has some powerful tools in the shape of custom Converters and Resolvers. However, the documentation can be a little unclear as to which type to use for a given situation, and exactly how to register the type in your mapping configuration. Furthermore, there are too many parameters supplied to the methods you need to implement and it can be confusing to write, much less come back and maintain later.


MSpec Fakes with Async Await

In general, the C# language gives us lots of simple constructs to write asynchronous code simply and elegantly, but unfortunately when we come to write unit tests we can find ourselves having to write ugly, unintuitive boilerplate code in order to get our async code to run in MSpec Fakes.


JIRA Ticket Bookmarklet

Shave a couple of clicks off the time taken to open a JIRA ticket with this handy tip. Note that, while this post relates to using JIRA, the same process can be used for any hackable URL.


Run an Azure Agent in Docker

There are a number of benefits of running a dedicated Agent for your Azure Pipelines.


dotnet new Cheatsheet

Install a template from a file:

dotnet new -i ../[[path-to-project-folder]]
# Where path-to-project-folder is the folder containing the .template.config folder, which itself contains a template.json

Docker/Kubernetes/Helm Cheat-Sheet

Docker


Kubernetes Ingress URL Rewriting.

Relative URLS

When using relative URLS behind an ingress, you may find that you have issues if your service is served at some site like [my.domain]/[external-service-path]/ Navigating relative to the domain will miss out the /[external-service-path]/ part of the URL.


Creating a Helm Release for Kubernetes

To deploy a web application to Kubernetes using Helm, use the following steps (assuming you have already containerised your application.)


Publish Docker Build Test Results

Whilst building our dotnetcore apps inside a container gives us all sorts of advantages including repeatable builds and caching, it can present a challenge on a build server since we are running in the context of the Docker container, not the Build Server.


NuGet with Docker Builds

A Docker build does not necessarily run in a context that is authorised to access a private NuGet feed, so we have a challenge to access our packages on a dotnet restore.


Provisioning Kubernetes pod resources using Helm

In the values.yaml file, there is an entry


IStartupFilter

When registering services in ASP.Net Core, often you have to register the services in Startup.ConfigureServices and then tell the IApplicationBuilder to actually use them in Startup.Configure.