コード例 #1
0
        public void RegisterHandlingEvent(DateTime completionTime,
                                          TrackingId trackingId,
                                          VoyageNumber voyageNumber,
                                          UnLocode unLocode,
                                          HandlingType type)
        {
            //TODO: Revise transaciton and UoW logic
            using (var transactionScope = new TransactionScope())
            {
                var registrationTime = new DateTime();

                /* Using a factory to create a HandlingEvent (aggregate). This is where
                 * it is determined wether the incoming data, the attempt, actually is capable
                 * of representing a real handling event. */
                HandlingEvent evnt = handlingEventFactory.CreateHandlingEvent(
                    registrationTime, completionTime, trackingId, voyageNumber, unLocode, type);

                /* Store the new handling event, which updates the persistent
                 * state of the handling event aggregate (but not the cargo aggregate -
                 * that happens asynchronously!)*/

                handlingEventRepository.Store(evnt);

                /* Publish an event stating that a cargo has been handled. */
                applicationEvents.CargoWasHandled(evnt);

                transactionScope.Complete();
            }
            logger.Info("Registered handling event");
        }
コード例 #2
0
        public void InspectCargo(TrackingId trackingId)
        {
            Validate.NotNull(trackingId, "Tracking ID is required");
            Cargo cargo;
            using (var transactionScope = new TransactionScope())
            {
                cargo = cargoRepository.Find(trackingId);


                if (cargo == null)
                {
                    logger.Warn("Can't inspect non-existing cargo " + trackingId);
                    return;
                }

                HandlingHistory handlingHistory = handlingEventRepository.LookupHandlingHistoryOfCargo(trackingId);

                cargo.DeriveDeliveryProgress(handlingHistory);

                if (cargo.Delivery.IsMisdirected)
                {
                    applicationEvents.CargoWasMisdirected(cargo);
                }

                if (cargo.Delivery.IsUnloadedAtDestination)
                {
                    applicationEvents.CargoHasArrived(cargo);
                }

                cargoRepository.Store(cargo);
                transactionScope.Complete();
            }
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        public void RegisterHandlingEvent(DateTime completionTime,
                                          TrackingId trackingId,
                                          VoyageNumber voyageNumber,
                                          UnLocode unLocode,
                                          HandlingType type)
        {
            //TODO: Revise transaciton and UoW logic
            using (var transactionScope = new TransactionScope())
            {
                var registrationTime = new DateTime();

                /* Using a factory to create a HandlingEvent (aggregate). This is where
               it is determined wether the incoming data, the attempt, actually is capable
               of representing a real handling event. */
                HandlingEvent evnt = handlingEventFactory.CreateHandlingEvent(
                    registrationTime, completionTime, trackingId, voyageNumber, unLocode, type);

                /* Store the new handling event, which updates the persistent
                   state of the handling event aggregate (but not the cargo aggregate -
                   that happens asynchronously!)*/

                handlingEventRepository.Store(evnt);

                /* Publish an event stating that a cargo has been handled. */
                applicationEvents.CargoWasHandled(evnt);

                transactionScope.Complete();
            }
            logger.Info("Registered handling event");
        }
コード例 #5
0
        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();
        }
コード例 #6
0
        public void SearchNoExistingCargoTest()
        {
            //Arrange
            var cargoRepositoryMock = new Mock<ICargoRepository>();
            var handlingEventRepositoryMock = new Mock<IHandlingEventRepository>();
            var controllerMock = new Mock<CargoTrackingController>(cargoRepositoryMock.Object,
                                                                   handlingEventRepositoryMock.Object);
            var controller = controllerMock.Object;

            const string trackingIdStr = "trackId";
            var trackingId = new TrackingId(trackingIdStr);
            cargoRepositoryMock.Setup(m => m.Find(trackingId)).Returns((Cargo)null).Verifiable();

            //Act
            var viewModel = controller.Search(new TrackCommand { TrackingId = trackingIdStr })
                .GetModel<CargoTrackingViewAdapter>();

            //Assert
            //Verify expected method calls
            cargoRepositoryMock.Verify();
            handlingEventRepositoryMock.Verify();
            Assert.IsNull(viewModel);
            //Verfy if warning message is set to UI
            controllerMock.Verify(m => m.SetMessage(It.Is<string>(s => s == CargoTrackingController.UnknownMessageId)), Times.Once());
            //Verify that the method is not invoked
            handlingEventRepositoryMock.Verify(m => m.LookupHandlingHistoryOfCargo(It.IsAny<TrackingId>()), Times.Never());
        }
コード例 #7
0
 public Cargo find(TrackingId tid)
 {
     return sessionFactory.GetCurrentSession().
       CreateQuery("from Cargo where TrackingId = :tid").
       SetParameter("tid", tid).
       UniqueResult<Cargo>();
 }
コード例 #8
0
        public void Ctor_01()
        {
            // arrange:
            UnLocode   final     = new UnLocode("FINAL");
            TrackingId id        = new TrackingId("CLAIM");
            IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>();

            itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow).Repeat.AtLeastOnce();
            itinerary.Expect(i => i.FinalArrivalLocation).Return(final).Repeat.AtLeastOnce();
            IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>();

            specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any();
            CargoState previousState = MockRepository.GenerateStrictMock <CargoState>(id, specification);

            previousState = MockRepository.GenerateStrictMock <CargoState>(previousState, itinerary);
            previousState.Expect(s => s.IsUnloadedAtDestination).Return(true).Repeat.AtLeastOnce();
            previousState.Expect(s => s.TransportStatus).Return(TransportStatus.InPort).Repeat.AtLeastOnce();
            DateTime claimDate = DateTime.UtcNow;


            // act:
            ClaimedCargo state = new ClaimedCargo(previousState, claimDate);

            // assert:
            Assert.AreEqual(TransportStatus.Claimed, state.TransportStatus);
            Assert.AreEqual(RoutingStatus.Routed, state.RoutingStatus);
            Assert.AreSame(final, state.LastKnownLocation);
            Assert.AreSame(specification, state.RouteSpecification);
            Assert.IsNull(state.CurrentVoyage);
            Assert.IsTrue(state.IsUnloadedAtDestination);
            itinerary.VerifyAllExpectations();
            specification.VerifyAllExpectations();
            previousState.VerifyAllExpectations();
        }
コード例 #9
0
 public Cargo Find(TrackingId tid)
 {
     return((Cargo)Session.
            CreateQuery("from Cargo as c where c.trackingId.id = :tid").
            SetParameter("tid", tid.IdString).
            UniqueResult());
 }
コード例 #10
0
        public void TrackingIdShouldBeValueObject()
        {
            var trackingId = new TrackingId("XYZ");

            Assert.AreEqual(new TrackingId("XYZ"), trackingId);
            Assert.AreNotEqual(new TrackingId("ABC"), trackingId);
        }
コード例 #11
0
        public void InspectCargo(TrackingId trackingId)
        {
            Validate.NotNull(trackingId, "Tracking ID is required");
            Cargo cargo;

            using (var transactionScope = new TransactionScope())
            {
                cargo = cargoRepository.Find(trackingId);


                if (cargo == null)
                {
                    logger.Warn("Can't inspect non-existing cargo " + trackingId);
                    return;
                }

                HandlingHistory handlingHistory = handlingEventRepository.LookupHandlingHistoryOfCargo(trackingId);

                cargo.DeriveDeliveryProgress(handlingHistory);

                if (cargo.Delivery.IsMisdirected)
                {
                    applicationEvents.CargoWasMisdirected(cargo);
                }

                if (cargo.Delivery.IsUnloadedAtDestination)
                {
                    applicationEvents.CargoHasArrived(cargo);
                }

                cargoRepository.Store(cargo);
                transactionScope.Complete();
            }
        }
コード例 #12
0
        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);
                }
            }
        }
コード例 #13
0
		public void Ctor_01()
		{
			// arrange:
			GList mocks = new GList();
			TrackingId id = new TrackingId("START");
			DateTime loadTime = DateTime.Now;
			VoyageNumber voyageNumber = new VoyageNumber("VYG001");
			UnLocode location = new UnLocode("CURLC");
            IItinerary itinerary = MockRepository.GenerateStrictMock<IItinerary>();
            itinerary.Expect(i => i.Equals(null)).IgnoreArguments().Return(false).Repeat.Any();
            itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow + TimeSpan.FromDays(1)).Repeat.Any();
            itinerary.Expect(i => i.FinalArrivalLocation).Return(new UnLocode("ENDLC")).Repeat.Any();
            mocks.Add(itinerary);
            IRouteSpecification specification = MockRepository.GenerateStrictMock<IRouteSpecification>();
            specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any();
            CargoState previousState = MockRepository.GenerateStrictMock<CargoState>(id, specification);
            mocks.Add(previousState);
            previousState = MockRepository.GenerateStrictMock<CargoState>(previousState, itinerary);
            mocks.Add(previousState);
			IVoyage voyage = MockRepository.GenerateStrictMock<IVoyage>();
			voyage.Expect(v => v.Number).Return(voyageNumber).Repeat.AtLeastOnce();
			voyage.Expect(v => v.LastKnownLocation).Return(location).Repeat.AtLeastOnce();
			mocks.Add(voyage);
			
			// act:
			CargoState state = new OnboardCarrierCargo(previousState, voyage, loadTime);
		
			// assert:
			Assert.IsNotNull(state);
			Assert.AreSame(voyageNumber, state.CurrentVoyage);
			Assert.AreEqual(TransportStatus.OnboardCarrier, state.TransportStatus);
			Assert.AreSame(location, state.LastKnownLocation);
			foreach(object mock in mocks)
				mock.VerifyAllExpectations();
		}
コード例 #14
0
        public void testSave()
        {
            var unLocode = new UnLocode("SESTO");

            var           trackingId     = new TrackingId("XYZ");
            var           completionTime = DateTime.Parse("2008-01-01");
            HandlingEvent @event         = HandlingEventFactory.createHandlingEvent(completionTime,
                                                                                    trackingId,
                                                                                    null,
                                                                                    unLocode,
                                                                                    HandlingActivityType.CLAIM,
                                                                                    null);

            HandlingEventRepository.store(@event);

            flush();

            var result = GenericTemplate.QueryForObjectDelegate(CommandType.Text,
                                                                String.Format("select * from HandlingEvent where sequence_number = {0}", @event.SequenceNumber),
                                                                (r, i) => new { CARGO_ID = r["CARGO_ID"], COMPLETIONTIME = r["COMPLETIONTIME"] });

            Assert.AreEqual(1L, result.CARGO_ID);
            Assert.AreEqual(completionTime, result.COMPLETIONTIME);
            // TODO: the rest of the columns
        }
コード例 #15
0
ファイル: InPortCargoQA.cs プロジェクト: hungdluit/Epic.NET
        public void Ctor_02()
        {
            // arrange:
            List<object> mocks = new List<object>();

            UnLocode code = new UnLocode("START");
            DateTime arrival = DateTime.UtcNow;
            TrackingId id = new TrackingId("CARGO01");
            IItinerary itinerary = MockRepository.GenerateStrictMock<IItinerary>();
            itinerary.Expect(i => i.Equals(null)).IgnoreArguments().Return(false).Repeat.Any();
            itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow + TimeSpan.FromDays(1)).Repeat.Any();
            itinerary.Expect(i => i.FinalArrivalLocation).Return(code).Repeat.Any();
            mocks.Add(itinerary);
            IRouteSpecification specification = MockRepository.GenerateStrictMock<IRouteSpecification>();
            specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any();
            mocks.Add(specification);
            CargoState previousState = MockRepository.GenerateStrictMock<CargoState>(id, specification);
            mocks.Add(previousState);
            previousState = MockRepository.GenerateStrictMock<CargoState>(previousState, itinerary);
            mocks.Add(previousState);
            previousState.Expect(s => s.LastKnownLocation).Return(code).Repeat.Any();

            // act:
            InPortCargo state = new InPortCargo(previousState, code, arrival);

            // assert:
            Assert.IsTrue(TransportStatus.InPort == state.TransportStatus);
			Assert.IsNull(state.CurrentVoyage);
            Assert.AreSame(code, state.LastKnownLocation);
            Assert.IsTrue(state.IsUnloadedAtDestination);
            Assert.AreSame(id, state.Identifier);
            foreach (object mock in mocks)
                mock.VerifyAllExpectations();
        }
コード例 #16
0
        public void testSave()
        {
            var unLocode = new UnLocode("SESTO");

            var trackingId = new TrackingId("XYZ");
            var completionTime = DateTime.Parse("2008-01-01");
            HandlingEvent @event = HandlingEventFactory.createHandlingEvent(completionTime,
                trackingId,
                null,
                unLocode,
                HandlingActivityType.CLAIM,
                null);

            HandlingEventRepository.store(@event);

            flush();

            var result = GenericTemplate.QueryForObjectDelegate(CommandType.Text,
                String.Format("select * from HandlingEvent where sequence_number = {0}", @event.SequenceNumber),
                (r, i) => new {CARGO_ID = r["CARGO_ID"], COMPLETIONTIME = r["COMPLETIONTIME"]});

            Assert.AreEqual(1L, result.CARGO_ID);
            Assert.AreEqual(completionTime, result.COMPLETIONTIME);
            // TODO: the rest of the columns
        }
コード例 #17
0
        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;
        }
コード例 #18
0
        public static Cargo NewCargo(TrackingId trackingId, Location origin, Location destination,
                                     DateTime arrivalDeadline)
        {           

            var routeSpecification = new RouteSpecification(origin, destination, arrivalDeadline);
            return new Cargo(trackingId, routeSpecification);
        }
コード例 #19
0
        public void Equals_onDifferentVoyage_isFalse_02()
        {
            // arrange:
            DateTime   arrivalDate = DateTime.Now + TimeSpan.FromDays(30);
            TrackingId identifier  = new TrackingId("CARGO01");
            IItinerary itinerary   = MockRepository.GenerateStrictMock <IItinerary>();

            itinerary.Expect(i => i.Equals(null)).Return(false).Repeat.Any();
            itinerary.Expect(i => i.FinalArrivalDate).Return(arrivalDate).Repeat.Any();
            itinerary.Expect(i => i.Equals(itinerary)).Return(true).Repeat.Any();
            IRouteSpecification route = MockRepository.GenerateStrictMock <IRouteSpecification>();

            route.Expect(s => s.Equals(route)).Return(true).Repeat.Any();
            route.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any();
            FakeState state1 = new FakeState(identifier, route);

            state1 = new FakeState(state1, itinerary);
            state1._currentVoyage = null;
            FakeState state2 = new FakeState2(identifier, route);

            state2 = new FakeState(state2, itinerary);

            // act:

            // assert:
            Assert.IsFalse(state1.Equals(state2));
        }
コード例 #20
0
        /// <summary>
        /// Creates a handling event.
        /// </summary>
        /// <param name="completionTime">when the event was completed, for example finished loading</param>
        /// <param name="trackingId">cargo tracking id</param>
        /// <param name="voyageNumber">voyage number</param>
        /// <param name="unlocode">United Nations Location Code for the location of the event</param>
        /// <param name="type">type of event</param>
        /// <param name="operatorCode">operator code</param>
        /// <returns>A handling event.</returns>
        /// <exception cref="UnknownVoyageException">if there's no voyage with this number</exception>
        /// <exception cref="UnknownCargoException">if there's no cargo with this tracking id</exception>
        /// <exception cref="UnknownLocationException">if there's no location with this UN Locode</exception>
        public HandlingEvent createHandlingEvent(DateTime completionTime, TrackingId trackingId,
                                                 VoyageNumber voyageNumber, UnLocode unlocode,
                                                 HandlingActivityType type, OperatorCode operatorCode)
        {
            var cargo    = findCargo(trackingId);
            var voyage   = findVoyage(voyageNumber);
            var location = findLocation(unlocode);

            try
            {
                var registrationTime = DateTime.Now;
                if (voyage == null)
                {
                    return(new HandlingEvent(cargo, completionTime, registrationTime, type, location));
                }
                else
                {
                    return(new HandlingEvent(cargo, completionTime, registrationTime, type, location, voyage, operatorCode));
                }
            }
            catch (Exception e)
            {
                throw new CannotCreateHandlingEventException(e.Message, e);
            }
        }
コード例 #21
0
        public void Equals_withDifferentItineraries_isFalse()
        {
            // arrange:
            DateTime   arrivalDate = DateTime.Now + TimeSpan.FromDays(30);
            TrackingId identifier  = new TrackingId("CARGO01");
            IItinerary itinerary   = MockRepository.GenerateStrictMock <IItinerary>();

            itinerary.Expect(i => i.Equals(null)).Return(false).Repeat.Any();
            itinerary.Expect(i => i.FinalArrivalDate).Return(arrivalDate).Repeat.Any();
            IRouteSpecification route = MockRepository.GenerateStrictMock <IRouteSpecification>();

            route.Expect(s => s.Equals(route)).Return(true).Repeat.Any();
            route.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any();
            FakeState state1 = new FakeState(identifier, route);

            state1 = new FakeState(state1, itinerary);
            state1._lastKnownLocation = new Challenge00.DDDSample.Location.UnLocode("TESTA");
            FakeState state2 = new FakeState2(identifier, route);

            state2._lastKnownLocation = new Challenge00.DDDSample.Location.UnLocode("TESTA");

            // act:

            // assert:
            Assert.IsFalse(state1.Equals(state2));
        }
コード例 #22
0
        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);
                }
            }
        }
コード例 #23
0
ファイル: EventQA.cs プロジェクト: hungdluit/Epic.NET
		public void Ctor_withValidArgs_works(EventType type)
		{
			// arrange:
			List<object> mocks = new List<object>();
			Username userId = new Username("Giacomo");
			IUser user = MockRepository.GenerateStrictMock<IUser>();
			user.Expect(u => u.Username).Return(userId).Repeat.Once();
			mocks.Add(user);
			TrackingId cargoId = new TrackingId("CARGO001");
			UnLocode location = new UnLocode("UNLOC");
			VoyageNumber voyage = new VoyageNumber("VYG001");
			ICargo cargo = MockRepository.GenerateStrictMock<ICargo>();
			cargo.Expect(c => c.TrackingId).Return(cargoId).Repeat.Once();
			IDelivery delivery = MockRepository.GenerateStrictMock<IDelivery>();
			delivery.Expect(d => d.LastKnownLocation).Return(location).Repeat.Once();
			delivery.Expect(d => d.CurrentVoyage).Return(voyage).Repeat.Once();
			mocks.Add(delivery);
			cargo.Expect(c => c.Delivery).Return(delivery).Repeat.Twice();
			mocks.Add(cargo);
			DateTime completionDate = DateTime.UtcNow;
			
			// act:
			IEvent underTest = new Event(user, cargo, type, completionDate);
		
			// assert:
			Assert.AreSame(userId, underTest.User);
			Assert.AreSame(cargoId, underTest.Cargo);
			Assert.AreSame(location, underTest.Location);
			Assert.AreSame(voyage, underTest.Voyage);
			Assert.AreEqual(completionDate, underTest.Date);
			Assert.AreEqual(type, underTest.Type);
			foreach(object mock in mocks)
				mock.VerifyAllExpectations();
		}
コード例 #24
0
 public void FindEventsForCargo()
 {
     var trackingId = new TrackingId("XYZ");
     IList<HandlingEvent> handlingEvents =
         handlingEventRepository.LookupHandlingHistoryOfCargo(trackingId).DistinctEventsByCompletionTime();
     Assert.AreEqual(12, handlingEvents.Count);
 }
コード例 #25
0
        public void reportCargoUpdate(TrackingId trackingId)
        {
            Cargo cargo = cargoRepository.find(trackingId);
            CargoDetails cargoDetails = assembleFrom(cargo);

            reportSubmission.submitCargoDetails(cargoDetails);
        }
コード例 #26
0
        protected void SetUp()
        {
            var trackingId         = new TrackingId("XYZ");
            var routeSpecification = new RouteSpecification(SampleLocations.HONGKONG, SampleLocations.NEWYORK, new DateTime());

            cargo = new Cargo(trackingId, routeSpecification);
        }
コード例 #27
0
ファイル: NewCargoQA.cs プロジェクト: dmitribodiu/Epic.NET
        public void AssignToRoute_03()
        {
            // arrange:
            TrackingId id            = new TrackingId("CRG01");
            IItinerary itinerary     = MockRepository.GenerateStrictMock <IItinerary>();
            DateTime   finalArrival1 = DateTime.Now + TimeSpan.FromDays(30);

            itinerary.Expect(i => i.Equals(null)).Return(false).Repeat.AtLeastOnce();
            itinerary.Expect(i => i.FinalArrivalDate).Return(finalArrival1).Repeat.AtLeastOnce();
            IItinerary itinerary2 = MockRepository.GenerateStrictMock <IItinerary>();

            itinerary2.Expect(i => i.Equals(itinerary)).Return(true).Repeat.AtLeastOnce();
            IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>();

            specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Once();
            CargoState initialState = new NewCargo(id, specification);
            CargoState state        = initialState.AssignToRoute(itinerary);

            // act:
            CargoState newState = state.AssignToRoute(itinerary2);

            // assert:
            Assert.AreEqual(finalArrival1, newState.EstimatedTimeOfArrival);
            Assert.AreEqual(initialState.GetType(), state.GetType());
            Assert.AreNotSame(initialState, state);
            Assert.IsNotNull(newState);
            Assert.AreSame(state, newState);
        }
コード例 #28
0
 public Cargo find(TrackingId tid)
 {
     return(sessionFactory.GetCurrentSession().
            CreateQuery("from Cargo where TrackingId = :tid").
            SetParameter("tid", tid).
            UniqueResult <Cargo>());
 }
コード例 #29
0
ファイル: NewCargoQA.cs プロジェクト: dmitribodiu/Epic.NET
        public void Recieve_01()
        {
            // arrange:
            TrackingId          id            = new TrackingId("CRG01");
            UnLocode            code          = new UnLocode("START");
            IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>();
            ILocation           location      = MockRepository.GenerateMock <ILocation>();

            location.Expect(l => l.UnLocode).Return(code).Repeat.AtLeastOnce();
            IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>();

            itinerary.Expect(i => i.InitialDepartureLocation).Return(code).Repeat.AtLeastOnce();
            itinerary.Expect(i => i.Equals(null)).Return(false).Repeat.Any();
            itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow + TimeSpan.FromDays(1)).Repeat.Any();
            specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Once();
            CargoState state = new NewCargo(id, specification);

            state = state.AssignToRoute(itinerary);

            // act:
            CargoState newState = state.Recieve(location, DateTime.UtcNow);

            // assert:
            Assert.IsNotNull(newState);
            Assert.IsInstanceOf <InPortCargo>(newState);
            Assert.AreSame(code, newState.LastKnownLocation);
            Assert.IsTrue(newState.EstimatedTimeOfArrival.HasValue);
            Assert.IsTrue(TransportStatus.InPort == newState.TransportStatus);
            location.VerifyAllExpectations();
            itinerary.VerifyAllExpectations();
            specification.VerifyAllExpectations();
        }
コード例 #30
0
ファイル: ClaimedCargoQA.cs プロジェクト: hungdluit/Epic.NET
		public void Ctor_02()
		{
			// arrange:
			System.Collections.Generic.List<object> mocks = new System.Collections.Generic.List<object>();
			TrackingId id = new TrackingId("CLAIM");
			IItinerary itinerary = MockRepository.GenerateStrictMock<IItinerary>();
			itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow).Repeat.AtLeastOnce();
			mocks.Add(itinerary);
			IRouteSpecification specification = MockRepository.GenerateStrictMock<IRouteSpecification>();
			specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any();
			mocks.Add(specification);
			IRouteSpecification specification2 = MockRepository.GenerateStrictMock<IRouteSpecification>();
			specification2.Expect(s => s.IsSatisfiedBy(itinerary)).Return(false).Repeat.Any();
			mocks.Add(specification2);
			CargoState previousState = MockRepository.GenerateStrictMock<CargoState>(id, specification);
			mocks.Add(previousState);
			previousState = MockRepository.GenerateStrictMock<CargoState>(previousState, itinerary);
			mocks.Add(previousState);
			previousState = MockRepository.GenerateStrictMock<CargoState>(previousState, specification2);
			mocks.Add(previousState);
			DateTime claimDate = DateTime.UtcNow;
			
		
			// act:
			Assert.Throws<ArgumentException>(delegate { new ClaimedCargo(previousState, claimDate); });
		
			// assert:
			foreach(object mock in mocks)
			{
				mock.VerifyAllExpectations();
			}
		}
コード例 #31
0
ファイル: NewCargoQA.cs プロジェクト: dmitribodiu/Epic.NET
        public void Recieve_02()
        {
            // arrange:
            TrackingId          id            = new TrackingId("CRG01");
            UnLocode            start         = new UnLocode("START");
            UnLocode            other         = new UnLocode("OTHER");
            IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>();
            ILocation           location      = MockRepository.GenerateMock <ILocation>();

            location.Expect(l => l.UnLocode).Return(other).Repeat.AtLeastOnce();
            IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>();

            itinerary.Expect(i => i.InitialDepartureLocation).Return(start).Repeat.AtLeastOnce();
            itinerary.Expect(i => i.Equals(null)).Return(false).Repeat.Any();
            itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow + TimeSpan.FromDays(1)).Repeat.Any();
            specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Once();
            CargoState state = new NewCargo(id, specification);

            state = state.AssignToRoute(itinerary);

            // assert:
            Assert.Throws <ArgumentException>(delegate { state.Recieve(location, DateTime.UtcNow); });
            location.VerifyAllExpectations();
            itinerary.VerifyAllExpectations();
            specification.VerifyAllExpectations();
        }
コード例 #32
0
        public void SubmitReport(HandlingReport handlingReport)
        {
            IList <string> errors = new List <string>();

            DateTime?    completionTime = HandlingReportParser.ParseCompletionTime(handlingReport, errors);
            VoyageNumber voyageNumber   = HandlingReportParser.ParseVoyageNumber(handlingReport.VoyageNumber, errors);
            HandlingType type           = HandlingReportParser.ParseEventType(handlingReport.Type, errors);
            UnLocode     unLocode       = HandlingReportParser.ParseUnLocode(handlingReport.UnLocode, errors);

            foreach (string trackingIdStr in handlingReport.TrackingIds)
            {
                TrackingId trackingId = HandlingReportParser.ParseTrackingId(trackingIdStr, errors);

                if (errors.IsEmpty())
                {
                    DateTime registrationTime = DateTime.Now;
                    var      attempt          = new HandlingEventRegistrationAttempt(
                        registrationTime, completionTime.Value, trackingId, voyageNumber, type, unLocode);
                    applicationEvents.ReceivedHandlingEventRegistrationAttempt(attempt);
                }
                else
                {
                    string errorString = String.Join("\r\n", errors.ToArray());
                    logger.Error("Parse error in handling report: " + errorString);

                    throw new FaultException <HandlingReportException>(new HandlingReportException(errorString), new FaultReason(errorString));
                }
            }
        }
コード例 #33
0
ファイル: NewCargoQA.cs プロジェクト: dmitribodiu/Epic.NET
        public void Recieve_04()
        {
            // arrange:
            TrackingId id        = new TrackingId("CRG01");
            IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>();

            itinerary.Expect(i => i.Equals(null)).Return(false).Repeat.Any();
            itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow + TimeSpan.FromDays(1)).Repeat.Any();
            IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>();

            specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.AtLeastOnce();
            IRouteSpecification specification2 = MockRepository.GenerateStrictMock <IRouteSpecification>();

            specification2.Expect(s => s.IsSatisfiedBy(itinerary)).Return(false).Repeat.AtLeastOnce();
            specification.Expect(s => s.Equals(specification2)).Return(false).Repeat.Any();
            specification2.Expect(s => s.Equals(specification)).Return(false).Repeat.Any();
            ILocation  location       = MockRepository.GenerateMock <ILocation>();
            CargoState initialState   = new NewCargo(id, specification);
            CargoState routedState    = initialState.AssignToRoute(itinerary);
            CargoState misroutedState = routedState.SpecifyNewRoute(specification2);

            // assert:
            Assert.AreEqual(initialState.GetType(), routedState.GetType());
            Assert.AreNotSame(initialState, routedState);
            Assert.AreEqual(routedState.GetType(), misroutedState.GetType());
            Assert.AreNotSame(routedState, misroutedState);
            Assert.IsTrue(RoutingStatus.Misrouted == misroutedState.RoutingStatus);
            Assert.Throws <InvalidOperationException>(delegate { misroutedState.Recieve(location, DateTime.UtcNow); });
            location.VerifyAllExpectations();
            specification.VerifyAllExpectations();
            specification2.VerifyAllExpectations();
            itinerary.VerifyAllExpectations();
        }
コード例 #34
0
ファイル: CargoRepositoryInMem.cs プロジェクト: chandmk/esddd
        public void Init()
        {
            TrackingId xyz = new TrackingId("XYZ");
            Cargo cargoXYZ = createCargoWithDeliveryHistory(
                xyz, SampleLocations.STOCKHOLM, SampleLocations.MELBOURNE,
                handlingEventRepository.LookupHandlingHistoryOfCargo(xyz));
            cargoDb.Add(xyz.IdString, cargoXYZ);

            TrackingId zyx = new TrackingId("ZYX");
            Cargo cargoZYX = createCargoWithDeliveryHistory(
                zyx, SampleLocations.MELBOURNE, SampleLocations.STOCKHOLM,
                handlingEventRepository.LookupHandlingHistoryOfCargo(zyx));
            cargoDb.Add(zyx.IdString, cargoZYX);

            TrackingId abc = new TrackingId("ABC");
            Cargo cargoABC = createCargoWithDeliveryHistory(
                abc, SampleLocations.STOCKHOLM, SampleLocations.HELSINKI,
                handlingEventRepository.LookupHandlingHistoryOfCargo(abc));
            cargoDb.Add(abc.IdString, cargoABC);

            TrackingId cba = new TrackingId("CBA");
            Cargo cargoCBA = createCargoWithDeliveryHistory(
                cba, SampleLocations.HELSINKI, SampleLocations.STOCKHOLM,
                handlingEventRepository.LookupHandlingHistoryOfCargo(cba));
            cargoDb.Add(cba.IdString, cargoCBA);
        }
コード例 #35
0
ファイル: NewCargoQA.cs プロジェクト: dmitribodiu/Epic.NET
        public void AssignToRoute_01()
        {
            // arrange:
            TrackingId id        = new TrackingId("CRG01");
            IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>();

            itinerary.Expect(i => i.Equals(null)).Return(false);
            itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.Now + TimeSpan.FromDays(60)).Repeat.AtLeastOnce();
            IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>();

            specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Once();
            NewCargo state = new NewCargo(id, specification);

            // act:
            CargoState newState = state.AssignToRoute(itinerary);

            // assert:
            Assert.IsNotNull(newState);
            Assert.IsTrue(state.CalculationDate <= newState.CalculationDate);
            Assert.AreEqual(RoutingStatus.Routed, newState.RoutingStatus);
            Assert.AreSame(itinerary, newState.Itinerary);
            Assert.AreNotSame(state, newState);
            Assert.IsFalse(state.Equals(newState));
            Assert.IsFalse(newState.Equals(state));
            itinerary.VerifyAllExpectations();
            specification.VerifyAllExpectations();
        }
コード例 #36
0
        public void assignCargoToRoute(string trackingIdStr, RouteCandidateDTO routeCandidateDTO)
        {
            var itinerary  = DTOAssembler.fromDTO(routeCandidateDTO, voyageRepository, locationRepository);
            var trackingId = new TrackingId(trackingIdStr);

            bookingService.assignCargoToRoute(itinerary, trackingId);
        }
コード例 #37
0
        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;
        }
コード例 #38
0
        public void Init()
        {
            TrackingId xyz      = new TrackingId("XYZ");
            Cargo      cargoXYZ = createCargoWithDeliveryHistory(
                xyz, SampleLocations.STOCKHOLM, SampleLocations.MELBOURNE,
                handlingEventRepository.LookupHandlingHistoryOfCargo(xyz));

            cargoDb.Add(xyz.IdString, cargoXYZ);

            TrackingId zyx      = new TrackingId("ZYX");
            Cargo      cargoZYX = createCargoWithDeliveryHistory(
                zyx, SampleLocations.MELBOURNE, SampleLocations.STOCKHOLM,
                handlingEventRepository.LookupHandlingHistoryOfCargo(zyx));

            cargoDb.Add(zyx.IdString, cargoZYX);

            TrackingId abc      = new TrackingId("ABC");
            Cargo      cargoABC = createCargoWithDeliveryHistory(
                abc, SampleLocations.STOCKHOLM, SampleLocations.HELSINKI,
                handlingEventRepository.LookupHandlingHistoryOfCargo(abc));

            cargoDb.Add(abc.IdString, cargoABC);

            TrackingId cba      = new TrackingId("CBA");
            Cargo      cargoCBA = createCargoWithDeliveryHistory(
                cba, SampleLocations.HELSINKI, SampleLocations.STOCKHOLM,
                handlingEventRepository.LookupHandlingHistoryOfCargo(cba));

            cargoDb.Add(cba.IdString, cargoCBA);
        }
コード例 #39
0
        public void RegisterHandlingEvent(DateTime completionTime, TrackingId trackingId, UnLocode unLocode, HandlingEventType type)
        {
            HandlingHistory handlingHistory = _handlingEventRepository.LookupHandlingHistoryOfCargo(trackingId);
            Location        location        = _locationRepository.Find(unLocode);

            handlingHistory.RegisterHandlingEvent(type, location, DateTime.Now, completionTime);
        }
コード例 #40
0
        public void RegisterHandlingEvent(DateTime completionTime, TrackingId trackingId, UnLocode unLocode, HandlingEventType type)
        {
            Cargo    cargo    = _cargoRepository.Find(trackingId);
            Location location = _locationRepository.Find(unLocode);

            cargo.RegisterHandlingEvent(type, location, DateTime.Now, completionTime);
        }
コード例 #41
0
        public void SearchNoExistingCargoTest()
        {
            //Arrange
            var cargoRepositoryMock         = new Mock <ICargoRepository>();
            var handlingEventRepositoryMock = new Mock <IHandlingEventRepository>();
            var controllerMock = new Mock <CargoTrackingController>(cargoRepositoryMock.Object,
                                                                    handlingEventRepositoryMock.Object);
            var controller = controllerMock.Object;

            const string trackingIdStr = "trackId";
            var          trackingId    = new TrackingId(trackingIdStr);

            cargoRepositoryMock.Setup(m => m.Find(trackingId)).Returns((Cargo)null).Verifiable();

            //Act
            var viewModel = controller.Search(new TrackCommand {
                TrackingId = trackingIdStr
            })
                            .GetModel <CargoTrackingViewAdapter>();

            //Assert
            //Verify expected method calls
            cargoRepositoryMock.Verify();
            handlingEventRepositoryMock.Verify();
            Assert.IsNull(viewModel);
            //Verfy if warning message is set to UI
            controllerMock.Verify(m => m.SetMessage(It.Is <string>(s => s == CargoTrackingController.UnknownMessageId)), Times.Once());
            //Verify that the method is not invoked
            handlingEventRepositoryMock.Verify(m => m.LookupHandlingHistoryOfCargo(It.IsAny <TrackingId>()), Times.Never());
        }
コード例 #42
0
        public Cargo.Cargo Find(TrackingId trackingId)
        {
            const string query = @"from DDDSample.Domain.Cargo.Cargo c where c.TrackingId = :trackingId";

            return(Session.CreateQuery(query).SetString("trackingId", trackingId.IdString)
                   .UniqueResult <Cargo.Cargo>());
        }
コード例 #43
0
        public void reportCargoUpdate(TrackingId trackingId)
        {
            Cargo        cargo        = cargoRepository.find(trackingId);
            CargoDetails cargoDetails = assembleFrom(cargo);

            reportSubmission.submitCargoDetails(cargoDetails);
        }
コード例 #44
0
        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();
        }
コード例 #45
0
        public void assignCargoToRoute(string trackingIdStr, RouteCandidateDTO routeCandidateDTO)
        {
            var itinerary = DTOAssembler.fromDTO(routeCandidateDTO, voyageRepository, locationRepository);
            var trackingId = new TrackingId(trackingIdStr);

            bookingService.assignCargoToRoute(itinerary, trackingId);
        }
コード例 #46
0
        public void Ctor_02()
        {
            // arrange:
            GList      mocks     = new GList();
            TrackingId id        = new TrackingId("START");
            DateTime   loadTime  = DateTime.Now;
            IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>();

            itinerary.Expect(i => i.Equals(null)).IgnoreArguments().Return(false).Repeat.Any();
            itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow + TimeSpan.FromDays(1)).Repeat.Any();
            itinerary.Expect(i => i.FinalArrivalLocation).Return(new UnLocode("ENDLC")).Repeat.Any();
            mocks.Add(itinerary);
            IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>();

            specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any();
            CargoState previousState = MockRepository.GenerateStrictMock <CargoState>(id, specification);

            mocks.Add(previousState);
            previousState = MockRepository.GenerateStrictMock <CargoState>(previousState, itinerary);
            mocks.Add(previousState);

            // assert:
            Assert.Throws <ArgumentNullException>(delegate { new OnboardCarrierCargo(previousState, null, loadTime); });
            foreach (object mock in mocks)
            {
                mock.VerifyAllExpectations();
            }
        }
コード例 #47
0
        public void Ctor_05()
        {
            // arrange:
            TrackingId id        = new TrackingId("CLAIM");
            IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>();

            itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow).Repeat.AtLeastOnce();
            IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>();

            specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any();
            CargoState previousState = MockRepository.GenerateStrictMock <CargoState>(id, specification);

            previousState = MockRepository.GenerateStrictMock <CargoState>(previousState, itinerary);
            previousState.Expect(s => s.IsUnloadedAtDestination).Return(false).Repeat.AtLeastOnce();
            previousState.Expect(s => s.TransportStatus).Return(TransportStatus.InPort).Repeat.AtLeastOnce();
            DateTime claimDate = DateTime.UtcNow;


            // act:
            Assert.Throws <ArgumentException>(delegate { new ClaimedCargo(previousState, claimDate); });

            // assert:
            itinerary.VerifyAllExpectations();
            specification.VerifyAllExpectations();
            previousState.VerifyAllExpectations();
        }
コード例 #48
0
        protected void setUp()
        {
            TrackingId         trackingId         = new TrackingId("XYZ");
            RouteSpecification routeSpecification = new RouteSpecification(L.HONGKONG, L.NEWYORK, DateTime.Now);

            cargo = new Cargo(trackingId, routeSpecification);
        }
コード例 #49
0
ファイル: Cargo.cs プロジェクト: paulrayner/dddsample
 public Cargo(TrackingId trackingId, RouteSpecification routeSpecification)
 {
     TrackingId = trackingId;
     RouteSpecification = routeSpecification;
     TransportStatus = TransportStatus.NotReceived;
     RoutingStatus = RoutingStatus.NotRouted;
 }
コード例 #50
0
ファイル: ClaimedCargoQA.cs プロジェクト: hungdluit/Epic.NET
		public void Ctor_01()
		{
			// arrange:
			UnLocode final = new UnLocode("FINAL");
			TrackingId id = new TrackingId("CLAIM");
			IItinerary itinerary = MockRepository.GenerateStrictMock<IItinerary>();
			itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow).Repeat.AtLeastOnce();
			itinerary.Expect(i => i.FinalArrivalLocation).Return(final).Repeat.AtLeastOnce();
			IRouteSpecification specification = MockRepository.GenerateStrictMock<IRouteSpecification>();
			specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any();
			CargoState previousState = MockRepository.GenerateStrictMock<CargoState>(id, specification);
			previousState = MockRepository.GenerateStrictMock<CargoState>(previousState, itinerary);
			previousState.Expect(s => s.IsUnloadedAtDestination).Return(true).Repeat.AtLeastOnce();
			previousState.Expect(s => s.TransportStatus).Return(TransportStatus.InPort).Repeat.AtLeastOnce();
			DateTime claimDate = DateTime.UtcNow;
			
		
			// act:
			ClaimedCargo state = new ClaimedCargo(previousState, claimDate);
		
			// assert:
			Assert.AreEqual(TransportStatus.Claimed, state.TransportStatus);
			Assert.AreEqual(RoutingStatus.Routed, state.RoutingStatus);
			Assert.AreSame(final, state.LastKnownLocation);
			Assert.AreSame(specification, state.RouteSpecification);
			Assert.IsNull(state.CurrentVoyage);
			Assert.IsTrue(state.IsUnloadedAtDestination);
			itinerary.VerifyAllExpectations();
			specification.VerifyAllExpectations();
			previousState.VerifyAllExpectations();
		}
コード例 #51
0
        /// <summary>
        /// Creates a handling event.
        /// </summary>
        /// <param name="completionTime">when the event was completed, for example finished loading</param>
        /// <param name="trackingId">cargo tracking id</param>
        /// <param name="voyageNumber">voyage number</param>
        /// <param name="unlocode">United Nations Location Code for the location of the event</param>
        /// <param name="type">type of event</param>
        /// <param name="operatorCode">operator code</param>
        /// <returns>A handling event.</returns>
        /// <exception cref="UnknownVoyageException">if there's no voyage with this number</exception>
        /// <exception cref="UnknownCargoException">if there's no cargo with this tracking id</exception>
        /// <exception cref="UnknownLocationException">if there's no location with this UN Locode</exception>
        public HandlingEvent createHandlingEvent(DateTime completionTime, TrackingId trackingId,
                                                 VoyageNumber voyageNumber, UnLocode unlocode,
                                                 HandlingActivityType type, OperatorCode operatorCode)
        {
            var cargo = findCargo(trackingId);
            var voyage = findVoyage(voyageNumber);
            var location = findLocation(unlocode);

            try
            {
                var registrationTime = DateTime.Now;
                if(voyage == null)
                {
                    return new HandlingEvent(cargo, completionTime, registrationTime, type, location);
                }
                else
                {
                    return new HandlingEvent(cargo, completionTime, registrationTime, type, location, voyage, operatorCode);
                }
            }
            catch(Exception e)
            {
                throw new CannotCreateHandlingEventException(e.Message, e);
            }
        }
コード例 #52
0
        public IEnumerable<Itinerary> requestPossibleRoutesForCargo(TrackingId trackingId)
        {
            var cargo = _cargoRepository.find(trackingId);
            if(cargo == null)
                return new List<Itinerary>();

            return _routingService.fetchRoutesForSpecification(cargo.RouteSpecification);
        }
コード例 #53
0
        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");
        }
コード例 #54
0
ファイル: HandlingEventFactory.cs プロジェクト: chandmk/esddd
 private Cargo FindCargo(TrackingId trackingId)
 {
     Cargo cargo = cargoRepository.Find(trackingId);
     if (cargo == null)
     {
         throw new UnknownCargoException(trackingId);
     }
     return cargo;
 }
コード例 #55
0
        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));
        }
コード例 #56
0
        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);
        }
コード例 #57
0
        public void alertIfReadyToClaim(TrackingId trackingId)
        {
            var cargo = cargoRepository.find(trackingId);

            if(cargo.IsReadyToClaim)
            {
                // At this point, a real system would probably send an email or SMS
                // or something, but we simply log a message.
                LOG.Info("Cargo " + cargo + " is ready to be claimed");
            }
        }
コード例 #58
0
ファイル: CargoRepositoryInMem.cs プロジェクト: chandmk/esddd
        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;
        }
コード例 #59
0
        public void changeDestination(TrackingId trackingId, UnLocode unLocode)
        {
            var cargo = _cargoRepository.find(trackingId);
            Validate.notNull(cargo, "Can't change destination of non-existing cargo " + trackingId);
            var newDestination = _locationRepository.find(unLocode);

            var routeSpecification = cargo.RouteSpecification.WithDestination(newDestination);
            cargo.SpecifyNewRoute(routeSpecification);

            _cargoRepository.store(cargo);
            _logger.Info("Changed destination for cargo " + trackingId + " to " + routeSpecification.Destination);
        }
コード例 #60
0
ファイル: CargoQA.cs プロジェクト: hungdluit/Epic.NET
		public void Ctor_withValidArgs_isNotRouted()
		{
			// arrange:
			TrackingId identifier = new TrackingId("CARGO01");
			IRouteSpecification route = MockRepository.GenerateStrictMock<IRouteSpecification>();
		
			// act:
			TCargo tested = new TCargo(identifier, route);
		
			// assert:
			Assert.AreEqual(RoutingStatus.NotRouted, tested.Delivery.RoutingStatus);
		}