示例#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;
            }
        }
示例#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);
        }
示例#3
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);
        }
示例#4
0
        public void Test_SingleTripLifecycle_ForAllPartnerFleets()
        {
            PartnerTrip trip = null;

            foreach (PartnerFleet fleet in partner.PartnerFleets.Values)
            {
                var i = 1;
                foreach (Pair <Location, Location> tripStartEnd in fleet.possibleTrips)
                {
                    Console.WriteLine("Trip " + i++ + "/" + fleet.possibleTrips.Length);
                    TestTripLifecycleAndReturningDriver(fleet, tripStartEnd);
                }
            }
        }
示例#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);
            }
        }
示例#6
0
 private void ValidateOriginationAndService(PartnerTrip trip)
 {
     if (trip.status == Status.Queued) //if still completely local
     {
         Assert.AreEqual(PartnerTrip.Origination.Local, trip.origination, "The origination 'trip' is different to local. Trip ID: " + trip.ID);
         Assert.AreEqual(PartnerTrip.Origination.Local, trip.service, "The service 'trip' is different to local. Trip ID: " + trip.ID);
     }
     else
     {
         if (origination != null)
         {
             Assert.AreEqual(origination, trip.origination, "The origination is different. Trip ID: " + trip.ID);
         }
         if (service != null)
         {
             Assert.AreEqual(service, trip.service, "The service is different. Trip ID: " + trip.ID);
         }
     }
 }
示例#7
0
 public void ValidateTripThruStatus(PartnerTrip trip)
 {
     if (trip.origination != PartnerTrip.Origination.Foreign && trip.service != PartnerTrip.Origination.Foreign)
     {
         return;
     }
     Gateway.GetTripStatusResponse response = tripthru.GetTripStatus(new Gateway.GetTripStatusRequest(partner.ID, trip.ID));
     Assert.AreEqual(trip.status, response.status, "The trip local status is different in compare how gateway says. Trip ID: " + trip.ID);
     if (trip.status == Status.Enroute)
     {
         Assert.IsNotNull(response.driverLocation, "The trip is route but the driverLocation is null. Trip ID: " + trip.ID);
     }
     if (trip.status == Status.PickedUp)
     {
         Assert.IsTrue(response.driverLocation.Equals(trip.pickupLocation, tolerance: locationVerificationTolerance), "The trip is PickedUp but the driverLocation is out to the tolerance area. Trip ID: " + trip.ID);
     }
     if (trip.status == Status.Complete)
     {
         Assert.IsTrue(response.driverLocation.Equals(trip.dropoffLocation, tolerance: locationVerificationTolerance), "The trip is Complete but the driverLocation is out to the tolerance area. Trip ID: " + trip.ID);
     }
 }
示例#8
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
                    {}
                }
            }
        }
示例#9
0
        private DateTime GetTimeWhenStatusShouldBeReached(PartnerTrip trip)
        {
            DateTime timeoutAt;

            switch (trip.status)
            {
            case Status.Enroute:
            case Status.PickedUp:
            case Status.Complete:
            {
                Assert.IsNotNull(trip.ETA, "The trip ETA is null. Trip ID:" + trip.ID);
                timeoutAt = (DateTime)trip.ETA + maxLateness;
                break;
            }

            default:
            {
                timeoutAt = DateTime.UtcNow + maxLateness;
                break;
            }
            }
            return(timeoutAt);
        }