This project is read-only.

Complex types as output

Jul 6, 2009 at 8:12 PM

I'm trying to create some pretty BDD style reports with NBehave and it's going well.  The only problem I have is that my inputs and outputs are complex types and the only output I'm getting in the reports are the class name.  How can I specifiy I want a object property or method in the output.  For example, I have the following class:

public class Debit
            public DebtType DebtType{ get; set;}
            public double Amount { get; set; }

And I want the Amount value as part of the the scenario:

story.WithScenario("Calculating Ratio")
    .Given("An income of", 5000, income => user.SetPrimaryIncome(income, "primary"))
    .And("Credit Card Debt is , TestData.GetCreditCardDebit(1000), user.AddDebit)
    .And("Utility Bill is", TestData.GetUtilityDebit(500), user.AddDebit)
    .When("Calculating Ratio", calculator, c => debt = c.CalculateDebtRatioFor(user))

I need the output to be:

Scenario: Calculating Ratio
            Given An income of: 5000
            And Credit Card Debt is 1000
            And Utility Bill is : 500
            When Calculating Ratio: pyf_spike.Calculators.QuickCalculator

Instead of:

Scenario: Calculating Ratio
            Given An income of: 5000
            And Credit Card Debt is pyf_spike.DebtTypes.Debit
            And Utility Bill: pyf_spike.DebtTypes.Debit
            When Calculating Ratio: pyf_spike.Calculators.QuickCalculator

Simply override tostring is not what I want to do here, because the result fro Calculator is also a complex type and I need to display all of the properties to.



Jul 7, 2009 at 7:57 PM

In the current version of NBehave overriding ToString() is your only option.
It should be quite simple to add an interface that nbehave could look for and use instead of ToString() if implemented.