Skip to content

Instantly share code, notes, and snippets.

@gregoryyoung
gregoryyoung / generator.cs
Created July 5, 2011 14:45
data driven test
/*
* This sample shows the building of a data driven specification. This is the simplest
* version of a generator. Basically the runner will call anything that returns an IEnumerable<Specification>.
* You can customize how the specifications are returned. In this case multiple specifications are
* generated, based on the data involved. In this case, four specifications are returned.
*
* With a little bit of work this could also be made much more generic (eg to support all data driven specs)
*/
public class DataDrivenSpecifications
{
@gregoryyoung
gregoryyoung / Example.cs
Created July 6, 2011 19:27
Simple.Testing.Documentation.Example
public class AccountSpecifications
{
public Specification when_constructing_an_account = new
ConstructorSpecification<Account>()
{
When = () => new Account("Jane Smith", 17),
Expect =
{
account => account.AccountHolderName == "Jane Smith",
account => account.UniqueIdentifier == 17,
@gregoryyoung
gregoryyoung / doc.cs
Created July 7, 2011 02:06
doc generator
static void Main(string[] args)
{
SimpleRunner.RunAllInAssembly(typeof(Program).Assembly).ForEach(PrintSpec);
}
private static void PrintSpec(RunResult result)
{
var passed = result.Passed ? "Passed" : "Failed";
Console.WriteLine(result.Name.Replace('_', ' ') + " - " +passed);
if(result.On != null)
@gregoryyoung
gregoryyoung / failedtest
Created August 24, 2011 22:08
Failed Test output
The Run Result's Message must be equal to " On Failed" FAILED
Assertion failed, expression was:
The Run Result's Message must be equal to " On Failed"
' |
| False
"No when on specification"
@gregoryyoung
gregoryyoung / gist:1500720
Created December 20, 2011 08:00
Greg's Stop Loss Kata
Greg's Stop Loss Kata
Testing is very hard when time is involved ...
A trailing stop loss is a term used in financial trading. For a very in depth explanation you can read here http://www.investopedia.com/articles/trading/03/080603.asp and http://en.wikipedia.org/wiki/Order_(exchange)#Stop_orders
However we do not need a huge amount of background in order to do the kata as we are going to limit the problem a bit.
The general idea is that when you buy into a stock at a price say $10. You want it to automatically get sold if the stock goes below $9 (-$1). If we use the term "trailing" that means that id the price goes up to $11 then the sell point becomes $10.
@gregoryyoung
gregoryyoung / gist:1500722
Created December 20, 2011 08:01
spolier for Stop Loss Kata
Hint #2 ... why not make time a message as well?
@gregoryyoung
gregoryyoung / gist:1898785
Created February 24, 2012 07:41
quick kata impl
class stoploss {
private Dictionary<Guid, decimal> fifteen = new Dictionary>Guid, decimal>()
private Dictionary<Guid, decimal> thirty = new Dictionary>Guid, decimal>();;
bool alive = true;
decimal price
Guid id;
public stoploss(PositionAcquiredMessage m) {
id = m.PositionId;
}
public class Analytics
{
// Tracker version.
private const string Version = "4.4sa";
private const string CookieName = "__utmmobile";
// The path the cookie will be available to, edit this to use a different
// cookie path.
private const string CookiePath = "/";
@gregoryyoung
gregoryyoung / gist:1981871
Created March 5, 2012 23:09
Notepad Diagram Visualizations!
System.Void AutoTest.Minimizer.Tests.when_generating_cache_name_for_method::static_method_returns_simple_cache_name()
System.Void AutoTest.Minimizer.Tests.when_generating_cache_name_for_method::static_method_returns_simple_cache_name()
System.Void AutoTest.Minimizer.Tests.AssemblyTestFixture::SetUp().001 ms here
System.Void AutoTest.Minimizer.Tests.when_generating_cache_name_for_method::static_method_returns_simple_cache_name().008 ms here
Mono.Cecil.MethodDefinition AutoTest.Minimizer.Tests.AssemblyReferenceExtension::GetMethodDefinition<T>(Mono.Cecil.AssemblyDefinition,System.String).007 ms here
Mono.Cecil.TypeDefinition AutoTest.Minimizer.Tests.AssemblyReferenceExtension::GetTypeDefinition<T>(Mono.Cecil.AssemblyDefinition).007 ms here
Mono.Cecil.MemberReference AutoTest.Minimizer.Tests.when_generating_cache_name_for_method::GetMethodReferenceFrom(Mono.Cecil.MethodDefinition).000 ms here
System.Collections.Generic.IList`1<AutoTest.Minimizer.MemberAccess> AutoTest.Minimizer.TypeScanne
@gregoryyoung
gregoryyoung / gist:2290767
Created April 3, 2012 09:57
xunit example
A profiler can quite easily find the constructor call to default constructor on this code:
[Fact]
public void ModestCreatesParameterWithBlah(){
var p = new MultiOrderedConstructorType();
p.Number = ...;
Assert.AreEqual(0, p.Number);
}
but on this it is created outside the scope of the test (its done internally by xunit)