TestStack / TestStack.BDDfy

BDDfy is the simplest BDD framework EVER!
MIT License
417 stars 84 forks source link

Re-using Then steps #242

Open epitka opened 7 years ago

epitka commented 7 years ago

I am wondering if it is possible to re-use steps. I have several commands whose side effect is that they all end up creating an object on which i want to run some asserts. So, I was wondering if it would be possible to re-use "then" steps. I looked at AccountHasInsufficientFund example and I tried adding Bddfy step between other steps, hoping that it would add these steps in proper place. In the example below, I moved commented out lines into a class BidCreated that has only "then" steps. But when I did that, I get and exception that all columns from the example are not used up. Any idea if what I am trying to do is possible?

Update: After running example I see that it only seems to associate a story with a test.

 this
                .Given(s => Given_default_data_for_command())
                .And(s => Given_that_OutToAgent_is(OutToAgentDate))
                .And(s => And_given_that_InUnderwriting_is(InUnderwritingDate))
                .When(s => When_Command_Is_Executed())
               .BDDfy<BidCreated>() // following commented lines were moved into BidCreated class
                //.Then(s => Then_Bid_should_be_created())
                //    .And(s => And_description_should_be(Command.Description))
                //    .And(s => And_Client_should_be(Command.Client))
                //    .And(s => And_optionNumber_should_be(Command.OptionNumber))
                //    .And(s => And_BidType_should_be(Command.BidType.Code))
                //    .And(s => And_ClaimsApplicationType_should_be(Command.ClaimsApplicationType.Code))
                //    .And(s => And_RegulatoryBody_should_be(Command.UnderwritingLicenseFiling.RegulatoryBody))
                //    .And(s => And_Underwriter_should_be(Command.Underwriter))
                //    .And(s => And_UnderwritingFirm_should_be(Command.UnderwritingLicenseFiling.UnderwritingFirm))
                //.Then(s => Then_One_and_only_one_BidProposal_should_be_created())
                //    .And(s => And_BaseForm_should_be(Command.UnderwritingLicenseFiling.BaseForm))
                //    .And(s => And_ProductionSchedule_should_have_only_one_step())
                //    .And(s => And_ProductionSchedule_should_be_in_InitialCreation())
                //    .And(s => And_ProductionTargets_should_be_created(ExpectProductionTargetsToBeCalculated))
                //    .And(s => Then_One_and_only_one_ClientPolicy_should_be_created())
                .WithExamples(new ExampleTable("Out To Agent Date", "In Underwriting Date",
                    "Expect Production Targets To Be Calculated")
                {
                    {DateTime.Now.AddDays(30), null, true},
                    {null, DateTime.Now.AddDays(30), true},
                    {null, null, false}
                })
               .BDDfy()
                ;