This file contains 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
/* | |
* 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 | |
{ |
This file contains 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 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, |
This file contains 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
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) |
This file contains 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
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" |
This file contains 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
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. |
This file contains 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
Hint #2 ... why not make time a message as well? |
This file contains 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
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; | |
} |
This file contains 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 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 = "/"; |
This file contains 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
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 |
This file contains 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
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) |