Skip to content

Instantly share code, notes, and snippets.

@crmckenzie
crmckenzie / BadApiDesign.cs
Created August 15, 2012 20:47
Bad Batch API Design
public interface IRecordProcessor
{
Response Process(Record[] records);
}
public class Response
{
public bool Success { get; set; }
}
@crmckenzie
crmckenzie / Install-VSCommandPrompt.ps1
Last active October 8, 2015 17:18
Install-VSCommandPrompt
function Install-VSCommandPrompt($version = "2013")
{
switch ($version)
{
2013 { $toolsVersion = "120" }
2012 { $toolsVersion = "110" }
2010 { $toolsVersion = "100" }
2008 { $toolsVersion = "90" }
2005 { $toolsVersion = "80" }
@crmckenzie
crmckenzie / gist:3990195
Created October 31, 2012 21:56
Bootstrapping Isg.EntityFramework.ObservableProvider
ObservableProviderConfiguration.RegisterProvider("System.Data.SqlServerCe.4.0", setAsDefault:true);
@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: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
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: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 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: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);
@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();
}
}