Skip to content

Instantly share code, notes, and snippets.

@crmckenzie
crmckenzie / ConfigureToUseSqlite
Last active December 17, 2015 02:19
How I setup my NHibernate configuration to use Sqlite for unit tests.
public static void ConfigureToUseSqlite(this IKernel kernel)
{
var nHibernateConfiguration = Substitute.For<INHibernateConfiguration>(); // custom interface
var msSqlConfiguration = SQLiteConfiguration.Standard
.InMemory()
.ShowSql()
;
nHibernateConfiguration.GetPersistenceConfiguration().Returns(msSqlConfiguration);
@crmckenzie
crmckenzie / FakeLocalStorage
Created July 22, 2014 18:03
FakeLocalStorage
define([], function() {
function FakeLocalStorage() {
var self = this;
self.length = 0;
self.keys = [];
return self;
}
@crmckenzie
crmckenzie / gist:0f8960452a9827d5d81d
Last active February 28, 2020 23:21
NUnit Collection Equivalence Extension Methods
public static class NUnitExtensions
{
public static CollectionItemsEqualConstraint Using<T>(this CollectionEquivalentConstraint constraint,
Func<T, T, bool> expression)
{
return constraint.Using(new PredicateComparison<T>(expression));
}
public static CollectionItemsEqualConstraint Using<TExpected, TActual>(this CollectionEquivalentConstraint constraint,
Func<TExpected, TActual, bool> expression)
@crmckenzie
crmckenzie / gist:f9eb2e7a59f3318e5bb7
Created August 19, 2014 21:06
Analyze your PATH variable
$path = $env:Path.Split(';') | Where-Object {[string]::IsNullOrWhiteSpace($_) -eq $false } | Sort-Object { $_ }
"Paths that do not exist"
$pathsThatDoNotExist = $path | Where-Object {[System.IO.Directory]::Exists($_) -eq $false}
$pathsThatDoNotExist
""
""
""
"Scrubbed path variable"
@crmckenzie
crmckenzie / gist:d7bbe1be5519f27449e8
Created October 23, 2014 18:55
Reload Powershell Module
Function Reload-Module($ModuleName)
{
$module = Get-Module $ModuleName
$path = $module.Path
"removing $ModuleName"
Remove-Module $ModuleName
"importing $path"
Import-Module $path
@crmckenzie
crmckenzie / .vimrc
Last active August 29, 2015 14:13
.vimrc
" no one cares about vi... poor vi
set nocompatible
" vundle setup
filetype on " required on Mac
filetype off
let is_windows=has('win32')
set runtimepath+=~/.vim/bundle/vundle.vim
@crmckenzie
crmckenzie / Code.cs
Created October 20, 2015 21:18
EF 6 Conventions example
public class StringVarcharFieldConvention : Convention
{
public StringVarcharFieldConvention()
{
this.Properties()
.Where(p => p.PropertyType == typeof(string))
.Configure(c => c.HasColumnType("varchar").HasMaxLength(250))
;
}
@crmckenzie
crmckenzie / EF6-AppRole.cs
Last active October 21, 2015 20:00
EF6 with Application Roles
public class DbConnectionApplicationRoleInterceptor : IDbConnectionInterceptor
{
private readonly string _appRole;
private readonly string _password;
private byte[] _cookie;
public DbConnectionApplicationRoleInterceptor()
{
}
@crmckenzie
crmckenzie / appveyor.yml
Created December 14, 2015 20:22
Semantically Version NuGet Package Build/Test/Publish with AppVeyor
version: 0.1.0.{build}
environment:
packageVersion: 0.1.0
init:
- ps: $env:buildVersion = "$env:packageVersion.$env:appveyor_build_number"
- ps: $env:nugetVersion = "$env:packageVersion-beta-$env:appveyor_build_number"
- ps: Update-AppveyorBuild -Version $env:buildVersion
@crmckenzie
crmckenzie / ControllerContextTestExtensions.cs
Last active August 20, 2019 16:13
Faking Controller Context
public static class Fakes
{
public static UrlHelper FakeUrlHelper(HttpContextBase httpContext, RouteData routeData, RouteCollection routeCollection)
{
var requestContext = new RequestContext(httpContext, routeData);
var urlHelper = new UrlHelper(requestContext, routeCollection);
return urlHelper;
}
public static RouteCollection GetRouteCollection()