Skip to content

Instantly share code, notes, and snippets.

View chrisoldwood's full-sized avatar

Chris Oldwood chrisoldwood

View GitHub Profile
@chrisoldwood
chrisoldwood / SpecFlow.Hooks.cs
Last active December 5, 2022 10:39
Custom SpecFlow listener and "logging" class to reduce noise when running SpecFlow tests from the command line.
using TechTalk.SpecFlow;
namespace MyCompany.SpecFlowTests
{
[Binding]
public static class Hooks
{
[BeforeFeature]
public static void BeforeFeature()
{
@chrisoldwood
chrisoldwood / Test-Driven-SQL-Procedure.sql
Last active January 14, 2016 22:13
The final versions of the example SQL code written during my live-coding Test-Driven SQL talk
if (object_id('pub.ReportBugsPerDeveloper') is not null)
drop procedure pub.ReportBugsPerDeveloper;
go
create procedure pub.ReportBugsPerDeveloper
as
select
su.FirstName + ' ' + su.LastName as FullName,
count(b.BugId) as BugCount
from
@chrisoldwood
chrisoldwood / CreateAssemblyVersionInfo.txt
Last active May 18, 2016 10:42
Visual C# pre-build step to generate a common AssemblyVersionInfo.cs from a version number defined by a couple of environment variables.
<PreBuildEvent>
if not defined PRODUCT_VERSION set PRODUCT_VERSION=0.0.0
if not defined BUILD_NUMBER set BUILD_NUMBER=1
echo using System.Reflection;&gt;"$(SolutionDir)Source\AssemblyVersionInfo.cs"
echo [assembly: AssemblyVersion("%25PRODUCT_VERSION%25.%25BUILD_NUMBER%25")]&gt;&gt;"$(SolutionDir)Source\AssemblyVersionInfo.cs"
</PreBuildEvent>
@chrisoldwood
chrisoldwood / SimpleDependencyResolver.cs
Created January 14, 2016 21:28
A minimalist IoC container for use with ASP.Net/OWIN.
using System;
using System.Collections.Generic;
using System.Web.Http.Dependencies;
namespace WebApi
{
using TypeFactories = Dictionary<Type, Func<object>>;
public sealed class SimpleDependencyResolver : IDependencyResolver
{
@chrisoldwood
chrisoldwood / CheckPackageVersions.ps1
Last active November 24, 2018 23:31
Checks all packages.config files looking for version mismatches between different projects.
<#
.synopsis
Scans the packages.config files in a .Net solution looking for multiple
versions of the same package.
.description
Ideally your .Net based solutions should always be using a consistent
set of NuGet packages to avoid subtle bugs. This script, a companion to
CheckPackageCache, analyses all the NuGet packages used by your solution
and tells you if multiple package versions are being referenced.
@chrisoldwood
chrisoldwood / CheckPackageCache.ps1
Last active November 24, 2018 23:29
Checks the solution's packages folder looking for multiple versions of the same package.
<#
.synopsis
Looks for multiple versions of the same NuGet package in the NuGet
packages folder for a .Net based soluton.
.description
If you check your NuGet dependencies into your source control repository
it's easy for old versions to be left hanging around. This script, a
companion to CheckPackageVersions, highlights where you might have stale
packages left behind.
@chrisoldwood
chrisoldwood / PowerShellExitTest.ps1
Last active August 16, 2023 13:49
A set of tests to show if your version of PowerShell returns the correct exit code under various error conditions.
exit 1
@chrisoldwood
chrisoldwood / CustomJsonConverter.cs
Last active February 17, 2023 23:16
Example showing infinite loop deserialising polymorphic types with a custom JsonConverter.
namespace JsonTests
{
public class CustomJsonConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return typeof(BaseType).IsAssignableFrom(objectType);
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
@chrisoldwood
chrisoldwood / fixr.py
Created June 2, 2018 23:19
Python script to query the Fixr REST API
import requests
import argparse
import sys
def listVenues():
response = requests.get(f'{baseUrl}/venue?limit=1000&offset=0')
json = response.json()
for venue in json['data']:
id = venue['id']
@chrisoldwood
chrisoldwood / Log-SQL-IO-Stats.ps1
Last active August 6, 2018 12:11
Example of how to capture SQL Server query IO statistics from a .Net based client.
Set-StrictMode -Version Latest
$ErrorActionPreference = 'stop'
$configuration = 'Server=.\SQLEXPRESS;Database=master;Trusted_Connection=True;'
$connection = New-Object System.Data.SqlClient.SqlConnection $configuration
$connection.Open()
$handler = [System.Data.SqlClient.SqlInfoMessageEventHandler] {
param($sender, $event)