public void ShouldNotThrow() { //arrange //act //assert Expect(() => StationBuilder.Create().Build()) .To.Not.Throw(); }
public void GivenNullZone_ShouldThrow() { //arrange //act //assert Expect(() => StationBuilder.Create().WithZone(null).Build()) .To.Throw <ArgumentNullException>() .With.Property(err => err.ParamName) .Equal.To("zone"); }
public void GivenCard_ShouldStartJouneyFromThatStation() { //arrange var station = StationBuilder.Create() .Build(); var card = Substitute.For <ICard>(); //act station.SwipeIn(card); //assert card.Received(1).StartJourney(station); }
public void GivenStation_WithJourneyNoUnderway_ThrowsJourneyException() { //arrange var station = StationBuilder.Create() .Build(); var card = CardBuilder.Create() .Build(); //act //assert Expect(() => card.EndJourney(station)).To.Throw <JourneyException>(); }
public void GivenNull_ShouldThrow() { //arrange var station = StationBuilder.Create() .Build(); //act //assert Expect(() => station.SwipeOut(null)) .To.Throw <ArgumentNullException>() .With.Property(err => err.ParamName) .Equal.To("card"); }
public void GivenStation_SetsCurrentJourneyStartFrom() { //arrange var station = StationBuilder.Create() .Build(); var card = CardBuilder.Create() .Build(); //act card.StartJourney(station); //assert Expect(card.CurrentJourneyStartFrom).To.Not.Be.Null(); Expect(card.CurrentJourneyStartFrom).To.Equal(station); }
public void GivenSameStationAsJourneyStart_ReturnsNull() { //arrange var stationFrom = StationBuilder.Create() .Build(); var card = CardBuilder.Create() .Build(); //act card.StartJourney(stationFrom); var actual = card.EndJourney(stationFrom); //assert Expect(actual).To.Be.Null(); }
public void GivenCard_ShouldEndJouneyAtThatStation() { //arrange var journey = JourneyBuilder.BuildDefault(); var station = StationBuilder.Create() .Build(); var card = Substitute.For <ICard>(); card.EndJourney(station).Returns(journey); //act var actual = station.SwipeOut(card); //assert Expect(actual).To.Be(journey); }
private static Journey CreateSingleJourneyWithZoneCost(decimal from, decimal to) { var stationFrom = StationBuilder.Create() .WithZoneWithCostPerSingleJourney(from) .Build(); var stationTo = StationBuilder.Create() .WithZoneWithCostPerSingleJourney(to) .Build(); var card = CardBuilder.Create() .Build(); card.StartJourney(stationFrom); return(card.EndJourney(stationTo)); }
public void GivenStation_WithJourneyUnderway_ClearsCurrentJourneyStartFrom() { //arrange var stationTo = StationBuilder.Create() .Build(); var stationFrom = StationBuilder.Create() .Build(); var card = CardBuilder.Create() .Build(); //act card.StartJourney(stationFrom); card.EndJourney(stationTo); //assert Expect(card.CurrentJourneyStartFrom).To.Be.Null(); }
public void GivenStation_WithJourneyUnderway_AddsJourneyToHistory() { //arrange var stationTo = StationBuilder.Create() .Build(); var stationFrom = StationBuilder.Create() .Build(); var card = CardBuilder.Create() .Build(); //act card.StartJourney(stationFrom); var actual = card.EndJourney(stationTo); //assert Expect(card.JourneyHistory.AsEnumerable()).To.Contain(actual); }
public void GivenStation_WithJourneyUnderway_ReturnsJourney() { //arrange var stationTo = StationBuilder.Create() .Build(); var stationFrom = StationBuilder.Create() .Build(); var card = CardBuilder.Create() .Build(); //act card.StartJourney(stationFrom); var actual = card.EndJourney(stationTo); //assert Expect(actual).To.Not.Be.Null(); }
public void ReturnsJourney_WithCostNotExceedingCostPerWeekLimitOfMostExpensiveZone() { //arrange var costFirstJourney = 3m; var dateOfFirstJourney = new DateTime(2018, 8, 6); var expectedCostSecondJourney = 2m; var dateOfSecondJourney = dateOfFirstJourney.AddDays(7); var zone1 = FakeZoneBuilder .Create() .WithCostPerSingleJourney(3) .WithCostPerMonthLimit(4) .Build(); var zone2 = FakeZoneBuilder .Create() .WithCostPerSingleJourney(4) .WithCostPerMonthLimit(5) .Build(); var firstJourney = JourneyBuilder.Create() .WithCost(costFirstJourney) .WithDate(dateOfFirstJourney) .Build(); var card = CardBuilder.Create() .WithJourneyHistory(firstJourney) .WithDateTimeProviderFor(dateOfSecondJourney) .Build(); var stationStart = StationBuilder.Create() .WithZone(zone1) .Build(); var stationEnd = StationBuilder.Create() .WithZone(zone2) .Build(); //act card.StartJourney(stationStart); var actual = card.EndJourney(stationEnd); //assert Expect(actual.Cost).To.Equal(expectedCostSecondJourney); }
public void ShouldReturnJourney_WithCostNotExceedingCostPerMonthLimitOfZone() { //arrange var costPerJourney = 2.5m; var dateOfFirstJourney = new DateTime(2018, 8, 6); var costFirstJourney = 18m; var limitPerDay = 4.5m; var limitPerWeek = 10m; var limitPerMonth = 20m; var dateOfSecondJourney = dateOfFirstJourney.AddDays(7); var expectedCostSecondJourney = 2m; var firstJourney = JourneyBuilder.Create() .WithDate(dateOfFirstJourney) .WithCost(costFirstJourney) .Build(); var card = CardBuilder.Create() .WithDateTimeProviderFor(dateOfSecondJourney) .WithJourneyHistory(firstJourney) .Build(); var zone = FakeZoneBuilder .Create() .WithCostPerSingleJourney(costPerJourney) .WithCostPerDayLimit(limitPerDay) .WithCostPerWeekLimit(limitPerWeek) .WithCostPerMonthLimit(limitPerMonth) .Build(); var stationStart = StationBuilder.Create() .WithZone(zone) .Build(); var stationEnd = StationBuilder.Create() .WithZone(zone) .Build(); //act card.StartJourney(stationStart); var actual = card.EndJourney(stationEnd); //assert Expect(actual.Cost).To.Equal(expectedCostSecondJourney); }
public void GivenSecondJourneyNotInSameDayOrWeekAsFirst_WithCostBelowMonthMax_ShouldReturnJourney_WithFullCostOfSingleJourney() { //arrange var costPerJourney = 2.5m; var limitPerDay = 4.5m; var limitPerWeek = 4.5m; var dateOfFirstJourney = new DateTime(2018, 8, 6); var costFirstJourney = costPerJourney; var dateOfSecondJourney = dateOfFirstJourney.AddDays(7); var expectedCostSecondJourney = costPerJourney; var firstJourney = JourneyBuilder.Create() .WithDate(dateOfFirstJourney) .WithCost(costFirstJourney) .Build(); var card = CardBuilder.Create() .WithDateTimeProviderFor(dateOfSecondJourney) .WithJourneyHistory(firstJourney) .Build(); var zone = FakeZoneBuilder .Create() .WithCostPerSingleJourney(costPerJourney) .WithCostPerDayLimit(limitPerDay) .WithCostPerWeekLimit(limitPerWeek) .Build(); var stationStart = StationBuilder.Create() .WithZone(zone) .Build(); var stationEnd = StationBuilder.Create() .WithZone(zone) .Build(); //act card.StartJourney(stationStart); var actual = card.EndJourney(stationEnd); //assert Expect(actual.Cost).To.Equal(expectedCostSecondJourney); }
public void GivenStation_WithJourneyUnderway_ReturnsJourneyWithDate() { //arrange var today = new DateTime(2018, 8, 12, 13, 14, 15); var stationTo = StationBuilder.Create() .Build(); var stationFrom = StationBuilder.Create() .Build(); var card = CardBuilder.Create() .WithDateTimeProviderFor(today) .Build(); //act card.StartJourney(stationFrom); var actual = card.EndJourney(stationTo); //assert Expect(actual.Date).To.Equal(today); }
public void GivenSecondJourneyInSameMonth_ButNotSameYear_ShouldReturnJourney_WithFullCostOfSingleJourney() { //arrange var costPerJourney = 2.5m; var costFirstJourney = 18m; var limitPerMonth = 20m; var dateOfFirstJourney = new DateTime(2017, 1, 1); var dateOfSecondJourney = dateOfFirstJourney.AddYears(1); var expectedCostSecondJourney = costPerJourney; var firstJourney = JourneyBuilder.Create() .WithDate(dateOfFirstJourney) .WithCost(costFirstJourney) .Build(); var card = CardBuilder.Create() .WithDateTimeProviderFor(dateOfSecondJourney) .WithJourneyHistory(firstJourney) .Build(); var zone = FakeZoneBuilder .Create() .WithCostPerSingleJourney(costPerJourney) .WithCostPerMonthLimit(limitPerMonth) .Build(); var stationStart = StationBuilder.Create() .WithZone(zone) .Build(); var stationEnd = StationBuilder.Create() .WithZone(zone) .Build(); //act card.StartJourney(stationStart); var actual = card.EndJourney(stationEnd); //assert Expect(actual.Cost).To.Equal(expectedCostSecondJourney); }
public void ReturnsJourney_WithCostNotExceedingCostPerDayLimitOfMostExpensiveZone() { //arrange var costFirstJourney = 3m; var expectedCostSecondJourney = 2m; var zone1 = FakeZoneBuilder .Create() .WithCostPerSingleJourney(3) .WithCostPerDayLimit(4) .Build(); var zone2 = FakeZoneBuilder .Create() .WithCostPerSingleJourney(4) .WithCostPerDayLimit(5) .Build(); var firstJourney = JourneyBuilder.Create() .WithCost(costFirstJourney) .Build(); var card = CardBuilder.Create() .WithJourneyHistory(firstJourney) .Build(); var stationStart = StationBuilder.Create() .WithZone(zone1) .Build(); var stationEnd = StationBuilder.Create() .WithZone(zone2) .Build(); //act card.StartJourney(stationStart); var actual = card.EndJourney(stationEnd); //assert Expect(actual.Cost).To.Equal(expectedCostSecondJourney); }