Skip to content

Inheriting tests produce unexpected test name #187

Open
@powerdude

Description

@powerdude

Hello,

If I take the example and tweak it like so:

[TestClass]
[Story(
Title = "UI Account holder withdraws cash",
AsA = "As an Account Holder",
IWant = "I want to withdraw cash from an ATM",
SoThat = "So that I can get money when the bank is closed")]
public class UiAccountHolderWithCash : AccountHolderWithdrawsCashFluentScanner
{

    public override void AndTheAccountBalanceShouldBe(int balance)
    {
        Assert.AreEqual(balance, _card.AccountBalance);
    }

    public override void CardIsRetained(bool cardIsRetained)
    {
        Assert.AreEqual(cardIsRetained, _atm.CardIsRetained);
    }
}



//[TestClass]
//[Story(
//    Title = "Account holder withdraws cash",
//    AsA = "As an Account Holder",
//    IWant = "I want to withdraw cash from an ATM",
//    SoThat = "So that I can get money when the bank is closed")]
public abstract class AccountHolderWithdrawsCashFluentScanner
{
    private const string GivenTheAccountBalanceIsTitleTemplate =
                "Given the account balance is ${0}";
    private const string AndTheMachineContainsEnoughMoneyTitleTemplate =
                "And the machine contains enough money";
    private const string WhenTheAccountHolderRequestsTitleTemplate =
                "When the account holder requests ${0}";
    private const string AndTheCardShouldBeReturnedTitleTemplate =
                "And the card should be returned";

    protected Card _card;
    protected Atm _atm;

    public void GivenTheAccountBalanceIs(int balance)
    {
        _card = new Card(true, balance);
    }

    public void GivenTheCardIsDisabled()
    {
        _card = new Card(false, 100);
        _atm = new Atm(100);
    }

    public void AndTheCardIsValid()
    {
    }

    public void AndTheMachineContains(int atmBalance)
    {
        _atm = new Atm(atmBalance);
    }

    public void WhenTheAccountHolderRequests(int moneyRequest)
    {
        _atm.RequestMoney(_card, moneyRequest);
    }

    public void TheAtmShouldDispense(int dispensedMoney)
    {
        Assert.AreEqual(dispensedMoney, _atm.DispenseValue);
    }

    public abstract void AndTheAccountBalanceShouldBe(int balance);

    public abstract void CardIsRetained(bool cardIsRetained);

    void AndTheAtmShouldSayThereAreInsufficientFunds()
    {
        Assert.AreEqual(DisplayMessage.InsufficientFunds, _atm.Message);
    }

    void AndTheAtmShouldSayTheCardHasBeenRetained()
    {
        Assert.AreEqual(DisplayMessage.CardIsRetained, _atm.Message);
    }

    [TestMethod]
    public void AccountHasInsufficientFund()
    {
        this.Given(s => s.GivenTheAccountBalanceIs(10),
        GivenTheAccountBalanceIsTitleTemplate)
                .And(s => s.AndTheCardIsValid())
                .And(s => s.AndTheMachineContains(100),
        AndTheMachineContainsEnoughMoneyTitleTemplate)
            .When(s => s.WhenTheAccountHolderRequests(20),
        WhenTheAccountHolderRequestsTitleTemplate)
            .Then(s => s.TheAtmShouldDispense(0), "Then the ATM should not dispense")
                .And(s => s.AndTheAtmShouldSayThereAreInsufficientFunds())
                .And(s => s.AndTheAccountBalanceShouldBe(10))
                .And(s => s.CardIsRetained(false),
        AndTheCardShouldBeReturnedTitleTemplate)
            .BDDfy();
    }

    [TestMethod]
    public void AccountHasSufficientFund()
    {
        this.Given(s => s.GivenTheAccountBalanceIs(100),
        GivenTheAccountBalanceIsTitleTemplate)
                .And(s => s.AndTheCardIsValid())
                .And(s => s.AndTheMachineContains(100),
        AndTheMachineContainsEnoughMoneyTitleTemplate)
            .When(s => s.WhenTheAccountHolderRequests(20),
        WhenTheAccountHolderRequestsTitleTemplate)
            .Then(s => s.TheAtmShouldDispense(20), "Then the ATM should dispense $20")
                .And(s => s.AndTheAccountBalanceShouldBe(80),
        "And the account balance should be $80")
                .And(s => s.CardIsRetained(false),
        AndTheCardShouldBeReturnedTitleTemplate)
            .BDDfy();
    }

    [TestMethod]
    public void CardHasBeenDisabled()
    {
        this.Given(s => s.GivenTheCardIsDisabled())
            .When(s => s.WhenTheAccountHolderRequests(20))
            .Then(s => s.CardIsRetained(true), "Then the ATM should retain the card")
                .And(s => s.AndTheAtmShouldSayTheCardHasBeenRetained())
            .BDDfy();
    }
}

I'd hope to see an error for UiAccountHolderWithCash.CardHasBeenDisabled. Instead i get UiAccountHolderWithCash.AccountHolderWithdrawsCashFluentScanner.CardHasBeenDisabled.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions