public void TestIsSatisfiedByWrongDestination() { var routeSpecification = new RouteSpecification( SampleLocations.HONGKONG, SampleLocations.DALLAS, DateUtil.ToDate("2009-03-01")); Assert.IsFalse(routeSpecification.IsSatisfiedBy(itinerary)); }
public void setUp() { reportSubmission = MockRepository.GenerateMock<ReportSubmission>(); CargoRepository cargoRepository = new CargoRepositoryInMem(); HandlingEventRepository handlingEventRepository = new HandlingEventRepositoryInMem(); HandlingEventFactory handlingEventFactory = new HandlingEventFactory(cargoRepository, new VoyageRepositoryInMem(), new LocationRepositoryInMem()); TrackingId trackingId = new TrackingId("ABC"); RouteSpecification routeSpecification = new RouteSpecification(L.HONGKONG, L.ROTTERDAM, DateTime.Parse("2009-10-10")); Cargo cargo = new Cargo(trackingId, routeSpecification); cargoRepository.store(cargo); HandlingEvent handlingEvent = handlingEventFactory.createHandlingEvent( DateTime.Parse("2009-10-02"), trackingId, null, L.HONGKONG.UnLocode, HandlingActivityType.RECEIVE, new OperatorCode("ABCDE") ); handlingEventRepository.store(handlingEvent); cargo.Handled(handlingEvent.Activity); reportPusher = new ReportPusher(reportSubmission, cargoRepository, handlingEventRepository); eventSequenceNumber = handlingEvent.SequenceNumber; }
public void TestIsSatisfiedByMissedDeadline() { var routeSpecification = new RouteSpecification( SampleLocations.HONGKONG, SampleLocations.CHICAGO, DateUtil.ToDate("2009-02-15")); Assert.IsFalse(routeSpecification.IsSatisfiedBy(itinerary)); }
public IRoute GetRoute(RouteSpecification spec, RouteType routeType) { IRouteAlgorithm algorithm = this.factory.CreateAlgorithm(routeType); return algorithm.CalculateRoute(spec); }
public static Cargo NewCargo(TrackingId trackingId, Location origin, Location destination, DateTime arrivalDeadline) { var routeSpecification = new RouteSpecification(origin, destination, arrivalDeadline); return new Cargo(trackingId, routeSpecification); }
public void SolveType_Specification_finds_correct_route(Type expected, string route) { var specification = new RouteSpecification(route); var context = _Router.SolveType(specification); context.Type.Should().Be(expected); }
public void testCalculatePossibleRoutes() { TrackingId trackingId = new TrackingId("ABC"); RouteSpecification routeSpecification = new RouteSpecification(L.HONGKONG, L.HELSINKI, DateTime.Parse("2009-04-01")); Cargo cargo = new Cargo(trackingId, routeSpecification); var candidates = externalRoutingService.fetchRoutesForSpecification(routeSpecification); Assert.NotNull(candidates); foreach(Itinerary itinerary in candidates) { var legs = itinerary.Legs; Assert.NotNull(legs); Assert.True(legs.Any()); // Cargo origin and start of first leg should match Assert.AreEqual(cargo.RouteSpecification.Origin, legs.ElementAt(0).LoadLocation); // Cargo final destination and last leg stop should match Location lastLegStop = legs.Last().UnloadLocation; Assert.AreEqual(cargo.RouteSpecification.Destination, lastLegStop); for(int i = 0; i < legs.Count() - 1; i++) { // Assert that all legs are connected Assert.AreEqual(legs.ElementAt(i).UnloadLocation, legs.ElementAt(i + 1).LoadLocation); } } }
public IList <Itinerary> FetchRoutesForSpecification(RouteSpecification routeSpecification) { if (routeSpecification.Origin.Equals(SampleLocations.HONGKONG)) { var nsLegs = new List <Leg> { new Leg(SampleVoyages.v100, SampleLocations.HONGKONG, SampleLocations.NEWYORK, DateUtil.ToDate("2009-03-03"), DateUtil.ToDate("2009-03-09")), new Leg(SampleVoyages.v200, SampleLocations.NEWYORK, SampleLocations.CHICAGO, DateUtil.ToDate("2009-03-10"), DateUtil.ToDate("2009-03-14")), new Leg(SampleVoyages.v200, SampleLocations.CHICAGO, SampleLocations.STOCKHOLM, DateUtil.ToDate("2009-03-07"), DateUtil.ToDate("2009-03-11")) }; // Hongkong - NYC - Chicago - Stockholm, initial routing return(new List <Itinerary> { new Itinerary(nsLegs) }); } else { var tsLegs = new List <Leg> { new Leg(SampleVoyages.v300, SampleLocations.TOKYO, SampleLocations.HAMBURG, DateUtil.ToDate("2009-03-08"), DateUtil.ToDate("2009-03-12")), new Leg(SampleVoyages.v400, SampleLocations.HAMBURG, SampleLocations.STOCKHOLM, DateUtil.ToDate("2009-03-14"), DateUtil.ToDate("2009-03-15")) }; // Tokyo - Hamburg - Stockholm, rerouting misdirected cargo from Tokyo return(new List <Itinerary> { new Itinerary(tsLegs) }); } }
internal string TranslateRouteUrl(string cultureName, RouteSpecification routeSpec) { var key = routeSpec.RouteUrlTranslationKey ?? _keyGenerator.RouteUrl(routeSpec.AreaName, routeSpec.ControllerName, routeSpec.ActionName); return GetTranslation(key, cultureName); }
internal string TranslateAreaUrl(string cultureName, RouteSpecification routeSpec) { var key = routeSpec.AreaUrlTranslationKey ?? _keyGenerator.AreaUrl(routeSpec.AreaName); return GetTranslation(key, cultureName); }
public void TestIsSatisfiedByWrongOrigin() { var routeSpecification = new RouteSpecification( SampleLocations.HANGZOU, SampleLocations.CHICAGO, DateUtil.ToDate("2009-03-01")); Assert.IsFalse(routeSpecification.IsSatisfiedBy(itinerary)); }
public void TestCalculatePossibleRoutes() { var trackingId = new TrackingId("ABC"); var routeSpecification = new RouteSpecification(SampleLocations.HONGKONG, SampleLocations.HELSINKI, DateTime.Now); var cargo = new Cargo(trackingId, routeSpecification); voyageRepositoryMock.Setup(v => v.Find(It.IsAny<VoyageNumber>())).Returns(SampleVoyages.CM002); IList<Itinerary> candidates = externalRoutingService.FetchRoutesForSpecification(routeSpecification); Assert.IsNotNull(candidates); foreach (Itinerary itinerary in candidates) { IList<Leg> legs = itinerary.Legs; Assert.IsNotNull(legs); Assert.IsFalse(legs.IsEmpty()); // Cargo origin and start of first leg should match Assert.AreEqual(cargo.Origin, legs[0].LoadLocation); // Cargo final destination and last leg stop should match Location lastLegStop = legs[legs.Count - 1].UnloadLocation; Assert.AreEqual(cargo.RouteSpecification.Destination, lastLegStop); for (int i = 0; i < legs.Count - 1; i++) { // Assert that all legs are connected Assert.AreEqual(legs[i].UnloadLocation, legs[i + 1].LoadLocation); } } voyageRepositoryMock.Verify(); }
public void TestIsSatisfiedBySuccess() { var routeSpecification = new RouteSpecification( SampleLocations.HONGKONG, SampleLocations.CHICAGO, DateUtil.ToDate("2009-03-01")); Assert.IsTrue(routeSpecification.IsSatisfiedBy(itinerary)); }
public async void ImportJsonDataToDataBaseTest() { string testDataFile = @"TestData/route_with_all_parameters.json"; DataExchangeHelper dataExchange = new DataExchangeHelper(); using (StreamReader reader = new StreamReader(testDataFile)) { var jsonContent = reader.ReadToEnd(); reader.Close(); var importedRoute = dataExchange.ConvertSdkJsonContentToEntity <Route>(jsonContent, out string errorString); fixture._route4meDbContext.Routes.Add(importedRoute); await fixture._route4meDbContext.SaveChangesAsync(); string routeDbId = importedRoute.RouteDbId; var routeSpec = new RouteSpecification(routeDbId); var routeFromRepo = await fixture.r4mdbManager.RoutesRepository.GetByIdAsync(routeSpec); Assert.IsType <Route>(routeFromRepo); } }
public Cargo(TrackingId trackingId, RouteSpecification routeSpecification) { TrackingId = trackingId; RouteSpecification = routeSpecification; TransportStatus = TransportStatus.NotReceived; RoutingStatus = RoutingStatus.NotRouted; }
public void updateCargo() { TrackingId trackingId = trackingIdFactory.nextTrackingId(); RouteSpecification routeSpecification = new RouteSpecification(L.HONGKONG, L.GOTHENBURG, DateTime.Parse("2009-10-15")); Cargo cargo = new Cargo(trackingId, routeSpecification); cargoRepository.store(cargo); HandlingEvent handlingEvent = handlingEventFactory.createHandlingEvent(DateTime.Parse("2009-10-01 14:30"), cargo.TrackingId, V.HONGKONG_TO_NEW_YORK.VoyageNumber, L.HONGKONG.UnLocode, HandlingActivityType.LOAD, new OperatorCode("ABCDE")); handlingEventRepository.store(handlingEvent); Assert.That(handlingEvent.Activity, Is.Not.EqualTo(cargo.MostRecentHandlingActivity)); cargoUpdater.updateCargo(handlingEvent.SequenceNumber); Assert.That(handlingEvent.Activity, Is.EqualTo(cargo.MostRecentHandlingActivity)); Assert.True(handlingEvent.Activity != cargo.MostRecentHandlingActivity); systemEvents.AssertWasCalled(se => se.notifyOfCargoUpdate(cargo)); }
public void testIsSatisfiedBy_Success() { RouteSpecification routeSpecification = new RouteSpecification(L.HONGKONG, L.CHICAGO, DateTime.Parse("2009-03-01")); Assert.True(routeSpecification.IsSatisfiedBy(itinerary)); }
public static Itinerary FetchRoutesForSpecification(RouteSpecification routeSpecification) { // TODO Remove hard-coding here var leg = new Leg(Location.Location.HongKong, Location.Location.Dallas, new DateTime(2012, 11, 9), new DateTime(2012, 11, 12)); var legs = new List<Leg> { leg }; return new Itinerary(legs); }
public void testIsSatisfiedBy_WrongDestination() { RouteSpecification routeSpecification = new RouteSpecification(L.HONGKONG, L.DALLAS, DateTime.Parse("2009-03-01")); Assert.False(routeSpecification.IsSatisfiedBy(itinerary)); }
public void testIsSatisfiedBy_MissedDeadline() { RouteSpecification routeSpecification = new RouteSpecification(L.HONGKONG, L.CHICAGO, DateTime.Parse("2009-02-15")); Assert.False(routeSpecification.IsSatisfiedBy(itinerary)); }
public IRoute GetRoute(RouteSpecification spec, RouteType routeType) { IRouteAlgorithm algorithm = this.factory.CreateAlgorithm(routeType); return(algorithm.CalculateRoute(spec)); }
public void testIsSatisfiedBy_WrongOrigin() { RouteSpecification routeSpecification = new RouteSpecification(L.HANGZOU, L.CHICAGO, DateTime.Parse("2009-03-01")); Assert.False(routeSpecification.IsSatisfiedBy(itinerary)); }
// --- Support --- private Cargo setupCargoFromHongkongToStockholm() { TrackingId trackingId = trackingIdFactory.nextTrackingId(); DateTime arrivalDeadline = DateTime.Parse("2009-04-10"); RouteSpecification routeSpecification = new RouteSpecification(L.HONGKONG, L.STOCKHOLM, arrivalDeadline); return(new Cargo(trackingId, routeSpecification)); }
public IList <Itinerary> FetchRoutesForSpecification(RouteSpecification routeSpecification) { IList <TransitPath> paths = _graphTraversalService.FindShortestPaths( routeSpecification.Origin.UnLocode.CodeString, routeSpecification.Destination.UnLocode.CodeString, new Constraints(routeSpecification.ArrivalDeadline)); return(paths.Select(x => ToItinerary(x)).ToList()); }
public void ChangeDestination(TrackingId trackingId, UnLocode destinationUnLocode) { Cargo cargo = _cargoRepository.Find(trackingId); Location destination = _locationRepository.Find(destinationUnLocode); RouteSpecification routeSpecification = new RouteSpecification(cargo.RouteSpecification.Origin, destination, cargo.RouteSpecification.ArrivalDeadline); cargo.SpecifyNewRoute(routeSpecification); }
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 Ctor__NoItineraryGiven__RoutingStatusSetToNotRouted( RouteSpecification routeSpec ) { // ACT var sut = new Delivery(routeSpec, null, null); // ASSERT Assert.Equal(RoutingStatus.NotRouted, sut.RoutingStatus); }
public void Ctor__NoItinenaryGiven__IsMishandledSetToFalse( RouteSpecification routeSpec, HandlingEvent @event) { // ACT var sut = new Delivery(routeSpec, null, @event); // ASSERT Assert.False(sut.IsMishandled); }
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 Ctor__NoItineraryGiven__NextExpectedActivitySetToNone( RouteSpecification routeSpec , HandlingEvent @event) { // ACT var sut = new Delivery(routeSpec, null, @event); // ASSERT Assert.Null(sut.NextExpectedHandlingActivity); }
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 static Cargo createCargoWithDeliveryHistory(TrackingId trackingId, Location origin, Location destination, HandlingHistory handlingHistory) { RouteSpecification routeSpecification = new RouteSpecification(origin, destination, new DateTime()); Cargo cargo = new Cargo(trackingId, routeSpecification); cargo.DeriveDeliveryProgress(handlingHistory); return cargo; }
public void GetRouteReturnsCorrectRoute([Frozen]Mock<IRouteAlgorithmFactory> factoryStub, Mock<IRouteAlgorithm> routeAlgorithmStub, RouteSpecification specification, RouteType selectedAlgorithm, IRoute expectedResult, RouteController sut) { // Fixture setup factoryStub.Setup(f => f.CreateAlgorithm(selectedAlgorithm)).Returns(routeAlgorithmStub.Object); routeAlgorithmStub.Setup(a => a.CalculateRoute(specification)).Returns(expectedResult); // Exercise system var result = sut.GetRoute(specification, selectedAlgorithm); // Verify outcome Assert.Equal(expectedResult, result); // Teardown }
protected void setUp() { cargoRepository = MockRepository.GenerateMock<CargoRepository>(); voyageRepository = new VoyageRepositoryInMem(); locationRepository = new LocationRepositoryInMem(); factory = new HandlingEventFactory(cargoRepository, voyageRepository, locationRepository); trackingId = new TrackingId("ABC"); RouteSpecification routeSpecification = new RouteSpecification(L.TOKYO, L.HELSINKI, DateTime.Now); cargo = new Cargo(trackingId, routeSpecification); }
public void It_is_not_satisfied_if_destination_does_not_match() { var specification = new RouteSpecification(Krakow, Wroclaw, ArrivalDeadline); var itinerary = new Itinerary(new[] { new Leg(null, Krakow, new DateTime(2011, 12, 1), Warszawa, new DateTime(2011, 12, 2)) }); Assert.IsFalse(specification.IsSatisfiedBy(itinerary)); }
public static Cargo createCargoWithDeliveryHistory(TrackingId trackingId, Location origin, Location destination, HandlingHistory handlingHistory) { RouteSpecification routeSpecification = new RouteSpecification(origin, destination, new DateTime()); Cargo cargo = new Cargo(trackingId, routeSpecification); cargo.DeriveDeliveryProgress(handlingHistory); return(cargo); }
public void Ctor__RouteSpecGivenNotSatifiedByItineraryGiven__RoutingStatusSetToMisRouted( RouteSpecification routeSpec) { // ARRANGE var itinerary = new Fixture().Customize(new DefaultItineraryCustomization()).Create <Itinerary>(); // ACT var sut = new Delivery(routeSpec, itinerary, null); // ASSERT Assert.Equal(RoutingStatus.MisRouted, sut.RoutingStatus); }
public void Ctor__NoEventGiven__CurrentVoyageSetToNone( RouteSpecification routeSpec) { // ARRANGE var itinerary = new Fixture().Customize(new DefaultItineraryCustomization()).Create <Itinerary>(); // ACT var sut = new Delivery(routeSpec, itinerary, null); // ASSERT Assert.Null(sut.CurrentVoyage); }
protected void setUp() { cargoRepository = MockRepository.GenerateMock <CargoRepository>(); voyageRepository = new VoyageRepositoryInMem(); locationRepository = new LocationRepositoryInMem(); factory = new HandlingEventFactory(cargoRepository, voyageRepository, locationRepository); trackingId = new TrackingId("ABC"); RouteSpecification routeSpecification = new RouteSpecification(L.TOKYO, L.HELSINKI, DateTime.Now); cargo = new Cargo(trackingId, routeSpecification); }
public void Handle(BookNewCargoCommand message) { RouteSpecification routeSpecification = new RouteSpecification( new UnLocode(message.Origin), new UnLocode(message.Destination), message.ArrivalDeadline); TrackingId trackingId = _cargoRepository.NextTrackingId(); Cargo cargo = new Cargo(trackingId, routeSpecification); _cargoRepository.Store(cargo); }
public TrackingId BookNewCargo(UnLocode originUnLocode, UnLocode destinationUnLocode, DateTime arrivalDeadline) { Location origin = _locationRepository.Find(originUnLocode); Location destination = _locationRepository.Find(destinationUnLocode); RouteSpecification routeSpecification = new RouteSpecification(origin, destination, arrivalDeadline); TrackingId trackingId = _cargoRepository.NextTrackingId(); Cargo cargo = new Cargo(trackingId, routeSpecification); _cargoRepository.Store(cargo); return(trackingId); }
public void Ctor__RouteSpecNotSatisifiedByItinerary__NextExpectedActivitySetToNone( RouteSpecification routeSpec, HandlingEvent @event) { // ARRANGE var itinerary = new Fixture().Customize(new DefaultItineraryCustomization()).Create <Itinerary>(); // ACT var sut = new Delivery(routeSpec, itinerary, @event); // ASSERT Assert.Null(sut.NextExpectedHandlingActivity); }
public TrackingId BookNewCargo(string customerLogin, UnLocode originUnLocode, UnLocode destinationUnLocode, DateTime arrivalDeadline) { var origin = _locationRepository.Find(originUnLocode); var destination = _locationRepository.Find(destinationUnLocode); var customer = _customerRepository.Find(customerLogin); var routeSpecification = new RouteSpecification(origin, destination, arrivalDeadline); var trackingId = _cargoRepository.NextTrackingId(); var cargo = new Cargo(trackingId, routeSpecification, customer); _cargoRepository.Store(cargo); return(trackingId); }
public void testConstruction() { TrackingId trackingId = new TrackingId("XYZ"); DateTime arrivalDeadline = DateTime.Parse("2009-03-13"); RouteSpecification routeSpecification = new RouteSpecification(L.STOCKHOLM, L.MELBOURNE, arrivalDeadline); Cargo cargo = new Cargo(trackingId, routeSpecification); Assert.AreEqual(RoutingStatus.NOT_ROUTED, cargo.RoutingStatus); Assert.AreEqual(TransportStatus.NOT_RECEIVED, cargo.TransportStatus); Assert.AreEqual(Location.None, cargo.LastKnownLocation); Assert.AreEqual(Voyage.None, cargo.CurrentVoyage); }
private IEnumerable <Itinerary> GetAllPossibleRoutes(RouteSpecification routeSpecification) { IList <Voyage> voyages = _voyageRepository.FindBeginingBefore(routeSpecification.ArrivalDeadline); IList <TransitEdge> graph = voyages.SelectMany(v => v.Schedule.CarrierMovements.Select(m => ToEdge(v, m))).ToList(); var allPaths = _graphTraversalService.FindPaths( routeSpecification.Origin.UnLocode.CodeString, routeSpecification.Destination.UnLocode.CodeString, graph, new Constraints(routeSpecification.ArrivalDeadline)); return(allPaths.Select(x => ToItinerary(x))); }
public void CargoIsInitializedCorrectly() { var cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(Location.Location.HongKong, Location.Location.Dallas)); var expectedRouteSpecification = new RouteSpecification(Location.Location.HongKong, Location.Location.Dallas); Assert.AreEqual(new TrackingId("XYZ"), cargo.TrackingId); Assert.AreEqual(expectedRouteSpecification, cargo.RouteSpecification); Assert.AreEqual(TransportStatus.NotReceived, cargo.TransportStatus); Assert.AreEqual(RoutingStatus.NotRouted, cargo.RoutingStatus); }
public void Ctor__EventGiven__LastKnownLocationIsSetToTheEventLocation( RouteSpecification routeSpec , HandlingEvent @event) { // ARRANGE var itinerary = new Fixture().Customize(new DefaultItineraryCustomization()).Create <Itinerary>(); // ACT var sut = new Delivery(routeSpec, itinerary, @event); // ASSERT Assert.Equal(@event.Location, sut.LastKnownLocation); }
public void Ctor__EventWithAVoyageNumber__CurrentVoyageIsSetToEventVoyage( RouteSpecification routeSpec , HandlingEvent @event) { // ARRANGE var itinerary = new Fixture().Customize(new DefaultItineraryCustomization()).Create <Itinerary>(); // ACT var sut = new Delivery(routeSpec, itinerary, @event); // ASSERT Assert.Equal(@event.Voyage, sut.CurrentVoyage); }
public TrackingId bookNewCargo(UnLocode originUnLocode, UnLocode destinationUnLocode, DateTime arrivalDeadline) { var trackingId = _trackingIdFactory.nextTrackingId(); var origin = _locationRepository.find(originUnLocode); var destination = _locationRepository.find(destinationUnLocode); var routeSpecification = new RouteSpecification(origin, destination, arrivalDeadline); var cargo = new Cargo(trackingId, routeSpecification); _cargoRepository.store(cargo); _logger.Info("Booked new cargo with tracking id " + cargo.TrackingId.Value); return cargo.TrackingId; }
public void Ctor__EmitsNewBookEvent( TrackingId trackingId, RouteSpecification routeSpec ) { // ACT var sut = new Domain.Shipping.Cargo.Cargo(trackingId, routeSpec); // ASSERT Assert.Equal(routeSpec, sut.RouteSpec); Assert.Equal(routeSpec, sut.Delivery.RouteSpec); sut.Events[0].Should().BeEquivalentTo(new Events.NewBooked(trackingId, routeSpec)); }
public void TestConstruction() { var trackingId = new TrackingId("XYZ"); var arrivalDeadline = DateUtil.ToDate("2009-03-13"); var routeSpecification = new RouteSpecification( SampleLocations.STOCKHOLM, SampleLocations.MELBOURNE, arrivalDeadline); Cargo cargo = new Cargo(trackingId, routeSpecification); Assert.AreEqual(RoutingStatus.NOT_ROUTED, cargo.Delivery.RoutingStatus); Assert.AreEqual(TransportStatus.NOT_RECEIVED, cargo.Delivery.TransportStatus); Assert.AreEqual(Location.UNKNOWN, cargo.Delivery.LastKnownLocation); Assert.AreEqual(Voyage.NONE, cargo.Delivery.CurrentVoyage); }
protected void SetUp() { cargoRepositoryMock = new Mock<ICargoRepository>(); cargoRepository = cargoRepositoryMock.Object; voyageRepository = new VoyageRepositoryInMem(); locationRepository = new LocationRepositoryInMem(); factory = new HandlingEventFactory(cargoRepository, voyageRepository, locationRepository); trackingId = new TrackingId("ABC"); var routeSpecification = new RouteSpecification(SampleLocations.TOKYO, SampleLocations.HELSINKI, DateTime.Now); cargo = new Cargo(trackingId, routeSpecification); }
public void testEquals() { RouteSpecification HKG_DAL = new RouteSpecification(L.HONGKONG, L.DALLAS, DateTime.Parse("2009-03-01")); RouteSpecification HKG_DAL_AGAIN = new RouteSpecification(L.HONGKONG, L.DALLAS, DateTime.Parse("2009-03-01")); RouteSpecification SHA_DAL = new RouteSpecification(L.SHANGHAI, L.DALLAS, DateTime.Parse("2009-03-01")); RouteSpecification HKG_CHI = new RouteSpecification(L.HONGKONG, L.CHICAGO, DateTime.Parse("2009-03-01")); RouteSpecification HKG_DAL_LATERARRIVAL = new RouteSpecification(L.HONGKONG, L.DALLAS, DateTime.Parse("2009-03-15")); Assert.AreEqual(HKG_DAL, HKG_DAL_AGAIN); Assert.False(HKG_DAL.Equals(SHA_DAL)); Assert.False(HKG_DAL.Equals(HKG_CHI)); Assert.False(HKG_DAL.Equals(HKG_DAL_LATERARRIVAL)); }
public IEnumerable<Itinerary> fetchRoutesForSpecification(RouteSpecification routeSpecification) { /* The RouteSpecification is picked apart and adapted to the external API. */ var origin = routeSpecification.Origin; var destination = routeSpecification.Destination; var limitations = new Hashtable(); limitations.Add("DEADLINE", routeSpecification.ArrivalDeadline.ToString()); IEnumerable<TransitPath> transitPaths; try { transitPaths = graphTraversalService.findShortestPath( origin.UnLocode.Value, destination.UnLocode.Value, limitations ); } catch(Exception e) { log.Error(e, e); return new List<Itinerary>(); } /* The returned result is then translated back into our domain model. */ var itineraries = new List<Itinerary>(); foreach(TransitPath transitPath in transitPaths) { var itinerary = toItinerary(transitPath); // Use the specification to safe-guard against invalid itineraries if(routeSpecification.IsSatisfiedBy(itinerary)) { itineraries.Add(itinerary); } else { log.Warn("Received itinerary that did not satisfy the route specification"); } } return itineraries; }