-
Notifications
You must be signed in to change notification settings - Fork 84
Buying train tickets example #132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| using NUnit.Framework; | ||
| using TestStack.BDDfy.Samples.BuyingTrainFares; | ||
|
|
||
| namespace TestStack.BDDfy.Samples | ||
| { | ||
| [TestFixture] | ||
| public class BuyingTrainFareWithExamples | ||
| { | ||
| private Fare fare; | ||
| private BuyerCategory _buyerCategory; | ||
| Money Price { get; set; } | ||
|
|
||
| [Test] | ||
| public void SuccessfulRailCardPurchases() | ||
| { | ||
| this.Given(_ => TheBuyerIsA(_buyerCategory)) | ||
| .And(_ => TheBuyerSelectsA(fare)) | ||
| .When(_ => TheBuyerPays()) | ||
| .Then(_ => ASaleOccursWithAnAmountOf(Price)) | ||
| .WithExamples(new ExampleTable( | ||
| "Buyer Category", "Fare", "Price") | ||
| { | ||
| {BuyerCategory.Student, new MonthlyPass(), new Money(76)}, | ||
| {BuyerCategory.Senior, new MonthlyPass(), new Money(98)}, | ||
| {BuyerCategory.Standard, new MonthlyPass(), new Money(146)}, | ||
| {BuyerCategory.Student, new WeeklyPass(), new Money(23)}, | ||
| {BuyerCategory.Senior, new WeeklyPass(), new Money(30)}, | ||
| {BuyerCategory.Standard, new WeeklyPass(), new Money(44)}, | ||
| {BuyerCategory.Student, new DayPass(), new Money(4)}, | ||
| {BuyerCategory.Senior, new DayPass(), new Money(5)}, | ||
| {BuyerCategory.Standard, new DayPass(), new Money(7)}, | ||
| {BuyerCategory.Student, new SingleTicket(), new Money(1.5m)}, | ||
| {BuyerCategory.Senior, new SingleTicket(), new Money(2m)}, | ||
| {BuyerCategory.Standard, new SingleTicket(), new Money(3m)} | ||
| }) | ||
| .BDDfy("Successful rail card purchases"); | ||
| } | ||
|
|
||
| void TheBuyerIsA(BuyerCategory buyerCategory) | ||
| { | ||
|
|
||
| } | ||
|
|
||
| void TheBuyerSelectsA(Fare fare) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| { | ||
|
|
||
| } | ||
|
|
||
| void TheBuyerPays() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or have you already implemented that feature?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't, but plan to once examples are merged (before v4 is released)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this will be really really useful as I tend to reuse step methods across scenarios but in different roles (i.e. once as a When and another time as an AndWhen); but having the step nature in the method name makes it hard. |
||
| { | ||
|
|
||
| } | ||
|
|
||
| void ASaleOccursWithAnAmountOf(Money price) | ||
| { | ||
|
|
||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| namespace TestStack.BDDfy.Samples.BuyingTrainFares | ||
| { | ||
| enum BuyerCategory | ||
| { | ||
| Student, | ||
| Senior, | ||
| Standard | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| namespace TestStack.BDDfy.Samples.BuyingTrainFares | ||
| { | ||
| class DayPass : Fare | ||
| { | ||
| public override string ToString() | ||
| { | ||
| return "Day Pass"; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| namespace TestStack.BDDfy.Samples.BuyingTrainFares | ||
| { | ||
| class Fare | ||
| { | ||
|
|
||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| using System.Globalization; | ||
|
|
||
| namespace TestStack.BDDfy.Samples.BuyingTrainFares | ||
| { | ||
| class Money | ||
| { | ||
| public Money(decimal amount) | ||
| { | ||
| Amount = amount; | ||
| } | ||
|
|
||
| public decimal Amount { get; set; } | ||
|
|
||
| protected bool Equals(Money other) | ||
| { | ||
| return Amount == other.Amount; | ||
| } | ||
|
|
||
| public override bool Equals(object obj) | ||
| { | ||
| if (ReferenceEquals(null, obj)) return false; | ||
| if (ReferenceEquals(this, obj)) return true; | ||
| if (obj.GetType() != GetType()) return false; | ||
| return Equals((Money)obj); | ||
| } | ||
|
|
||
| public override int GetHashCode() | ||
| { | ||
| return Amount.GetHashCode(); | ||
| } | ||
|
|
||
| public static bool operator ==(Money left, Money right) | ||
| { | ||
| return Equals(left, right); | ||
| } | ||
|
|
||
| public static bool operator !=(Money left, Money right) | ||
| { | ||
| return !Equals(left, right); | ||
| } | ||
|
|
||
| public override string ToString() | ||
| { | ||
| return Amount.ToString("C", CultureInfo.CreateSpecificCulture("EN-US")); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| namespace TestStack.BDDfy.Samples.BuyingTrainFares | ||
| { | ||
| class MonthlyPass : Fare | ||
| { | ||
| public override string ToString() | ||
| { | ||
| return "Monthly Pass"; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| namespace TestStack.BDDfy.Samples.BuyingTrainFares | ||
| { | ||
| class SingleTicket : Fare | ||
| { | ||
| public override string ToString() | ||
| { | ||
| return "Day Pass"; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| namespace TestStack.BDDfy.Samples.BuyingTrainFares | ||
| { | ||
| class WeeklyPass : Fare | ||
| { | ||
| public override string ToString() | ||
| { | ||
| return "Weekly Pass"; | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to rename this to
GivenTheBuyerIsAuntil the logic for prefixing the title according to step type is implemented.