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.Reflection; | |
public class PrintDotNetVersionInfo { | |
public static void Main(string[] args) { | |
PrintVersionInfo(); | |
} | |
public static void PrintVersionInfo() { | |
Console.WriteLine(".NET Version: " + System.Environment.Version.ToString()); |
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
// NOTE: Yes, NUNit has an [ExpectedException] attribute, but: | |
// - Sometimes I want to have a few assertions in the same [Test] | |
// - AssertThrows(() => { code }) is nicer than ExpectedException, IMHO | |
// | |
// NOTE: This is implemented as extension methods so it doesn't matter what | |
// class your NUnit tests are in ... if you don't want to have to say | |
// this.AsserThrows() (instead of just AssertThrows), you could add | |
// these methods to a baseclass that your [TestFixture] classes inherit from. | |
// Usage: |
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 System.Linq; | |
using DuplicateFinder.Core.Commands; | |
using Machine.Specifications; | |
namespace DuplicateFinder.Core.Integration.Tests { |
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
# Usage: | |
# fill_in_fields :foo => 'bar' # fill_in 'foo', :with => 'bar' | |
# fill_in_fields :user, :name => 'bob' # fill_in 'user_name', :with => 'bob' | |
# fill_in_fields :contact, :address, :street => '6 cedar rd' # fill_in 'contact_address_street_, :with => '6 cedar rd' | |
def fill_in_fields *args | |
field, value = args.pop.first | |
prefix = '' | |
while args.any? | |
prefix += args.shift.to_s + "_" | |
end |
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.Threading.Tasks; | |
namespace AppThatRunsItself { | |
public class App { | |
public static void Main(string[] args) { | |
// we might instantiate a host and run an app with it | |
var host = new Hosting.Host(); | |
var dotNet40_thing = new Task(() => Console.WriteLine("Hello from task")); |
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
# Ruby syntax notes: | |
# | |
# - the last value of a method is implicitly returned. 'return' is typically only used for short-circuiting | |
# - attr_reader :foo is the same as def foo; @foo; end | |
# - get_foo and set_foo methods are very Java-esque and you should typically not name methods like that in Ruby | |
# - instead of @array.push(1), use the push operator. @array << 1 | |
# - if you want to do something conditionally on one line, the conditional comes *after* the code, eg. x = 5 if @dogs.any? | |
# - except for single line blocks, eg. each {|x| ... }, variable names should not be abbreviated | |
# - parenthesis are optional and should only be used when they help make the code easier to understand (subject to debate) | |
# |
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; | |
public static class Int32TimesExtension { | |
public static void Times(this int numberOfTimes, Action<int> action) { | |
for (int i = 0; i < numberOfTimes; i++) | |
action.Invoke(i); | |
} | |
} | |
public class Program { |
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
module ShouldHaveAttributes | |
class Validator | |
def initialize object | |
@object = object | |
end | |
def method_missing name, *args, &block | |
# puts "#{@object}.#{name}.should == #{args.first.inspect}" | |
@object.send(name).should == args.first |
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.Reflection; | |
namespace NUnit.Framework { | |
public static class ShouldHavePropertiesExtension { | |
/// <summary>For checking lots of properties on an object</summary> | |
/// <remarks> | |
/// Lets you say: | |
/// <code> |
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 eatFood = new Action<object>(food => Console.WriteLine("I eat {0}", food)); | |
var foods = new List<string> { "banana", "bagel", "pizza" }; | |
foods.ForEach(food => eatFood.Invoke(food)); | |
// I eat banana | |
// I eat bagel | |
// I eat pizza |