public void NotSendRequestConfirmations_WhenRequestIdsMatchExistingRequests_AndThoseRequestsHaveAStatusOfPendingConfirmation_AndTodayIsNotSevenDaysBeforeTheItineraryDate()
        {
            var dateTimeNow            = DateTime.Today;
            var dateTimeNowUnspecified = DateTime.SpecifyKind(dateTimeNow, DateTimeKind.Unspecified);
            var dateTimeUtcNow         = DateTime.SpecifyKind(dateTimeNow, DateTimeKind.Utc);

            var @event = new Event {
                Id = 1, TimeZoneId = "Eastern Standard Time"
            };
            var itinerary = new Itinerary {
                Id = 1, Date = dateTimeNowUnspecified.Date.AddDays(1), EventId = @event.Id, Event = @event
            };
            var request = new Request {
                RequestId = Guid.NewGuid(), Status = RequestStatus.PendingConfirmation
            };

            var backgroundJobClient = new Mock <IBackgroundJobClient>();
            var smsSender           = new Mock <ISmsSender>();

            Context.Requests.Add(request);
            Context.Itineraries.Add(itinerary);
            Context.Events.Add(@event);
            Context.SaveChanges();

            var sut = new SendRequestConfirmationMessagesSevenDaysBeforeAnItineraryDate(Context, backgroundJobClient.Object, smsSender.Object)
            {
                DateTimeUtcNow = () => dateTimeUtcNow.Date
            };

            sut.SendSms(new List <Guid> {
                request.RequestId
            }, itinerary.Id);

            smsSender.Verify(x => x.SendSmsAsync(It.IsAny <string>(), It.IsAny <string>()), Times.Never);
        }
        protected override void LoadTestData()
        {
            var itinerary1 = new Itinerary
            {
                Id   = 1,
                Name = "Test Itinerary 1"
            };

            var task1 = new VolunteerTask
            {
                Id   = 1,
                Name = "Test Task"
            };

            var taskSignup1 = new VolunteerTaskSignup
            {
                Id            = 1,
                VolunteerTask = task1,
                Itinerary     = itinerary1,
                IsTeamLead    = true
            };

            Context.Add(itinerary1);
            Context.Add(task1);
            Context.Add(taskSignup1);

            Context.SaveChanges();
        }
        public void compareMatches()
        {
            Itinerary itinerary = new Itinerary(Leg.DeriveLeg(V.pacific1, L.TOKYO, L.LONGBEACH),
                Leg.DeriveLeg(V.continental2, L.LONGBEACH, L.DALLAS));

            LegActivityMatch startMatch = LegActivityMatch.Match(Leg.DeriveLeg(V.pacific1, L.TOKYO, L.LONGBEACH),
                HandlingActivity.LoadOnto(V.pacific1).In(L.TOKYO),
                itinerary);

            Assert.That(startMatch.HandlingActivity, Is.EqualTo(HandlingActivity.LoadOnto(V.pacific1).In(L.TOKYO)));
            Assert.That(startMatch.Leg, Is.EqualTo(Leg.DeriveLeg(V.pacific1, L.TOKYO, L.LONGBEACH)));

            LegActivityMatch endMatch = LegActivityMatch.Match(Leg.DeriveLeg(V.pacific1, L.TOKYO, L.LONGBEACH),
                HandlingActivity.UnloadOff(V.pacific1).In(L.LONGBEACH),
                itinerary);

            Assert.That(endMatch.HandlingActivity, Is.EqualTo(HandlingActivity.UnloadOff(V.pacific1).In(L.LONGBEACH)));
            Assert.That(endMatch.Leg, Is.EqualTo(Leg.DeriveLeg(V.pacific1, L.TOKYO, L.LONGBEACH)));

            LegActivityMatch nextMatch = LegActivityMatch.Match(Leg.DeriveLeg(V.continental2, L.LONGBEACH, L.DALLAS),
                HandlingActivity.LoadOnto(V.continental2).In(L.LONGBEACH),
                itinerary);

            Assert.That(nextMatch.HandlingActivity,
                Is.EqualTo(HandlingActivity.LoadOnto(V.continental2).In(L.LONGBEACH)));
            Assert.That(nextMatch.Leg, Is.EqualTo(Leg.DeriveLeg(V.continental2, L.LONGBEACH, L.DALLAS)));

            Assert.That(startMatch.CompareTo(endMatch), Is.EqualTo(-1));
            Assert.That(endMatch.CompareTo(startMatch), Is.EqualTo(1));
            Assert.That(endMatch.CompareTo(nextMatch), Is.EqualTo(-1));
            Assert.That(nextMatch.CompareTo(endMatch), Is.EqualTo(1));

            Assert.That(startMatch.CompareTo(startMatch), Is.EqualTo(0));
        }
 public BookingResponseSettings(Itinerary itinerary, CarrierSchema carrierSchema = CarrierSchema.Iata, LocationSchema locationSchema = LocationSchema.Iata)
 {
     FlightResponse = itinerary.FlightResponse;
     CarrierSchema = carrierSchema;
     LocationSchema = locationSchema;
     Itinerary = itinerary;
 }
示例#5
0
        public List <Itinerary> GetAllItinerary()
        {
            List <Itinerary> itineraries = new List <Itinerary>();

            try
            {
                using (SqlConnection conn = new SqlConnection(_connectionString))
                {
                    conn.Open();

                    string        sql    = $"SELECT * FROM itinerary;";
                    SqlCommand    cmd    = new SqlCommand(sql, conn);
                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        Itinerary itinerary = ReadItinerary(reader);
                        //PopulateLandmarks(itinerary);

                        itineraries.Add(itinerary);
                    }
                }
                foreach (Itinerary itinerary in itineraries)
                {
                    PopulateLandmarks(itinerary);
                }
            }
            catch (SqlException e)
            {
                Console.WriteLine("Could not retrieve itineraries from database.");
                Console.WriteLine(e.Message);
                throw;
            }
            return(itineraries);
        }
示例#6
0
        public async Task WorksGreatWithMutableMessagesToo()
        {
            StartBus("endpoint-a").Activator.AddHandlerWithBusTemporarilyStopped <SomeMutableMessage>(async message => message.AddLine("Handled by endpoint-a"));
            StartBus("endpoint-b").Activator.AddHandlerWithBusTemporarilyStopped <SomeMutableMessage>(async message => message.AddLine("Handled by endpoint-b"));
            StartBus("endpoint-c").Activator.AddHandlerWithBusTemporarilyStopped <SomeMutableMessage>(async message => message.AddLine("Handled by endpoint-c"));

            var routingSlipWasReturnedToSender = new ManualResetEvent(false);
            var collectedLines = new List <string>();

            var initiator = StartBus("initiator").Activator.AddHandlerWithBusTemporarilyStopped <SomeMutableMessage>(async message =>
            {
                collectedLines.AddRange(message.Lines);
                routingSlipWasReturnedToSender.Set();
            });

            var itinerary = new Itinerary("endpoint-a", "endpoint-b", "endpoint-c").ReturnToSender();

            await initiator.Bus.Advanced.Routing.SendRoutingSlip(itinerary, new SomeMutableMessage());

            routingSlipWasReturnedToSender.WaitOrDie(TimeSpan.FromSeconds(3));

            Assert.That(collectedLines, Is.EqualTo(new[]
            {
                "Handled by endpoint-a",
                "Handled by endpoint-b",
                "Handled by endpoint-c",
            }));
        }
        public IActionResult TestTraceRoute(double lat, double lng, double acc)
        {
            var userRouteTracer = new UserRouteTracer();
            var i = new Itinerary()
            {
                Legs = new[] {
                    new Leg()
                    {
                        Geometry = new [] {
                            new Coordinate(48.237986, 16.453807),
                            new Coordinate(48.238296, 16.453866),
                            new Coordinate(48.238812, 16.452647),
                            new Coordinate(48.238976, 16.451767),
                            new Coordinate(48.239520, 16.448791)
                        },
                        StartTime = DateTime.Now,
                        EndTime   = DateTime.Now.AddMinutes(10)
                    },
                }
            };
            var result = userRouteTracer.TraceUserWithParticles(i, new TraceLocation()
            {
                Coordinate = new Coordinate(lat, lng),
                Accuracy   = new TraceLocationAccuracy()
                {
                    Confidence = 0.68,
                    Radius     = acc
                },
                Timestamp = DateTime.Now.AddMinutes(4)
            });

            return(Ok(result));
        }
        public void toCargoRoutingDTO()
        {
            var origin = L.HONGKONG;
            var destination = L.LONGBEACH;
            var cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(origin, destination, DateTime.Now));

            var itinerary = new Itinerary(
                Leg.DeriveLeg(SampleVoyages.pacific1, L.HONGKONG, L.TOKYO),
                Leg.DeriveLeg(SampleVoyages.pacific1, L.TOKYO, L.LONGBEACH)
                );

            cargo.AssignToRoute(itinerary);

            var dto = DTOAssembler.toDTO(cargo);

            Assert.AreEqual(2, dto.getLegs().Count());

            LegDTO legDTO = dto.getLegs().ElementAt(0);
            Assert.AreEqual("PAC1", legDTO.getVoyageNumber());
            Assert.AreEqual("CNHKG", legDTO.getFrom());
            Assert.AreEqual("JNTKO", legDTO.getTo());

            legDTO = dto.getLegs().ElementAt(1);
            Assert.AreEqual("PAC1", legDTO.getVoyageNumber());
            Assert.AreEqual("JNTKO", legDTO.getFrom());
            Assert.AreEqual("USLBG", legDTO.getTo());
        }
 public void Test1()
 {
     var userRouteTracer = new UserRouteTracer();
     var i = new Itinerary()
     {
         Legs = new[] {
             new Leg()
             {
                 Geometry = new [] {
                     new Coordinate(48.237986, 16.453807),
                     new Coordinate(48.238296, 16.453866),
                     new Coordinate(48.238812, 16.452647),
                     new Coordinate(48.238976, 16.451767),
                     new Coordinate(48.239520, 16.448791)
                 }
             }
         }
     };
     var result = userRouteTracer.TraceUserOnItinerary(i, new TraceLocation()
     {
         Coordinate = new Coordinate(48.239071, 16.451171),
         Accuracy   = new TraceLocationAccuracy()
         {
             Confidence = 0.68,
             Radius     = 20
         }
     });
     var denseLine   = userRouteTracer.InsertPointsBetween(i.Legs.SelectMany(v => v.Geometry).ToList());
     var debugOutput = $"[{string.Join(",\n", denseLine.Select(v => $"[{v.Lat.ToString(CultureInfo.InvariantCulture)},{v.Lng.ToString(CultureInfo.InvariantCulture)}]"))}";
 }
        public void ProcessItineraryAtRiskTest()
        {
            using var scope = _factory.Services.CreateScope();
            var itineraryService = scope.ServiceProvider.GetService <IItineraryService>();
            var database         = scope.ServiceProvider.GetService <IDatabaseEngine>();

            var locationList = new List <Location>();

            locationList.Add(new Location(37.4219984444444, -122.084, DateTime.Now, true, new Area("United States", "California", "Mountain View", "A subrub")));
            locationList.Add(new Location(37.4219985555555, -122.084, DateTime.Now, true, new Area("United States", "California", "Mountain View", "A subrub")));
            locationList.Add(new Location(37.4219986666666, -122.084, DateTime.Now, true, new Area("United States", "California", "Mountain View", "A subrub")));

            var userItinerary = new Itinerary(locationList);

            var clusterService = scope.ServiceProvider.GetService <IClusterService>();

            clusterService.AddLocationToCluster(new Location(37.4219984444444, -122.084, DateTime.Now, true, new Area("United States", "California", "Mountain View", "A subrub")));
            clusterService.AddLocationToCluster(new Location(37.4219985555555, -122.084, DateTime.Now, true, new Area("United States", "California", "Mountain View", "A subrub")));
            clusterService.AddLocationToCluster(new Location(37.4219986666666, -122.084, DateTime.Now, true, new Area("United States", "California", "Mountain View", "A subrub")));


            var clusterManagementService = scope.ServiceProvider.GetService <IClusterManagementService>();

            clusterManagementService.BeginManagment();

            var itineraryRiskAtRisk = itineraryService.ProcessItinerary(userItinerary, database.Get_User_Access_Token("*****@*****.**"));

            Assert.Equal(2, itineraryRiskAtRisk.TotalItineraryRisk);
        }
示例#11
0
        public void toCargoRoutingDTO()
        {
            var origin      = L.HONGKONG;
            var destination = L.LONGBEACH;
            var cargo       = new Cargo(new TrackingId("XYZ"), new RouteSpecification(origin, destination, DateTime.Now));

            var itinerary = new Itinerary(
                Leg.DeriveLeg(SampleVoyages.pacific1, L.HONGKONG, L.TOKYO),
                Leg.DeriveLeg(SampleVoyages.pacific1, L.TOKYO, L.LONGBEACH)
                );

            cargo.AssignToRoute(itinerary);

            var dto = DTOAssembler.toDTO(cargo);

            Assert.AreEqual(2, dto.getLegs().Count());

            LegDTO legDTO = dto.getLegs().ElementAt(0);

            Assert.AreEqual("PAC1", legDTO.getVoyageNumber());
            Assert.AreEqual("CNHKG", legDTO.getFrom());
            Assert.AreEqual("JNTKO", legDTO.getTo());

            legDTO = dto.getLegs().ElementAt(1);
            Assert.AreEqual("PAC1", legDTO.getVoyageNumber());
            Assert.AreEqual("JNTKO", legDTO.getFrom());
            Assert.AreEqual("USLBG", legDTO.getTo());
        }
        public void IsExpected_ReceiveEvent_FirstLegLocationMathesEventLocation_True()
        {
            Itinerary     itinerary = new Itinerary(new[] { new Leg(null, Krakow, DateTime.Now, Warszawa, DateTime.Now) });
            HandlingEvent @event    = new HandlingEvent(HandlingEventType.Receive, Krakow, DateTime.Now, DateTime.Now);

            Assert.IsTrue(itinerary.IsExpected(@event));
        }
示例#13
0
        public Trip ItineraryToTrip(Itinerary itineray, int travelerId, string origin, string destination, string priorityCode, bool mobilityFlag, bool bicycleFlag)
        {
            Trip trip = new Trip();

            trip.Steps = new List <Step>();

            trip.Id            = 1;
            trip.TravelerId    = travelerId;
            trip.Origination   = origin;
            trip.Destination   = destination;
            trip.TripStartDate = itineray.startTime.ToDateTimeUTC();
            trip.TripEndDate   = itineray.endTime.ToDateTimeUTC();
            trip.PriorityCode  = priorityCode;
            trip.MobilityFlag  = mobilityFlag;
            trip.BicycleFlag   = bicycleFlag;

            int maxStringLength = 0;

            for (int i = 0; i < itineray.legs.Count; i++)
            {
                Step step = new Step();

                step.Id               = i + 1;
                step.TripId           = trip.Id;
                step.ModeId           = ModeType.StringToId(itineray.legs[i].mode);
                step.StartDate        = itineray.legs[i].startTime.ToDateTimeUTC();
                step.EndDate          = itineray.legs[i].endTime.ToDateTimeUTC();
                step.FromName         = itineray.legs[i].from.name;
                step.FromStopCode     = itineray.legs[i].from.stopCode;
                step.BlockIdentifier  = itineray.legs[i].tripBlockId;
                step.EncodedMapString = itineray.legs [i].legGeometry.points;

                if (step.EncodedMapString.Length > maxStringLength)
                {
                    maxStringLength = step.EncodedMapString.Length;
                }

                if (itineray.legs[i].from.stopId != null)
                {
                    step.FromProviderId = Providers.StringToId(itineray.legs[i].from.stopId.agencyId);
                }

                step.ToName     = itineray.legs[i].to.name;
                step.ToStopCode = itineray.legs[i].to.stopCode;

                if (itineray.legs[i].to.stopId != null)
                {
                    step.ToProviderId = Providers.StringToId(itineray.legs[i].to.stopId.agencyId);
                }

                step.Distance    = Convert.ToDecimal(itineray.legs[i].distance);
                step.RouteNumber = itineray.legs[i].routeShortName;

                trip.Steps.Add(step);
            }

            var x = maxStringLength;

            return(trip);
        }
示例#14
0
        public void ItineraryShouldNotBeAbleToModifyLegs()
        {
            var twoLegsStub = TwoLegsStub();
            var itinerary = new Itinerary(twoLegsStub);
            twoLegsStub.AddRange(twoLegsStub);

            var expectedTwoLegsStub = TwoLegsStub();
            Assert.AreEqual(expectedTwoLegsStub, itinerary.Legs);
        }
示例#15
0
 internal static RouteCandidateDTO toDTO(Itinerary itinerary)
 {
     var legDTOs = new List<LegDTO>(itinerary.Legs.Count());
     foreach(Leg leg in itinerary.Legs)
     {
         legDTOs.Add(toLegDTO(leg));
     }
     return new RouteCandidateDTO(legDTOs);
 }
        public void assignCargoToRoute(Itinerary itinerary, TrackingId trackingId)
        {
            var cargo = _cargoRepository.find(trackingId);
            Validate.notNull(cargo, "Can't assign itinerary to non-existing cargo " + trackingId);
            cargo.AssignToRoute(itinerary);
            _cargoRepository.store(cargo);

            _logger.Info("Assigned cargo " + trackingId + " to new route");
        }
 /// <summary>
 /// Assemble a Route Candidate DTO from provided Itinerary. 
 /// </summary>
 /// <param name="itinerary">itinerary</param>
 /// <returns>A route candidate DTO</returns>
 public RouteCandidateDTO ToDTO(Itinerary itinerary)
 {
     IList<LegDTO> legDTOs = new List<LegDTO>(itinerary.Legs.Count);
     foreach (Leg leg in itinerary.Legs)
     {
         legDTOs.Add(ToLegDTO(leg));
     }
     return new RouteCandidateDTO(legDTOs);
 }
示例#18
0
        public void ItineraryWithSamePropertiesShouldBeSame()
        {
            var twoLegsStub = TwoLegsStub();
            var itinerary = new Itinerary(twoLegsStub);
            var expectedItinerary = new Itinerary(twoLegsStub);

            Assert.AreEqual(expectedItinerary, itinerary);
            Assert.AreEqual(twoLegsStub, itinerary.Legs);
        }
        public void Itinerary_ShouldNotBeEqual_WithOtherItineraryWithDifferentLegs()
        {
            var option = new PricingOption { Price = 123m, QuoteAge = 1, AgentIds = { 12 } };

            var first = new Itinerary { OutboundLegId = "AAA", InboundLegId = "BBB", PricingOptions = { option } };
            var second = new Itinerary { OutboundLegId = "BBB", InboundLegId = "CCC", PricingOptions = { option } };

            var comparer = new ShallowEqualityComparer<Itinerary>();
            Assert.IsFalse(comparer.Equals(first, second));
        }
        public void Itinerary_ShouldNotBeEqual_IfPricingOptionWasAddedAndComparingDeep()
        {
            var option1 = new PricingOption { Price = 123m, QuoteAge = 1, AgentIds = { 12 } };
            var option2 = new PricingOption { Price = 456m, QuoteAge = 1, AgentIds = { 13 } };

            var first = new Itinerary { OutboundLegId = "AAA", InboundLegId = "BBB", PricingOptions = { option1 } };
            var second = new Itinerary { OutboundLegId = "AAA", InboundLegId = "BBB", PricingOptions = { option1, option2 } };

            Assert.IsFalse(((IInterimEquatable<Itinerary>)first).DeepEquals(second));
        }
示例#21
0
 protected void setUp()
 {
     routeSpecification = new RouteSpecification(L.HANGZOU, L.STOCKHOLM, DateTime.Parse("2008-11-03"));
     itinerary = new Itinerary(
         Leg.DeriveLeg(V.HONGKONG_TO_NEW_YORK, L.HANGZOU, L.NEWYORK),
         Leg.DeriveLeg(V.NEW_YORK_TO_DALLAS, L.NEWYORK, L.DALLAS),
         Leg.DeriveLeg(V.DALLAS_TO_HELSINKI, L.DALLAS, L.STOCKHOLM));
     delivery = Delivery.BeforeHandling();
     Thread.Sleep(1);
 }
        public void TestCargoOnTrack()
        {
            var trackingId = new TrackingId("CARGO1");
            var routeSpecification = new RouteSpecification(SampleLocations.SHANGHAI,
                                                                           SampleLocations.GOTHENBURG, dateTime);
            var cargo = new Cargo(trackingId, routeSpecification);

            var itinerary = new Itinerary(
                new List<Leg>
                    {
                        new Leg(voyage, SampleLocations.SHANGHAI, SampleLocations.ROTTERDAM, dateTime, dateTime),
                        new Leg(voyage, SampleLocations.ROTTERDAM, SampleLocations.GOTHENBURG, dateTime, dateTime)
                    });

            //Happy path
            var evnt = new HandlingEvent(cargo, dateTime, dateTime, HandlingType.RECEIVE,
                                                   SampleLocations.SHANGHAI);
            Assert.IsTrue(itinerary.IsExpected(evnt));

            evnt = new HandlingEvent(cargo, dateTime, dateTime, HandlingType.LOAD, SampleLocations.SHANGHAI, voyage);
            Assert.IsTrue(itinerary.IsExpected(evnt));

            evnt = new HandlingEvent(cargo, dateTime, dateTime, HandlingType.UNLOAD, SampleLocations.ROTTERDAM, voyage);
            Assert.IsTrue(itinerary.IsExpected(evnt));

            evnt = new HandlingEvent(cargo, dateTime, dateTime, HandlingType.LOAD, SampleLocations.ROTTERDAM, voyage);
            Assert.IsTrue(itinerary.IsExpected(evnt));

            evnt = new HandlingEvent(cargo, dateTime, dateTime, HandlingType.UNLOAD, SampleLocations.GOTHENBURG, voyage);
            Assert.IsTrue(itinerary.IsExpected(evnt));

            evnt = new HandlingEvent(cargo, dateTime, dateTime, HandlingType.CLAIM, SampleLocations.GOTHENBURG);
            Assert.IsTrue(itinerary.IsExpected(evnt));

            //Customs evnt changes nothing
            evnt = new HandlingEvent(cargo, dateTime, dateTime, HandlingType.CUSTOMS, SampleLocations.GOTHENBURG);
            Assert.IsTrue(itinerary.IsExpected(evnt));

            //Received at the wrong location
            evnt = new HandlingEvent(cargo, dateTime, dateTime, HandlingType.RECEIVE, SampleLocations.HANGZOU);
            Assert.IsFalse(itinerary.IsExpected(evnt));

            //Loaded to onto the wrong ship, correct location
            evnt = new HandlingEvent(cargo, dateTime, dateTime, HandlingType.LOAD, SampleLocations.ROTTERDAM,
                                     wrongVoyage);
            Assert.IsFalse(itinerary.IsExpected(evnt));

            //Unloaded from the wrong ship in the wrong location
            evnt = new HandlingEvent(cargo, dateTime, dateTime, HandlingType.UNLOAD, SampleLocations.HELSINKI,
                                     wrongVoyage);
            Assert.IsFalse(itinerary.IsExpected(evnt));

            evnt = new HandlingEvent(cargo, dateTime, dateTime, HandlingType.CLAIM, SampleLocations.ROTTERDAM);
            Assert.IsFalse(itinerary.IsExpected(evnt));
        }
        public void Itinerary_ShouldBeEqual_IfPricingOptionWasAddedAndComparingShallow()
        {
            var option1 = new PricingOption { Price = 123m, QuoteAge = 1, AgentIds = { 12 } };
            var option2 = new PricingOption { Price = 456m, QuoteAge = 1, AgentIds = { 13 } };

            var first = new Itinerary { OutboundLegId = "AAA", InboundLegId = "BBB", PricingOptions = { option1 } };
            var second = new Itinerary { OutboundLegId = "AAA", InboundLegId = "BBB", PricingOptions = { option1, option2 } };

            var comparer = new ShallowEqualityComparer<Itinerary>();
            Assert.IsTrue(comparer.Equals(first, second));
        }
示例#24
0
        public void testIfCargoIsOnTrack()
        {
            Itinerary itinerary = new Itinerary(Leg.DeriveLeg(voyage, L.SHANGHAI, L.ROTTERDAM),
                Leg.DeriveLeg(voyage, L.ROTTERDAM, L.GOTHENBURG));

            // HandlingActivity.Load(cargo, HandlingActivityType.RECEIVE, L.SHANGHAI, toDate("2009-05-03"))
            //Happy path
            HandlingActivity receiveShanghai = new HandlingActivity(HandlingActivityType.RECEIVE, L.SHANGHAI);
            Assert.IsTrue(itinerary.IsExpectedActivity(receiveShanghai));

            HandlingActivity loadShanghai = new HandlingActivity(HandlingActivityType.LOAD, L.SHANGHAI, voyage);
            Assert.IsTrue(itinerary.IsExpectedActivity(loadShanghai));

            HandlingActivity unloadRotterdam = new HandlingActivity(HandlingActivityType.UNLOAD, L.ROTTERDAM, voyage);
            Assert.IsTrue(itinerary.IsExpectedActivity(unloadRotterdam));

            HandlingActivity loadRotterdam = new HandlingActivity(HandlingActivityType.LOAD, L.ROTTERDAM, voyage);
            Assert.IsTrue(itinerary.IsExpectedActivity(loadRotterdam));

            HandlingActivity unloadGothenburg = new HandlingActivity(HandlingActivityType.UNLOAD, L.GOTHENBURG, voyage);
            Assert.IsTrue(itinerary.IsExpectedActivity(unloadGothenburg));

            HandlingActivity claimGothenburg = new HandlingActivity(HandlingActivityType.CLAIM, L.GOTHENBURG);
            Assert.IsTrue(itinerary.IsExpectedActivity(claimGothenburg));

            //TODO Customs event can only be interpreted properly by knowing the destination of the cargo.
            // This can be inferred from the Itinerary, but it isn't definitive. So, do we answer based on
            // the end of the itinerary (even though this would probably not be used in the app) or do we
            // ignore this at itinerary level somehow and leave it purely as a cargo responsibility.
            // (See customsClearancePoint tests in CargoTest)
            //    HandlingActivity customsGothenburg = new HandlingActivity(CUSTOMS, L.GOTHENBURG);
            //    Assert.IsTrue(itinerary.isExpectedActivity(customsGothenburg));

            //Received at the wrong location
            HandlingActivity receiveHangzou = new HandlingActivity(HandlingActivityType.RECEIVE, L.HANGZOU);
            Assert.IsFalse(itinerary.IsExpectedActivity(receiveHangzou));

            //Loaded to onto the wrong ship, correct location
            HandlingActivity loadRotterdam666 = new HandlingActivity(HandlingActivityType.LOAD, L.ROTTERDAM, wrongVoyage);
            Assert.IsFalse(itinerary.IsExpectedActivity(loadRotterdam666));

            //Unloaded from the wrong ship in the wrong location
            HandlingActivity unloadHelsinki = new HandlingActivity(HandlingActivityType.UNLOAD, L.HELSINKI, wrongVoyage);
            Assert.IsFalse(itinerary.IsExpectedActivity(unloadHelsinki));

            HandlingActivity claimRotterdam = new HandlingActivity(HandlingActivityType.CLAIM, L.ROTTERDAM);
            Assert.IsFalse(itinerary.IsExpectedActivity(claimRotterdam));
        }
示例#25
0
        public void testRoutingStatus()
        {
            Cargo cargo = new Cargo(new TrackingId("XYZ"),
                new RouteSpecification(L.STOCKHOLM, L.MELBOURNE, DateTime.Now));
            Itinerary good = new Itinerary(Leg.DeriveLeg(northernRail, L.SEATTLE, L.NEWYORK));
            Itinerary bad = new Itinerary(Leg.DeriveLeg(crazyVoyage, L.HAMBURG, L.HONGKONG));
            RouteSpecification acceptOnlyGood = new RouteSpecification(L.SEATTLE, L.NEWYORK, DateTime.Now);

            cargo.SpecifyNewRoute(acceptOnlyGood);
            Assert.AreEqual(RoutingStatus.NOT_ROUTED, cargo.RoutingStatus);

            cargo.AssignToRoute(bad);
            Assert.AreEqual(RoutingStatus.MISROUTED, cargo.RoutingStatus);

            cargo.AssignToRoute(good);
            Assert.AreEqual(RoutingStatus.ROUTED, cargo.RoutingStatus);
        }
        public void AssignCargoToRoute(Itinerary itinerary, TrackingId trackingId)
        {
            //TODO: Revise transaciton and UoW logic
            using (var transactionScope = new TransactionScope())
            {
                Cargo cargo = cargoRepository.Find(trackingId);
                if (cargo == null)
                {
                    throw new ArgumentException("Can't assign itinerary to non-existing cargo " + trackingId);
                }

                cargo.AssignToRoute(itinerary);
                cargoRepository.Store(cargo);

                transactionScope.Complete();
                logger.Info("Assigned cargo " + trackingId + " to new route");
            }
        }
示例#27
0
        public void toRouteCandidateDTO()
        {
            var itinerary = new Itinerary(
                Leg.DeriveLeg(SampleVoyages.pacific1, L.HONGKONG, L.TOKYO),
                Leg.DeriveLeg(SampleVoyages.pacific1, L.TOKYO, L.LONGBEACH)
                );

            var dto = DTOAssembler.toDTO(itinerary);

            Assert.AreEqual(2, dto.getLegs().Count());
            LegDTO legDTO = dto.getLegs().ElementAt(0);
            Assert.AreEqual("PAC1", legDTO.getVoyageNumber());
            Assert.AreEqual("CNHKG", legDTO.getFrom());
            Assert.AreEqual("JNTKO", legDTO.getTo());

            legDTO = dto.getLegs().ElementAt(1);
            Assert.AreEqual("PAC1", legDTO.getVoyageNumber());
            Assert.AreEqual("JNTKO", legDTO.getFrom());
            Assert.AreEqual("USLBG", legDTO.getTo());
        }
        public void setupCargo()
        {
            TrackingIdFactoryInMem trackingIdFactory = new TrackingIdFactoryInMem();

            // Creating new voyages to avoid rescheduling shared ones, breaking other tests
            voyage1 = new Voyage(new VoyageNumber("V1"), V.HONGKONG_TO_NEW_YORK.Schedule);
            voyage2 = new Voyage(new VoyageNumber("V2"), V.NEW_YORK_TO_DALLAS.Schedule);
            voyage3 = new Voyage(new VoyageNumber("V3"), V.DALLAS_TO_HELSINKI.Schedule);

            TrackingId trackingId = trackingIdFactory.nextTrackingId();
            RouteSpecification routeSpecification = new RouteSpecification(L.HANGZOU,
                L.STOCKHOLM,
                DateTime.Parse("2008-12-23"));

            cargo = new Cargo(trackingId, routeSpecification);
            Itinerary itinerary = new Itinerary(Leg.DeriveLeg(voyage1, L.HANGZOU, L.NEWYORK),
                Leg.DeriveLeg(voyage2, L.NEWYORK, L.DALLAS),
                Leg.DeriveLeg(voyage3, L.DALLAS, L.STOCKHOLM));
            cargo.AssignToRoute(itinerary);
        }
示例#29
0
        public void TestRoutingStatus()
        {       
            Cargo cargo = new Cargo(new TrackingId("XYZ"),
                                    new RouteSpecification(SampleLocations.STOCKHOLM, SampleLocations.MELBOURNE,
                                                           DateTime.Now));
            var good = new Itinerary();
            var bad = new Itinerary();

            RouteSpecification acceptOnlyGood = new RouteSpecificationStub(cargo.Origin,
                                                                           cargo.RouteSpecification.Destination,
                                                                           DateTime.Now, good);             
            cargo.SpecifyNewRoute(acceptOnlyGood);

            Assert.AreEqual(RoutingStatus.NOT_ROUTED, cargo.Delivery.RoutingStatus);

            cargo.AssignToRoute(bad);
            Assert.AreEqual(RoutingStatus.MISROUTED, cargo.Delivery.RoutingStatus);

            cargo.AssignToRoute(good);
            Assert.AreEqual(RoutingStatus.ROUTED, cargo.Delivery.RoutingStatus);
        }
示例#30
0
        private static string WriteItinerary(Itinerary itinerary)
        {
            var price = itinerary.PricingOptions.Min(o => o.Price);

            var outBound = itinerary.OutboundLeg.FlightInfos.First();
            var inBound = itinerary.InboundLeg.FlightInfos.First();

            return
                $"Price: {Currency.Default.FormatValue(price)} {Environment.NewLine}" +
                $" Outbound date: {itinerary.OutboundLeg.DepartureTime} {Environment.NewLine}" +
                $"  flight number: {outBound.Carrier.DisplayCode}{outBound.FlightNumber} {Environment.NewLine}" +
                $" Inbound date: {itinerary.InboundLeg.DepartureTime} {Environment.NewLine}" +
                $"  flight number: {inBound.Carrier.DisplayCode}{inBound.FlightNumber} {Environment.NewLine}";
        }
 protected void BookFlights(object sender, EventArgs e)
 {
     if ((flights.HasOutboundFlights && !HasOutboundFlight))
     {
         this.ValidationErrors.AddError("summary", new ErrorMessage("error.outboundFlight.required"));
     }
     if ((flights.HasReturnFlights && !HasReturnFlight))
     {
         this.ValidationErrors.AddError("summary", new ErrorMessage("error.returnFlight.required"));
     }
     if (this.ValidationErrors.IsEmpty)
     {
         FlightCollection flightsToBook = GetFlightsToBook();
         Itinerary itinerary = new Itinerary(flightsToBook);
         // TODO: forward to next logical page and get user details...
         ReservationConfirmation confirmation = bookingAgent.Book(
             new Reservation(new Passenger(1, "Aleksandar", "Seovic"), itinerary));
         Session[Constants.ReservationConfirmationKey] = confirmation;
         SetResult(ReservationConfirmed);
     }
 }
示例#32
0
        private Cargo setUpCargoWithItinerary(Location origin, Location midpoint, Location destination)
        {
            Cargo cargo = new Cargo(new TrackingId("CARGO1"), new RouteSpecification(origin, destination, DateTime.Now));

            Itinerary itinerary = new Itinerary(Leg.DeriveLeg(crazyVoyage, origin, midpoint),
                Leg.DeriveLeg(crazyVoyage, midpoint, destination));

            cargo.AssignToRoute(itinerary);
            return cargo;
        }
示例#33
0
        private Cargo shanghaiSeattleChicagoOnPacific2AndContinental3()
        {
            Cargo cargo = new Cargo(new TrackingId("CARGO1"),
                new RouteSpecification(L.SHANGHAI, L.CHICAGO, DateTime.Parse("2009-12-24")));

            // A cargo with no itinerary is not misdirected
            Assert.IsFalse(cargo.IsMisdirected);

            Itinerary itinerary = new Itinerary(Leg.DeriveLeg(V.pacific2, L.SHANGHAI, L.SEATTLE),
                Leg.DeriveLeg(V.continental3, L.SEATTLE, L.CHICAGO));
            cargo.AssignToRoute(itinerary);
            return cargo;
        }
示例#34
0
        public void testIsMisdirectedAfterRerouting()
        {
            Cargo cargo = shanghaiSeattleChicagoOnPacific2AndContinental3();

            cargo.Handled(HandlingActivity.LoadOnto(V.pacific2).In(L.SHANGHAI));
            Assert.IsFalse(cargo.IsMisdirected);

            // Cargo destination is changed by customer mid-route
            RouteSpecification newRouteSpec =
                cargo.RouteSpecification.WithOrigin(cargo.LastKnownLocation).WithDestination(L.NEWYORK);

            cargo.SpecifyNewRoute(newRouteSpec);
            // Misrouted, but not misdirected. Delivery is still accoring to plan (itinerary),
            // but not according to desire (route specification).
            Assert.IsFalse(cargo.IsMisdirected);
            Assert.IsTrue(cargo.RoutingStatus == RoutingStatus.MISROUTED);

            /**
     * This is a perfect example of how LegActivityMatch is a modelling breakthrough.
     * It allows us to easily construct an itinerary that completes the remainder of the
     * old itinerary and appends the new and different path.
     */
            Leg currentLeg = cargo.Itinerary.MatchLeg(cargo.MostRecentHandlingActivity).Leg;
            Itinerary newItinerary = new Itinerary(currentLeg, Leg.DeriveLeg(V.continental3, L.SEATTLE, L.NEWYORK));
            cargo.AssignToRoute(newItinerary);
            Assert.IsFalse(cargo.IsMisdirected);

            cargo.Handled(HandlingActivity.UnloadOff(V.pacific2).In(L.SEATTLE));
            Assert.IsFalse(cargo.IsMisdirected);

            cargo.Handled(HandlingActivity.LoadOnto(V.continental3).In(L.SEATTLE));
            Assert.IsFalse(cargo.IsMisdirected);

            cargo.Handled(HandlingActivity.UnloadOff(V.continental3).In(L.NEWYORK));
            Assert.IsFalse(cargo.IsMisdirected);
        }
示例#35
0
        public void testIsReadyToClaimWithDestinationSameAsCustomsClearancePoint()
        {
            Cargo cargo = new Cargo(new TrackingId("CARGO1"),
                new RouteSpecification(L.SHANGHAI, L.SEATTLE, DateTime.Parse("2009-12-24")));
            Itinerary itinerary = new Itinerary(Leg.DeriveLeg(V.pacific2, L.SHANGHAI, L.SEATTLE));
            cargo.AssignToRoute(itinerary);
            Assert.IsTrue(cargo.RouteSpecification.Destination.sameAs(cargo.CustomsClearancePoint));
            Assert.IsFalse(cargo.IsReadyToClaim);

            cargo.Handled(HandlingActivity.UnloadOff(V.pacific2).In(L.SEATTLE));
            Assert.IsFalse(cargo.IsReadyToClaim);

            cargo.Handled(HandlingActivity.CustomsIn(L.SEATTLE));
            Assert.IsTrue(cargo.IsReadyToClaim);

            cargo.Handled(HandlingActivity.ClaimIn(L.SEATTLE));
            Assert.IsFalse(cargo.IsReadyToClaim);
        }
示例#36
0
        public void testIsReadyToClaimWithDestinationDifferentFromCustomsClearancePoint()
        {
            Cargo cargo = new Cargo(new TrackingId("CARGO1"),
                new RouteSpecification(L.HONGKONG, L.NEWYORK, DateTime.Parse("2009-12-24")));
            Itinerary itinerary = new Itinerary(Leg.DeriveLeg(V.pacific1, L.HONGKONG, L.LONGBEACH),
                Leg.DeriveLeg(V.continental2, L.LONGBEACH, L.NEWYORK));
            cargo.AssignToRoute(itinerary);
            Assert.IsFalse(cargo.RouteSpecification.Destination.sameAs(cargo.CustomsClearancePoint));
            Assert.IsFalse(cargo.IsReadyToClaim);

            cargo.Handled(HandlingActivity.UnloadOff(V.pacific1).In(L.LONGBEACH));
            Assert.IsFalse(cargo.IsReadyToClaim);

            cargo.Handled(HandlingActivity.LoadOnto(V.continental2).In(L.LONGBEACH));
            Assert.IsFalse(cargo.IsReadyToClaim);

            cargo.Handled(HandlingActivity.UnloadOff(V.continental2).In(L.NEWYORK));
            Assert.IsTrue(cargo.IsReadyToClaim);
        }
示例#37
0
        private Cargo SetUpCargoWithItinerary(Location origin, Location midpoint, Location destination)
        {
            var cargo = new Cargo(new TrackingId("CARGO1"), new RouteSpecification(origin, destination, DateTime.Now));

            var itinerary = new Itinerary(
                new List<Leg>
                    {
                        new Leg(voyage, origin, midpoint, DateTime.Now, DateTime.Now),
                        new Leg(voyage, midpoint, destination, DateTime.Now, DateTime.Now)
                    });

            cargo.AssignToRoute(itinerary);
            return cargo;
        }
示例#38
0
 public RouteSpecificationStub(Location origin, Location destination, DateTime arrivalDeadline, Itinerary good) 
     : base(origin, destination, arrivalDeadline)
 {
     this.good = good;
 }
示例#39
0
 public override bool IsSatisfiedBy(Itinerary itinerary)
 {
     return itinerary == good;
 } 
示例#40
0
        public void ReplaceItinerary()
        {
            Cargo cargo = cargoRepository.Find(new TrackingId("FGH"));

            Assert.AreEqual(3L, GetLegCountFromDbByCargoId(cargo));

            Location legFrom = locationRepository.Find(new UnLocode("FIHEL"));
            Location legTo = locationRepository.Find(new UnLocode("DEHAM"));
            Itinerary newItinerary =
                new Itinerary(new List<Leg>
                                  {(new Leg(SampleVoyages.CM004, legFrom, legTo, new DateTime(), new DateTime()))});

            cargo.AssignToRoute(newItinerary);

            cargoRepository.Store(cargo);
            Flush();

            Assert.AreEqual(1L, GetLegCountFromDbByCargoId(cargo));
        }