Skip to content

Instantly share code, notes, and snippets.

class Identity
attr_reader :value
def initialize( value )
@value = value
end
def bind
yield @value
end
class Maybe
attr_reader :value
def initialize ( value )
@value = value
end
def bind
if (@value == nil)
Maybe.new( nil )
require "../list"
require "spec"
describe "Create a FuncList" do
# Called before each example.
before(:each) do
@subject = FuncList.new
end
@panesofglass
panesofglass / JobRepositoryTests.cs
Created July 21, 2009 18:19
Test format examples with xUnit.NET and NBehave
namespace Cloud.ATS.Domain.Tests
{
using Entities;
using NBehave.Narrator.Framework;
using Xunit;
using Xunit.AssertExtensions;
using Xunit.Specifications;
@panesofglass
panesofglass / IDetailLoader.cs
Created October 24, 2009 18:04
IDetailLoader<T>
public interface IDetailLoader<T>
{
void Load(string importPath, Action<T> addToBatch);
IEnumerable<T> GetDetailItems(IEnumerable<Row> rows);
T GetDetailItemFrom(Row row)
}
public abstract class DetailLoader<T> : IDetailLoader<T>
{
public virtual void Load(string importPath, ProgressItem progressItem, Action<T> addToBatch)
{
var spreadsheet = SpreadsheetDocument.Load(importPath);
var rows = spreadsheet.Rows();
progressItem.Start(rows.Count());
var details = GetDetailItems(rows, progressItem);
public class DetailLoaderWithProgressItem<T> : IDetailLoader<T>
{
private IDetailLoader<T> _loader;
private ProgressItem _progressItem;
public DetailLoaderWithProgressItem(IDetailLoader<T> loader, ProgressItem progressItem)
{
_loader = loader;
_progressItem = progressItem;
}
public abstract class DetailLoader<T> : IDetailLoader<T>
{
public virtual void Load(string importPath, Action<T> addToBatch)
{
var spreadsheet = SpreadsheetDocument.Load(importPath);
var rows = spreadsheet.Rows();
var details = GetDetailItems(rows);
foreach (var detail in details)
addToBatch(detail);
@panesofglass
panesofglass / ISpecification.cs
Created October 26, 2009 16:14
Interface for the Specification pattern.
namespace Foundation.Specifications
{
/// <summary>
/// Interface for a specification.
/// </summary>
/// <typeparam name="T">The type specified.</typeparam>
/// <seealso href="http://www.lostechies.com/blogs/chrismissal/archive/2009/09/10/using-the-specification-pattern-for-querying.aspx" />
public interface ISpecification<T>
{
/// <summary>
@panesofglass
panesofglass / CompositeSpecification.cs
Created October 26, 2009 16:15
Extension methods for creating composite Specifications.
using System;
using System.Linq.Expressions;
namespace Foundation.Specifications
{
/// <summary>
/// A composite specification.
/// </summary>
/// <seealso href="http://www.lostechies.com/blogs/chrismissal/archive/2009/09/10/using-the-specification-pattern-for-querying.aspx" />
public static class CompositeSpecification