Skip to content

Instantly share code, notes, and snippets.

@gregoryyoung
Created May 10, 2014 11:45
Show Gist options
  • Save gregoryyoung/848b8febc158d7f6a424 to your computer and use it in GitHub Desktop.
Save gregoryyoung/848b8febc158d7f6a424 to your computer and use it in GitHub Desktop.
Context
public class AccountSpecifications
{
const decimal perTransactionFee = 0.99m;
public Specification when_withdrawing_money()
{
var currentBalance = 13.0m;
return new ActionSpecification<AccountContext>
{
On = () => new AccountContext {
Account = new Account(currentBalance),
Command = new WithdrawCommand
{
Amount = 12.00m
}
},
When = account => account.Handle(cmd),
Expect =
{
account => account.Balance == (currentBalance - cmd.Amount) - perTransactionFee,
account => account.CloseToZeroBalance
},
};
}
public class AccountContext {
public Command Command;
public Account Account;
}
}
@gregoryyoung
Copy link
Author

for current balance

    public class shitbird {

        const int x = 5;
        int j = x + 6; //no worries using it
    }

and no you dont need to make a generic depending on how you wire things up. If you have a Command interface you can easily reuse it.

@yevhen
Copy link

yevhen commented May 10, 2014

I'm not sure I'm following you. How that would work without generics? You won't get x.Command.Amount property due to x.Command being of some base command type.

@gregoryyoung
Copy link
Author

To be clear on the ability to use it with just command. you can pretty easily write your own template to support this or could just drop in a dynamic :)

If you look in the other sepcification templates (which are just examples btw its expected that you may run your own) you will notice operations called transformedby you could do this there... or you could just do this

CommandContext {
dynamic sut;
Command command;
}

yeah I know not the most beautiful do you really need strong typing here?

@yevhen
Copy link

yevhen commented May 10, 2014

Anyway, having specs defined as fields leads to inconvenient developer experience with test runners

@yevhen
Copy link

yevhen commented May 10, 2014

Strong-typing? Why not? :)

@gregoryyoung
Copy link
Author

If you want strong typing just make your own template (like what ActionSpecification does).

For runners I know all about fields :) I built all that support into mighty moose for simple.testing and for machine.specs

@gregoryyoung
Copy link
Author

btw for a reference see:

https://github.com/gregoryyoung/Simple.Testing/blob/master/src/Simple.Testing.ClientFramework/SpecificationTemplates.cs

At the end of the day its just doing Expect(When(Given())) you can change what the pipeline types are along the way (the templates just give strong typing to it as a template)

@yevhen
Copy link

yevhen commented May 10, 2014

ok, I'll have a look. Tnx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment