Beispiel #1
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));
        }
Beispiel #2
0
 protected InPortCargo(InPortCargo previousState, IRouteSpecification newRoute)
     : base(previousState, newRoute)
 {
     _lastKnownLocation = previousState._lastKnownLocation;
     _date          = previousState._date;
     _customCleared = previousState._customCleared;
 }
Beispiel #3
0
        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();
        }
Beispiel #4
0
        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();
        }
Beispiel #5
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));
        }
Beispiel #6
0
        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();
        }
Beispiel #7
0
        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();
        }
Beispiel #8
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();
        }
Beispiel #9
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();
        }
        public virtual bool Equals(ISpecification <IItinerary> other)
        {
            IRouteSpecification otherRoute = other as IRouteSpecification;

            if (object.ReferenceEquals(otherRoute, null))
            {
                return(false);
            }
            if (object.ReferenceEquals(this, other))
            {
                return(true);
            }
            if (!_origin.Equals(otherRoute.Origin))
            {
                return(false);
            }
            if (!_destination.Equals(otherRoute.Destination))
            {
                return(false);
            }
            if (!_arrivalDeadline.Equals(otherRoute.ArrivalDeadline))
            {
                return(false);
            }
            return(true);
        }
        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();
            }
        }
Beispiel #12
0
        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);
        }
Beispiel #13
0
 public bool has_the_same_value_as(IRouteSpecification the_other)
 {
     return the_other != null &&
            this.underlying_origin_location.has_the_same_identity_as(the_other.origin()) &&
            this.underlying_destination_location.has_the_same_identity_as(the_other.destination()) &&
            this.underlying_arrival_deadline.has_the_same_value_as(the_other.arrival_dealine());
 }
Beispiel #14
0
        public void Ctor_03()
        {
            // arrange:
            IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>();

            // act:
            new NewCargo(null, specification);
        }
Beispiel #15
0
		public override CargoState SpecifyNewRoute (IRouteSpecification routeSpecification)
		{
			if(null == routeSpecification)
				throw new ArgumentNullException("routeSpecification");
			if(this.RouteSpecification.Equals(routeSpecification))
				return this;
			return new NewCargo(this, routeSpecification);
		}
Beispiel #16
0
        public void Equals_withNull_isFalse()
        {
            // arrange:
            TrackingId          identifier = new TrackingId("CARGO01");
            IRouteSpecification route      = MockRepository.GenerateStrictMock <IRouteSpecification>();
            FakeState           state      = new FakeState(identifier, route);

            Assert.IsFalse(state.Equals((CargoState)null));
            Assert.IsFalse(state.Equals((IDelivery)null));
        }
Beispiel #17
0
        public void Ctor_withNullRoute_throwsArgumentNullException()
        {
            // arrange:
            TrackingId          identifier = new TrackingId("CARGO01");
            IRouteSpecification route      = MockRepository.GenerateStrictMock <IRouteSpecification>();
            CargoState          mock       = MockRepository.GeneratePartialMock <CargoState>(identifier, route);

            // assert:
            Assert.Throws <ArgumentNullException>(delegate { new FakeState(mock, null as IRouteSpecification); });
        }
Beispiel #18
0
        public void Unload_01()
        {
            // arrange:
            TrackingId          id            = new TrackingId("CRG01");
            IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>();
            IVoyage             voyage        = MockRepository.GenerateMock <IVoyage>();
            CargoState          state         = new NewCargo(id, specification);

            // assert:
            Assert.Throws <InvalidOperationException>(delegate { state.Unload(voyage, DateTime.Now); });
        }
Beispiel #19
0
        public void ClearCustoms_01()
        {
            // arrange:
            TrackingId          id            = new TrackingId("CRG01");
            IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>();
            ILocation           location      = MockRepository.GenerateMock <ILocation>();
            CargoState          state         = new NewCargo(id, specification);

            // assert:
            Assert.Throws <InvalidOperationException>(delegate { state.ClearCustoms(location, DateTime.Now); });
        }
Beispiel #20
0
        public void AssignToRoute_04()
        {
            // arrange:
            TrackingId          id            = new TrackingId("CRG01");
            IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>();
            NewCargo            state         = new NewCargo(id, specification);

            // assert:
            Assert.Throws <ArgumentNullException>(delegate { state.AssignToRoute(null); });
            specification.VerifyAllExpectations();
        }
Beispiel #21
0
        public void Recieve_05()
        {
            // arrange:
            TrackingId          id            = new TrackingId("CRG01");
            IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>();
            CargoState          state         = new NewCargo(id, specification);

            // assert:
            Assert.Throws <ArgumentNullException>(delegate { state.Recieve(null, DateTime.UtcNow); });
            specification.VerifyAllExpectations();
        }
Beispiel #22
0
 public override CargoState SpecifyNewRoute(IRouteSpecification routeSpecification)
 {
     if (null == routeSpecification)
     {
         throw new ArgumentNullException("routeSpecification");
     }
     if (this.RouteSpecification.Equals(routeSpecification))
     {
         return(this);
     }
     return(new NewCargo(this, routeSpecification));
 }
Beispiel #23
0
        public void ToString_containsStateName()
        {
            // arrange:
            TrackingId          identifier = new TrackingId("CARGO01");
            IRouteSpecification route      = MockRepository.GenerateStrictMock <IRouteSpecification>();
            CargoState          state      = new FakeState(identifier, route);

            // act:
            string stateString = state.ToString();

            // assert:
            Assert.IsTrue(stateString.Contains(state.GetType().Name));
        }
Beispiel #24
0
        public void Ctor_withSameArgs_produceDifferentCalculationDate()
        {
            // arrange:
            TrackingId          identifier = new TrackingId("CARGO01");
            IRouteSpecification route      = MockRepository.GenerateStrictMock <IRouteSpecification>();

            // act:
            CargoState state1 = new FakeState(identifier, route);

            Thread.Sleep(100);
            CargoState state2 = new FakeState(identifier, route);

            // assert:
            Assert.AreNotEqual(state1.CalculationDate, state2.CalculationDate);
        }
Beispiel #25
0
        public void Ctor_03()
        {
            // arrange:
            TrackingId          id            = new TrackingId("CLAIM");
            IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>();
            CargoState          previousState = MockRepository.GenerateStrictMock <CargoState>(id, specification);
            DateTime            claimDate     = DateTime.UtcNow;


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

            // assert:
            specification.VerifyAllExpectations();
        }
Beispiel #26
0
        public void Ctor_withValidArgs_works()
        {
            // arrange:
            DateTime            runTime    = DateTime.UtcNow;
            TrackingId          identifier = new TrackingId("CARGO01");
            IRouteSpecification route      = MockRepository.GenerateStrictMock <IRouteSpecification>();

            // act:
            CargoState state = new FakeState(identifier, route);

            // assert:
            Assert.LessOrEqual(runTime, state.CalculationDate);
            Assert.AreSame(identifier, state.Identifier);
            Assert.AreSame(route, state.RouteSpecification);
            Assert.AreEqual(RoutingStatus.NotRouted, state.RoutingStatus);
            Assert.IsFalse(state.EstimatedTimeOfArrival.HasValue);
        }
Beispiel #27
0
        public void Equals_withDifferentIdentifiers_isFalse()
        {
            // arrange:
            TrackingId          identifier = new TrackingId("CARGO01");
            IRouteSpecification route      = MockRepository.GenerateStrictMock <IRouteSpecification>();
            FakeState           state1     = new FakeState(identifier, route);

            state1._lastKnownLocation = new Challenge00.DDDSample.Location.UnLocode("TESTA");
            FakeState state2 = new FakeState(new TrackingId("CARGO02"), route);

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

            // act:

            // assert:
            Assert.IsFalse(state1.Equals(state2));
        }
        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();
            }
        }
Beispiel #29
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();
        }
Beispiel #30
0
        protected CargoState(TrackingId identifier, IRouteSpecification routeSpecification)
        {
            if (null == identifier)
            {
                throw new ArgumentNullException("identifier");
            }
            if (null == routeSpecification)
            {
                throw new ArgumentNullException("routeSpecification");
            }

            _calculationDate = DateTime.UtcNow;

            this.Identifier         = identifier;
            this.RouteSpecification = routeSpecification;
            _routingStatus          = RoutingStatus.NotRouted;
            _estimatedTimeOfArrival = null;
        }
        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();
            }
        }
Beispiel #32
0
        public void AssignToRoute_02()
        {
            // arrange:
            TrackingId id        = new TrackingId("CRG01");
            IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>();

            itinerary.Expect(i => i.Equals(null)).Return(false);
            IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>();

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

            // act:
            Assert.Throws <ArgumentException>(delegate { state.AssignToRoute(itinerary); });

            // assert:
            itinerary.VerifyAllExpectations();
            specification.VerifyAllExpectations();
        }
Beispiel #33
0
		protected NewCargo(CargoState previousState, IRouteSpecification newRoute)
			: base(previousState, newRoute)
		{
		}
Beispiel #34
0
		public NewCargo (TrackingId identifier, IRouteSpecification routeSpecification)
			: base(identifier, routeSpecification)
		{
		}
Beispiel #35
0
		public FakeState2 (TrackingId identifier, IRouteSpecification route)
			: base(identifier, route)
		{
		}
Beispiel #36
0
		public FakeState2(CargoState previousState, IRouteSpecification route)
			: base(previousState, route)
		{
		}
		public override CargoState SpecifyNewRoute (IRouteSpecification routeSpecification)
		{
			string message = string.Format("The cargo {0} has been loaded on the {1} voyage.", Identifier, _voyage);
			throw new InvalidOperationException(message);
		}
Beispiel #38
0
		public override CargoState SpecifyNewRoute (IRouteSpecification routeSpecification)
		{
			throw new System.NotImplementedException();
		}
Beispiel #39
0
 public Cargo(ITrackingId tracking_id, IRouteSpecification route_specification)
 {
     this.underlying_tracking_id = tracking_id;
     this.underlying_route_specification = route_specification;
     this.underlying_origin_location = route_specification.origin();
 }