Skip to content

Instantly share code, notes, and snippets.

@yowchun93
Last active March 31, 2020 01:03
Show Gist options
  • Save yowchun93/e374185db82e9e8876ca6c3d845e741d to your computer and use it in GitHub Desktop.
Save yowchun93/e374185db82e9e8876ca6c3d845e741d to your computer and use it in GitHub Desktop.
Restaurant Reservations
public void TryAcceptReturnsReservationIdInHappyPathScenario(
[Frozen]Mock<IReservationsRepository> td,
Reservation reservation,
IReadOnlyCollection<Reservation> reservations,
MaîtreD sut,
int excessCapacity,
int expected)
{
// i think td refers to test-double
// ReservationsRepository is mocked
td.Setup(r => r.IsReservationInFuture(reservation)).Returns(true);
td
.Setup(r => r.ReadReservations(reservation.Date))
.Returns(reservations);
td.Setup(r => r.Create(reservation)).Returns(expected);
var reservedSeats = reservations.Sum(r => r.Quantity);
reservation.IsAccepted = false;
sut = sut.WithCapacity(
reservedSeats + reservation.Quantity + excessCapacity);
var actual = sut.TryAccept(reservation);
Assert.Equal(expected, actual);
Assert.True(reservation.IsAccepted);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment