Ejemplo n.º 1
0
        public void ValidateNextTripStatus(PartnerFleet fleet, PartnerTrip trip, Status nextStatus)
        {
            ValidateOriginationAndService(trip);
            if (trip.status == nextStatus)
            {
                ValidateTripThruStatus(trip);
            }
            WaitUntilStatusReachedOrTimeout(fleet, trip, GetTimeWhenStatusShouldBeReached(trip));

            Assert.AreEqual(nextStatus, trip.status, "The 'trip' not advance to the next status. Trip ID: " + trip.ID);
            switch (trip.status)
            {
            case Status.Enroute:
                Assert.IsNotNull(trip.driverLocation, "The trip is route but the driverLocation is null. Trip ID: " + trip.ID);
                break;

            case Status.PickedUp:
                Assert.IsNotNull(trip.driverLocation, "The trip is PickedUp but the driverLocation is null. Trip ID: " + trip.ID);
                Assert.IsTrue(trip.driverLocation.Equals(trip.pickupLocation, tolerance: locationVerificationTolerance), "The trip is PickedUp but the driverLocation is out to the tolerance area. Trip ID: " + trip.ID);
                break;

            case Status.Complete:
                Assert.IsNotNull(trip.driverLocation, "The trip is Complete but the driverLocation is null. Trip ID: " + trip.ID);
                Assert.IsTrue(trip.driverLocation.Equals(trip.dropoffLocation, tolerance: locationVerificationTolerance), "The trip is Complete but the driverLocation is out to the tolerance area. Trip ID: " + trip.ID);
                break;
            }
        }
Ejemplo n.º 2
0
        public void TestTripLifecycleAndReturningDriver(PartnerFleet fleet, Pair <Location, Location> tripSpec)
        {
            PartnerTrip trip = fleet.GenerateTrip(fleet.passengers[0], DateTime.UtcNow, tripSpec);

            TestTripLifecycle_FromNewToComplete(fleet, trip);
            ValidateReturningDriverRouteIfServiceLocal(fleet, trip);
        }
Ejemplo n.º 3
0
 public UnitTest_SingleTripLifecycleAndReturningDriver(Test_TripLifeCycle_Base parent, PartnerFleet fleet, Pair <Location, Location> tripSpec)
 {
     if (parent == null)
     {
         throw new Exception("parent must be defined");
     }
     this.parent   = parent;
     this.fleet    = fleet;
     this.tripSpec = tripSpec;
 }
Ejemplo n.º 4
0
        private void WaitUntilStatusReachedOrTimeout(PartnerFleet fleet, PartnerTrip trip, DateTime timeoutAt)
        {
            Status startingStatus = trip.status;

            do
            {
                // There's a reason we're calling ProcessTrip instead of ProcessQueue, as when there are multiple trips in a queue, a call to ProcessQueue
                // may end up processing more than one queue.  Then it may seem like trips jump a state (status).
                fleet.ProcessTrip(trip);
                Thread.Sleep(simInterval);
            } while (trip.status == startingStatus && DateTime.UtcNow < timeoutAt);
        }
Ejemplo n.º 5
0
        public void ValidateReturningDriverRouteIfServiceLocal(PartnerFleet fleet, PartnerTrip trip)
        {
            if (trip.service == PartnerTrip.Origination.Foreign)
            {
                return;
            }
            Status currentStatus = trip.status;

            Assert.AreNotEqual(trip.ETA, null, "The trip ETA is null. Trip ID");
            DateTime timeoutAt = (DateTime)trip.ETA + maxLateness;

            while (!trip.driver.location.Equals(fleet.location))
            {
                fleet.UpdateReturningDriverLocations();
                Assert.IsFalse(DateTime.UtcNow > timeoutAt, "The timeoutAt is less than UtcNow. Trip ID: " + trip.ID);
                System.Threading.Thread.Sleep(simInterval);
            }
        }
Ejemplo n.º 6
0
        public void TestTripLifecycle_FromNewToComplete(PartnerFleet fleet, PartnerTrip trip)
        {
            int activeTrips, response;

            Assert.AreEqual(Status.New, trip.status, "The trip: " + trip.ID + " no is a new trip.");

            lock (fleet)
            {
                fleet.QueueTrip(trip);
                response    = partner.tripsByID.Count(t => t.Value.origination == PartnerTrip.Origination.Local && t.Value.status != Status.Complete);
                activeTrips = ++_activeTrips;
            }

            Assert.AreEqual(Status.Queued, trip.status, "The trip: " + trip.ID + " no is a Queued trip.");
            Assert.AreEqual(activeTrips, response, "The activeTrips");
            ValidateNextTripStatus(fleet, trip, Status.Dispatched);
            ValidateNextTripStatus(fleet, trip, Status.Enroute);
            ValidateNextTripStatus(fleet, trip, Status.PickedUp);
            ValidateNextTripStatus(fleet, trip, Status.Complete);

            lock (fleet)
            {
                var trips = partner.tripsByID.Where(
                    t => t.Value.origination == PartnerTrip.Origination.Local && t.Value.status == Status.Complete);

                foreach (var tripp in trips)
                {
                    try
                    {
                        if (tripsList.Contains(tripp.Key))
                        {
                            continue;
                        }
                        tripsList.Add(tripp.Key);
                        --_activeTrips;
                    }catch
                    {}
                }
            }
        }