Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / gist:5338433
Last active December 15, 2015 23:09
Get registered bindings from Ninject.
public class InjectionBinding
{
public Type RegistrationKey { get; set; }
public IList<object> Implementations { get; set; }
public Type[] GetImplementationTypes()
{
return Implementations.Select(row => row.GetType()).ToArray();
}
}
@crmckenzie
crmckenzie / gist:4736254
Created February 8, 2013 02:53
Demo of a fluent api implementation for mapping one object to another. The unit test does not actually exercise the implementation, but it does demonstrate how the api will look to the consumer.
[Test]
public void ApiDocumentation()
{
// Arrange
var builder = Substitute.For<IBuilder>();
builder.Create<string>().From(5.0m).Returns("Five");
// Act
var result = builder.Create<string>().From(5.0m);
public interface ICommand<in TRequest, out TResponse> : IDisposable
{
TResponse Execute(TRequest request);
}
/// <summary>
/// Use Request.Empty when the command doesn't need any arguments.
/// </summary>
public class Request
{
@crmckenzie
crmckenzie / gist:4632765
Last active December 11, 2015 17:09
Recursive Mocks Sample
public interface IMapper
{
IMapperLink From<TInput>(TInput input);
}
public interface IMapperLink
{
TOutput To<TOutput>();
}
public interface IRepository : IDisposable
{
IQueryable<T> Find<T>() where T: class;
T Get<T>(object key) where T : class;
void Save(object value);
void Delete(object value);
@crmckenzie
crmckenzie / gist:4004375
Last active October 12, 2015 09:08
Powershell script to ilmerge a project. Useful in TeamCity
<#
.SYNOPSIS
IlMerges an assembly with its dependencies. Depends on nuget being installed in the PATH.
.PARAMETER targetProject
The name of the project to be ilmerged
.PARAMETER outputAssembly
The name of the ilmerged assembly when it is created
@crmckenzie
crmckenzie / gist:3994421
Created November 1, 2012 15:37
Consuming global ObservableDbProvider events
Hub.ConnectionOpening += (sender, args) =>
{
// your code here
};
Hub.ConnectionClosing += (sender, args) =>
{
// your code here
};
@crmckenzie
crmckenzie / gist:3990195
Created October 31, 2012 21:56
Bootstrapping Isg.EntityFramework.ObservableProvider
ObservableProviderConfiguration.RegisterProvider("System.Data.SqlServerCe.4.0", setAsDefault:true);