Esempio n. 1
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();
        }
Esempio n. 2
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();
        }
Esempio n. 3
0
        public void StateTransitions_01()
        {
            // arrange:
            UnLocode   final         = new UnLocode("FINAL");
            TrackingId id            = new TrackingId("CLAIM");
            ILocation  finalLocation = MockRepository.GenerateStrictMock <ILocation>();

            finalLocation.Expect(l => l.UnLocode).Return(final).Repeat.AtLeastOnce();
            ILocation otherLocation = MockRepository.GenerateStrictMock <ILocation>();

            otherLocation.Expect(l => l.UnLocode).Return(new UnLocode("OTHER")).Repeat.AtLeastOnce();
            IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>();

            itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow).Repeat.Any();
            itinerary.Expect(i => i.FinalArrivalLocation).Return(final).Repeat.Any();
            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.Any();
            previousState.Expect(s => s.TransportStatus).Return(TransportStatus.InPort).Repeat.Any();
            IVoyage  voyage    = MockRepository.GenerateStrictMock <IVoyage>();
            DateTime claimDate = DateTime.UtcNow;

            ClaimedCargo state = new ClaimedCargo(previousState, claimDate);

            // act:
            CargoState newState = state.Claim(finalLocation, claimDate);

            // assert:
            Assert.AreSame(state, newState);
            Assert.Throws <ArgumentNullException>(delegate { state.Claim(null, DateTime.UtcNow); });
            Assert.Throws <InvalidOperationException>(delegate { state.Claim(finalLocation, DateTime.UtcNow + TimeSpan.FromSeconds(10)); });
            Assert.Throws <InvalidOperationException>(delegate { state.Claim(otherLocation, claimDate); });
            Assert.Throws <InvalidOperationException>(delegate { state.LoadOn(voyage, DateTime.UtcNow + TimeSpan.FromSeconds(10)); });
            Assert.Throws <InvalidOperationException>(delegate { state.Unload(voyage, DateTime.UtcNow + TimeSpan.FromSeconds(10)); });
            Assert.Throws <InvalidOperationException>(delegate { state.SpecifyNewRoute(MockRepository.GenerateStrictMock <IRouteSpecification>()); });
            Assert.Throws <InvalidOperationException>(delegate { state.AssignToRoute(MockRepository.GenerateStrictMock <IItinerary>()); });
            Assert.Throws <InvalidOperationException>(delegate { state.Recieve(MockRepository.GenerateStrictMock <ILocation>(), DateTime.UtcNow + TimeSpan.FromSeconds(10) + TimeSpan.FromSeconds(10)); });
            Assert.Throws <InvalidOperationException>(delegate { state.ClearCustoms(MockRepository.GenerateStrictMock <ILocation>(), DateTime.UtcNow + TimeSpan.FromSeconds(10)); });
            itinerary.VerifyAllExpectations();
            specification.VerifyAllExpectations();
        }
        public void Unload_04()
        {
            // arrange:
            GList mocks = new GList();

            UnLocode     code         = new UnLocode("START");
            VoyageNumber voyageNumber = new VoyageNumber("ATEST");
            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);
            IVoyage voyage = MockRepository.GenerateStrictMock <IVoyage>();

            voyage.Expect(v => v.Number).Return(voyageNumber).Repeat.Any();
            voyage.Expect(v => v.LastKnownLocation).Return(code).Repeat.AtLeastOnce();
            voyage.Expect(v => v.IsMoving).Return(false).Repeat.AtLeastOnce();
            mocks.Add(voyage);
            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();
            OnboardCarrierCargo state = new OnboardCarrierCargo(previousState, voyage, arrival);

            // act:
            CargoState newState = state.Unload(voyage, arrival + TimeSpan.FromDays(2));

            // assert:
            Assert.IsNotNull(newState);
            Assert.IsInstanceOf <InPortCargo>(newState);
            Assert.AreSame(code, newState.LastKnownLocation);
            foreach (object mock in mocks)
            {
                mock.VerifyAllExpectations();
            }
        }
        public void LoadOn_02()
        {
            // arrange:
            GList mocks = new GList();

            UnLocode     code         = new UnLocode("START");
            VoyageNumber voyageNumber = new VoyageNumber("ATEST");
            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);
            IVoyage voyage = MockRepository.GenerateStrictMock <IVoyage>();

            voyage.Expect(v => v.Number).Return(voyageNumber).Repeat.Any();
            voyage.Expect(v => v.LastKnownLocation).Return(code).Repeat.AtLeastOnce();
            mocks.Add(voyage);
            IVoyage voyage2 = MockRepository.GenerateStrictMock <IVoyage>();

            voyage2.Expect(v => v.Number).Return(new VoyageNumber("VYGOTHER")).Repeat.Any();
            mocks.Add(voyage2);
            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();
            OnboardCarrierCargo state = new OnboardCarrierCargo(previousState, voyage, arrival);

            // assert:
            Assert.Throws <InvalidOperationException>(delegate { state.LoadOn(voyage2, arrival + TimeSpan.FromDays(2)); });
            foreach (object mock in mocks)
            {
                mock.VerifyAllExpectations();
            }
        }