This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IFoo { void MyMethod(Action<int[]> callback); } | |
[Test] | |
public void TestCallback() | |
{ | |
var sub = Substitute.For<IFoo>(); | |
var callback = Substitute.For<Action<int[]>>(); | |
var data = new[] { 1, 2, 3 }; | |
sub.When(x => x.MyMethod(callback)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec' | |
class DocsToCode | |
def docs_in(path) | |
[] | |
end | |
def code_in(doc) | |
"" | |
end | |
def extract(path) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IRoot { string Data { get; set; } } | |
[Serializable] | |
public abstract class Root : IRoot { public abstract string Data { get; set; } } | |
[Test] | |
public void FailingTest() | |
{ | |
var root = CreateMock(); // <-- create a mock with your favourite mocking framework for Root or IRoot | |
var formatter = new BinaryFormatter(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mouseDown = Observable.FromEventPattern(firstButton, "MouseDown"); | |
var mouseUp = Observable.FromEventPattern(firstButton, "MouseUp"); | |
var mouseMove = Observable.FromEventPattern(firstButton, "MouseMove"); | |
mouseDown.Subscribe(x => Debug.WriteLine(">>> mouse down")); | |
mouseUp.Subscribe(x => Debug.WriteLine(">>> mouse up")); | |
(from down in mouseDown | |
from up in mouseUp.TakeUntil(mouseMove) | |
select up) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NHibernatishExample { | |
public interface IRepository { SampleEntity Get(int id); } | |
public class SampleEntity { | |
public virtual int Id { get; set; } | |
public virtual string Name { get; set; } | |
} | |
public class SomeService { | |
private readonly IRepository _repository; | |
public SomeService(IRepository repository) { _repository = repository; } | |
public SampleEntity DoSomething() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* Retrieving a window once "minimised" | |
* Resuming/suspending Parallels VMs. | |
* Finder. All of finder, but primarily alternating between favourites on LHS and files on RHS | |
* Tweetdeck on Chrome [not OS X specific] | |
* Misson Control (accessing and using): Bind keyboard shortcut, tab to switch apps | |
* Visual switch between windows in same app: bind keyboard shortcut, tab/~ to switch between apps, arrows to switch windows | |
* Going Back through system prefs: Cmd + [, Cmd + ] | |
* Right click (App Key / right Win Key on Windows keyboards) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Car = Car { make :: String, model :: String } deriving (Eq,Show) | |
-- Explicit implementation of Ord for Car | |
instance Ord Car where | |
compare (Car { make = aMake, model = aModel}) (Car { make = bMake, model = bModel}) = | |
if makeCompare == EQ then aModel `compare` bModel else makeCompare | |
where makeCompare = aMake `compare` bMake | |
-- Implementation over arbitrary number of field in record. | |
comp :: (Ord a) => [b -> a] -> b -> b -> Ordering |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using NSubstitute; | |
using NSubstitute.Core; | |
using NUnit.Framework; | |
namespace Sample { | |
public static class MyTestExtensions { | |
public static void DoThese<T>(this WhenCalled<T> when, params Action<CallInfo>[] actions) { | |
var actionQueue = new Queue<Action<CallInfo>>(actions); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Simplified custom matcher example. | |
This shows matching args less than a specified int value. | |
More common use would be checking a few properties on a complex type (e.g. Car make, model, year) | |
*/ | |
//Arg.Matches.LessThan(2); | |
public static class Extensions { | |
public static int LessThan(this Match match, int number) { | |
return match.WhenNoErrorsFrom(x => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data TakeState a = TakeState Int a deriving (Show) | |
take' n = | |
let f (TakeState i acc) head = if i==n then (TakeState i acc) else (TakeState (i+1) (acc++[head])) | |
in foldl f (TakeState 0 []) |
OlderNewer