public async Task ExistingRoutesTest(string src, string dest)
        {
            JourneyBuilder journeyBuilder = new JourneyBuilder(_airlineStub.Object, _airportStub.Object, _routeStub.Object, src, dest);
            var            journey        = await journeyBuilder.Build();

            VerifyRoute(src, dest, journey);
        }
        public async Task EmptyRouteOnSameSrcAndDesc()
        {
            JourneyBuilder journeyBuilder = new JourneyBuilder(_airlineStub.Object, _airportStub.Object, _routeStub.Object, "ABC", "ABC");
            var            journey        = await journeyBuilder.Build();

            Assert.AreEqual(journey.Routes.Length, 0);
        }
        public async Task CaseSensivityTest(string src, string dest)
        {
            JourneyBuilder journeyBuilder = new JourneyBuilder(_airlineStub.Object, _airportStub.Object, _routeStub.Object, src, dest);
            var            journey        = await journeyBuilder.Build();

            Assert.IsNotNull(journey);
        }
示例#4
0
        public async Task <IActionResult> Get([FromQuery] string sourceAirport, [FromQuery] string destinationAirport, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (string.IsNullOrEmpty(sourceAirport))
            {
                return(BadRequest("sourceAirport is empty"));
            }

            if (string.IsNullOrEmpty(destinationAirport))
            {
                return(BadRequest("destinationAirport is empty"));
            }

            Journey journey = null;

            try
            {
                JourneyBuilder journeyBuilder = new JourneyBuilder(_airlineProvider, _airportProvider, _routeProvider, sourceAirport, destinationAirport, cancellationToken);
                journey = await journeyBuilder.Build();
            }
            catch (AirportNotFoundException exc)
            {
                return(BadRequest(exc.Message));
            }
            if (journey == null)
            {
                return(NotFound());
            }
            return(Ok(journey));
        }
        public async Task InactiveAirlinesAirportTest()
        {
            JourneyBuilder journeyBuilder = new JourneyBuilder(_airlineStub.Object, _airportStub.Object, _routeStub.Object, "SVO", "IAA");
            var            journey        = await journeyBuilder.Build();

            Assert.IsNull(journey);
        }
        public void OperationCancelledExceptionTest(string src, string dest)
        {
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
            JourneyBuilder          journeyBuilder          = new JourneyBuilder(_airlineStub.Object, _airportStub.Object, _routeStub.Object, src, dest, cancellationTokenSource.Token);

            cancellationTokenSource.Cancel();
            Assert.ThrowsAsync <TaskCanceledException>(async() => { await journeyBuilder.Build(); });
        }
 public void CanBuildCompleteJourney()
 {
     JourneyBuilder.Create(j =>
                           j.WithPassenger(p =>
                                           p.WithName("Matthijs", "van der Veer").BornOn(1989, 03, 25).OfType(PassengerType.Adult))
                           .WithSegment(s =>
                                        s.DepartingFrom("AMS").DepartingOn(2019, 03, 08, 15, 20).ArrivingAt("BCN")
                                        .ArrivingOn(2019, 03, 08, 17, 30))
                           .WithSegment(s =>
                                        s.DepartingFrom("BCN").DepartingOn(2019, 03, 09, 14, 10).ArrivingAt("AMS")
                                        .ArrivingOn(2019, 03, 09, 16, 20)));
 }
示例#8
0
            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);
            }
示例#9
0
                        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);
                        }
示例#10
0
                        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);
                        }
示例#11
0
                        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);
                        }
示例#12
0
                        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);
                        }
示例#13
0
                        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);
                        }
        public void CanAddMultipleSegments()
        {
            var journey = JourneyBuilder.Create(j => j.WithSegment(s => s).WithSegment(s => s).WithSegment(s => s));

            Assert.Equal(3, journey.Segments.Count);
        }
        public void CanAddMultiplePassengers()
        {
            var journey = JourneyBuilder.Create(j => j.WithPassenger(p => p).WithPassenger(p => p).WithPassenger(p => p));

            Assert.Equal(3, journey.Passengers.Count);
        }
        public void DestAirportNotFoundExceptionTest()
        {
            JourneyBuilder journeyBuilder = new JourneyBuilder(_airlineStub.Object, _airportStub.Object, _routeStub.Object, "LED", "___");

            Assert.ThrowsAsync <AirportNotFoundException>(async() => { await journeyBuilder.Build(); });
        }
        public void CanBuildJourney()
        {
            var journey = JourneyBuilder.Create(j => j);

            Assert.NotNull(journey);
        }