Skip to content

Instantly share code, notes, and snippets.

@blair55
blair55 / Base Test Class
Created October 10, 2012 21:25
AutoMocking with StructureMap and Moq in BDD Cucumber Style
public abstract class GivenA<T> where T : class
{
private MoqAutoMocker<T> _autoMocker = new MoqAutoMocker<T>();
protected T Target { get; private set; }
[SetUp]
public void Setup()
{
Given();
@blair55
blair55 / AggressivelyCacheAttribute.cs
Created November 7, 2012 22:35
WebAPI ActionFilter Dependency Injection with StructureMap
using System;
using System.Web.Http.Controllers;
using System.Web.Http.Filters;
using Raven.Client;
namespace MyWebApi.Attributes
{
public class AggressivelyCacheAttribute : ActionFilterAttribute
{
public IDocumentStore DocumentStore { get; set; }
@blair55
blair55 / AutoUpdater.csproj
Created December 13, 2012 14:20
ClickOnce Auto Update Application
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<RootNamespace>AutoUpdater</RootNamespace>
<AssemblyName>AutoUpdater</AssemblyName>
<!-- begin include -->
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<IsWebBootstrapper>true</IsWebBootstrapper>
<Install>true</Install>
<InstallFrom>Web</InstallFrom>
@blair55
blair55 / Maps
Last active December 11, 2015 09:49
A RavenDB MultiMap Index to query across documents on non-id key.
AddMap<Pixel>(pixels =>
from p in pixels
from tag in (p.Tags == null || !p.Tags.Any())
? new[] {"_notags_"}
: p.Tags
select new GroupedResult
{
Tag = tag,
PixelIds = new[] {p.Id},
Urls = new[] {(string) null}
@blair55
blair55 / HttpContextBaseExtenstions.cs
Last active December 14, 2015 08:58
HttpContext extension method to set sub domain safe cookie
public static class HttpContextBaseExtenstions
{
public static void SetSubdomainSafeCookie(this HttpContextBase context, string name, string value)
{
var domain = String.Empty;
if (!context.Request.IsLocal)
{
var domainSegments = context.Request.Url.Host.Split('.');
domain = "." + String.Join(".", domainSegments.Skip(1));
@blair55
blair55 / linkedSlider.js
Created April 18, 2013 21:05
Linked Slider AngularJS Directive using JQuery UI
app.directive('linkedSlider', function () {
return {
restrict: 'A',
scope: {
value: '=',
link: '=',
step: '@',
min: '@',
max: '@',
condition: '&'
@blair55
blair55 / Deploy Time Command Line 1
Created May 22, 2013 22:43
Specifying Environment Variables at Deploy Time not at Build Time
MyProject.deploy.cmd
/y /M:https://MyHostMachine:8172/MsDeploy.axd
/u:MyUserName /p:MyPassword /A:Basic -allowUntrusted
"-setParam:name='IIS Web Application Name',value='MyIISWebAppName'"
@blair55
blair55 / IMyInterface.cs
Last active December 18, 2015 04:29
Implement a C# Interface in F#
namespace Domain
{
public interface IMyInterface
{
string MyProperty { get; set; }
void PerformAction();
decimal MethodWithParameters(decimal a, int b);
}
@blair55
blair55 / ScoreChecker.cs
Last active December 20, 2015 10:39
New Tricks from an Old Pattern
public class ScoreChecker
{
public IPlayer GetScoredPlayer(IPlayer player)
{
if (player.Score > 8)
{
return new HighScorePlayer(player);
}
if (player.Score > 2)
@blair55
blair55 / TestsAfter.cs
Last active December 22, 2015 00:19
Comparing Test Spec Frameworks
public class WhenICreateIdentifierFromRequest : WithSubjectAndResult<ScoreResourceIdentifierFactory, ScoreResourceIdentifier>
{
static CreateScoreResourceRequest _createScoreResourceRequest;
Establish _context = () => The<IObjectHasher>().WhenToldTo(m => m.CreateHashFor(_createScoreResourceRequest)).Return("hash");
Because _of = () => Result = Subject.CreateIdentifierFromRequest(_createScoreResourceRequest);
It _createsAHashFromTheObject = () => The<IObjectHasher>().WasToldTo(m => m.CreateHashFor(_createScoreResourceRequest));