Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions Samples/TestStack.BDDfy.Samples/BuyingTrainFareWithExamples.cs
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)
Copy link
Copy Markdown
Member

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 GivenTheBuyerIsA until the logic for prefixing the title according to step type is implemented.

{

}

void TheBuyerSelectsA(Fare fare)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AndTheBuyerSelectsA?

{

}

void TheBuyerPays()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or have you already implemented that feature?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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
}
}
10 changes: 10 additions & 0 deletions Samples/TestStack.BDDfy.Samples/BuyingTrainFares/DayPass.cs
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";
}
}
}
7 changes: 7 additions & 0 deletions Samples/TestStack.BDDfy.Samples/BuyingTrainFares/Fare.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace TestStack.BDDfy.Samples.BuyingTrainFares
{
class Fare
{

}
}
47 changes: 47 additions & 0 deletions Samples/TestStack.BDDfy.Samples/BuyingTrainFares/Money.cs
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"));
}
}
}
10 changes: 10 additions & 0 deletions Samples/TestStack.BDDfy.Samples/BuyingTrainFares/MonthlyPass.cs
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";
}
}
}
10 changes: 10 additions & 0 deletions Samples/TestStack.BDDfy.Samples/BuyingTrainFares/SingleTicket.cs
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";
}
}
}
10 changes: 10 additions & 0 deletions Samples/TestStack.BDDfy.Samples/BuyingTrainFares/WeeklyPass.cs
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";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@
<Folder Include="Properties\" />
</ItemGroup>
<ItemGroup>
<Compile Include="BuyingTrainFares\BuyerCategory.cs" />
<Compile Include="BuyingTrainFares\DayPass.cs" />
<Compile Include="BuyingTrainFares\Fare.cs" />
<Compile Include="BuyingTrainFares\Money.cs" />
<Compile Include="BuyingTrainFares\MonthlyPass.cs" />
<Compile Include="BuyingTrainFares\SingleTicket.cs" />
<Compile Include="BuyingTrainFares\WeeklyPass.cs" />
<Compile Include="BuyingTrainFareWithExamples.cs" />
<Compile Include="CanRunAsyncSteps.cs" />
<Compile Include="Atm\AccountHasInsufficientFund.cs" />
<Compile Include="Atm\Atm.cs" />
Expand Down