Plain text !!
Hi All!
Just been having a play with the BDD sugar - and smacked on some extension methods … what I now have is plain text descriptions in tests. No more_underscores_used_to_make_sentences..
Its still a work in progress.. but here’s a preview of what the tests now look like..
** Update ** seems this has been done before with subspec -
public class when_adding_a_new_client : client_api_specs {
[SpecTitle]
public void if_the_client_dto_is_valid()
{
"if we are given a new client object that is valid".in_the_context(when_creating_a_new_account_with_a_valid_dto);
"when asked to create a new client".by_acting_on(() => system_under_test.create_new_account_from(client_dto));
"it should ask the validator to check the dto is valid".observe_that(() => the_dependency<IClientValidator>().was_told_to(x => x.validate(client_dto)));
"it should tell the repository to save a new client dto".observe_that(() => the_dependency<IClientRepository>().was_told_to(x => x.save(client_dto)));
}
}
[SpecTitle]
public void when_transfering_accounts(){
"if the client already has a beta test account".in_the_context(()=> { when_creating_a_new_account_with_a_valid_dto();
client_dto.has_beta_test_account = true;});
"when signing up for a full account".by_acting_on(()=>system_under_test.create_new_account_from(client_dto));
"it should tell the repository to get the client from storage".observe_that(()=>the_dependency<IClientRepository>().was_told_to(x=>x.get_client_from(client_dto.id)));
"it should apply the early adopters discount".observe_that(()=>a_client.charge(standardPrice.apply_discount_of(20)));
"it should tell the repository to update the client account".observe_that(() => the_dependency<IClientRepository>().was_told_to(x => x.save(client_dto)));
@"it should send an email to the client
telling them that the account has been upgraded".observe_that(()=>the_dependency<IEmailClient>().was_told_to(x=>x.sendMessage()));
}
Here’s the output report (using resharper as the test runner)
client_api_specs.when_transfering_accounts : Passed
acting on : when signing up for a full account
observation : it should tell the repository to get the client from storage
observation : it should apply the early adopters discount
observation : it should tell the repository to update the client account
observation : it should send an email to the clientÂ
      telling them that the account has been upgraded
Â
Let me know what you think!
Thanks
Zak