Skip to content

Instantly share code, notes, and snippets.

View moodmosaic's full-sized avatar

Nikos Baxevanis moodmosaic

View GitHub Profile
@moodmosaic
moodmosaic / ApiControllerRegistration.cs
Created March 15, 2012 14:04
Post: Using the Web API Dependency Resolver with Castle Windsor
foreach (Type controller in typeof(OrderController).Assembly.GetTypes().Where(type => typeof(IHttpController).IsAssignableFrom(type)))
{
// https://github.com/srkirkland/Inflector/blob/5fd4c818dd172bbe276fb210f25c2e2ceaff019e/Inflector/Inflector.cs
string name = Inflector.Pluralize(controller.Name.Replace("Controller", ""));
container.Register(Component
.For(controller)
.Named(name)
.LifestylePerWebRequest());
}
@moodmosaic
moodmosaic / BuildHttpSelfHostServer.cs
Created May 11, 2012 10:19
Draft: Minimum code required to initialize Windsor and return a new HttpSelfHostServer instance. (Work in-progress.)
private static HttpSelfHostServer BuildHttpSelfHostServer(string baseAddress)
{
var configuration = new HttpSelfHostConfiguration(baseAddress);
configuration.DependencyResolver =
new WindsorDependencyResolver(
new WindsorContainer()
.Install(new WebWindsorInstaller()));
configuration.Routes.MapHttpRoute(
@moodmosaic
moodmosaic / Equality_Behaves_As_Expected.cs
Last active December 15, 2015 07:39
A discussion branch for a question about Likeness on Stack Overflow.
// http://stackoverflow.com/questions/15558873/trouble-using-autofixtures-createproxy-to-use-likeness-semanticcomparison-feat
[Fact]
public void Equality_Behaves_As_Expected()
{
var template = new Fixture().Create<Band>();
var createdBand = new Band
{
Brass = template.Brass,
@moodmosaic
moodmosaic / Test_With_InlineAutoMockDataAttribute.cs
Last active December 16, 2015 12:28
A discussion branch for a question on Stack Overflow about using AutoFixture declaratively.
// http://stackoverflow.com/questions/16145284/autofixture-how-to-express-the-following-code-declaratively/16145954?noredirect=1#16145284
public class Tests
{
[Theory]
[InlineAutoMockData(@"-o=C:\Temp\someFile -p=1")]
[InlineAutoMockData(@"-p=1 -o=C:\Temp\someFile")]
public void ParseMissingParameterShouldReturnCorrectResult(
string argsString,
SomeClass sut)
@moodmosaic
moodmosaic / Ploeh.AutoFixture.js
Last active December 18, 2015 20:29
Node.js sample adapter-module for AutoFixture via Edge.js
var create = require('edge').func(function () {/*
//#r "Ploeh.AutoFixture.dll"
using System;
using Ploeh.AutoFixture;
public class Startup
{
public async System.Threading.Tasks.Task<object> Invoke(object request)
@moodmosaic
moodmosaic / SemanticEqualityComparisonInFSharp.fs
Last active December 30, 2015 13:49
Compare complex object graphs with SemanticComparer<T>.
module SemanticEqualityComparisonInFSharp
open System
open System.Reflection
open Ploeh.SemanticComparison
open Xunit
open Xunit.Extensions
[<CustomEquality; NoComparison>]
type StructuralType =
@moodmosaic
moodmosaic / GreedyFactoryMethods.cs
Last active January 2, 2016 17:29
AutoFixture strategy for invoking Factory Methods with most parameters based on Twitter discussion on https://twitter.com/madstt/status/420850414641090560
internal class GreedyFactoryMethodQuery : IMethodQuery
{
public IEnumerable<IMethod> SelectMethods(Type type)
{
if (type == null)
throw new ArgumentNullException("type");
return from mi in type.GetMethods(
BindingFlags.Static | BindingFlags.Public)
where mi.ReturnType == type
@moodmosaic
moodmosaic / Scenarios.fs
Last active August 29, 2015 14:00
mountebank mocks with F#
module Mountebank.Scenarios
// PM> Install-Package xunit
// PM> Install-Package Unquote
open System
open System.Net.Mail
open Xunit
let verify = Swensen.Unquote.Assertions.test
@moodmosaic
moodmosaic / runner.html
Last active August 29, 2015 14:00
A small sample of a Jasmine custom matcher that internally parses expressions into an AST.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Custom matchers for Expressions</title>
<!-- $ bower install jasmine && npm install jsep -->
<link href="bower_components/jasmine/lib/jasmine-core/jasmine.css" rel="stylesheet" />
<script src="bower_components/jasmine/lib/jasmine-core/jasmine.js"></script>
@moodmosaic
moodmosaic / Scenarios.fs
Last active August 29, 2015 14:00
mountebank stubs with F#
open FSharp.Data
open System
open System.Net
open Xunit
let verify = Swensen.Unquote.Assertions.test
[<Fact>]
[<UseImposterStub(
"192.168.1.4",