예제 #1
0
        public void Voyage_LiveCycle_05()
        {
            // arrange:
            UnLocode  code1 = new UnLocode("CODAA");
            ILocation loc1  = MockRepository.GenerateStrictMock <ILocation>();

            loc1.Expect(l => l.UnLocode).Return(code1).Repeat.Any();
            loc1.Expect(l => l.Name).Return("First location").Repeat.Any();
            UnLocode  code2 = new UnLocode("CODAB");
            ILocation loc2  = MockRepository.GenerateStrictMock <ILocation>();

            loc2.Expect(l => l.UnLocode).Return(code2).Repeat.Any();
            loc2.Expect(l => l.Name).Return("Second location").Repeat.Any();
            UnLocode  code3 = new UnLocode("CODAC");
            ILocation loc3  = MockRepository.GenerateStrictMock <ILocation>();

            loc3.Expect(l => l.UnLocode).Return(code3).Repeat.Any();
            loc3.Expect(l => l.Name).Return("Third location").Repeat.Any();

            ISchedule schedule = new Schedule();

            schedule = schedule.Append(new CarrierMovement(loc1, DateTime.UtcNow, loc2, DateTime.UtcNow + TimeSpan.FromDays(2)));
            schedule = schedule.Append(new CarrierMovement(loc2, DateTime.UtcNow + TimeSpan.FromDays(3), loc3, DateTime.UtcNow + TimeSpan.FromDays(4)));

            VoyageNumber    number        = new VoyageNumber("TESTVYG");
            VoyageEventArgs departedEvent = null;
            VoyageEventArgs stoppedEvent  = null;

            Challenge00.DDDSample.Voyage.Voyage voyage = new Challenge00.DDDSample.Voyage.Voyage(number, schedule);
            voyage.DepartFrom(loc1);
            voyage.StopOverAt(loc2);
            voyage.DepartFrom(loc2);
            voyage.Departed += delegate(object sender, VoyageEventArgs e) {
                departedEvent = e;
            };
            voyage.Stopped += delegate(object sender, VoyageEventArgs e) {
                stoppedEvent = e;
            };

            // act:
            voyage.StopOverAt(loc3);

            // assert:
            Assert.AreSame(number, voyage.Number);
            Assert.IsFalse(voyage.IsMoving);
            Assert.AreEqual(code3, voyage.LastKnownLocation);
            Assert.AreEqual(code3, voyage.NextExpectedLocation);
            Assert.IsNull(departedEvent);
            Assert.IsNotNull(stoppedEvent);
            Assert.AreEqual(code2, stoppedEvent.PreviousLocation);
            Assert.AreEqual(code3, stoppedEvent.DestinationLocation);
            loc1.VerifyAllExpectations();
            loc2.VerifyAllExpectations();
            loc3.VerifyAllExpectations();
        }
예제 #2
0
        public void GetHashCode_01()
        {
            // arrange:
            UnLocode  first  = new UnLocode("CDFST");
            UnLocode  second = new UnLocode("CDSND");
            ILocation origin = MockRepository.GenerateStrictMock <ILocation>();

            origin.Expect(l => l.UnLocode).Return(first).Repeat.AtLeastOnce();
            ILocation destination = MockRepository.GenerateStrictMock <ILocation>();

            destination.Expect(l => l.UnLocode).Return(second).Repeat.AtLeastOnce();
            DateTime  arrivalDeadline = DateTime.UtcNow + TimeSpan.FromDays(5);
            ILocation origin2         = MockRepository.GenerateStrictMock <ILocation>();

            origin2.Expect(l => l.UnLocode).Return(new UnLocode("OTHER")).Repeat.AtLeastOnce();
            ILocation destination2 = MockRepository.GenerateStrictMock <ILocation>();

            destination2.Expect(l => l.UnLocode).Return(new UnLocode("OTHER")).Repeat.AtLeastOnce();

            // act:
            IRouteSpecification specification1 = new RouteSpecification(origin, destination, arrivalDeadline);
            IRouteSpecification specification2 = new RouteSpecification(origin, destination, arrivalDeadline);
            IRouteSpecification specification3 = new RouteSpecification(origin2, destination, arrivalDeadline);
            IRouteSpecification specification4 = new RouteSpecification(origin, destination2, arrivalDeadline);

            // assert:
            Assert.AreEqual(specification1.GetHashCode(), specification2.GetHashCode());
            Assert.AreNotEqual(specification1.GetHashCode(), specification3.GetHashCode());
            Assert.AreNotEqual(specification1.GetHashCode(), specification4.GetHashCode());
            origin.VerifyAllExpectations();
            destination.VerifyAllExpectations();
        }
예제 #3
0
        public void IsSatisfiedBy_06()
        {
            // arrange:
            UnLocode  first  = new UnLocode("CDFST");
            UnLocode  second = new UnLocode("CDSND");
            UnLocode  third  = new UnLocode("CDTRD");
            ILocation origin = MockRepository.GenerateStrictMock <ILocation>();

            origin.Expect(l => l.UnLocode).Return(first).Repeat.AtLeastOnce();
            ILocation destination = MockRepository.GenerateStrictMock <ILocation>();

            destination.Expect(l => l.UnLocode).Return(second).Repeat.AtLeastOnce();
            DateTime arrivalDeadline = DateTime.UtcNow + TimeSpan.FromDays(5);

            IItinerary candidate = MockRepository.GenerateStrictMock <IItinerary>();

            candidate.Expect(i => i.InitialDepartureLocation).Return(first).Repeat.Once();
            candidate.Expect(i => i.FinalArrivalLocation).Return(third).Repeat.Once();
            candidate.Expect(i => i.FinalArrivalDate).Return(arrivalDeadline - TimeSpan.FromHours(1)).Repeat.Any();

            IRouteSpecification specification = new RouteSpecification(origin, destination, arrivalDeadline);

            // act:
            bool satisfied = specification.IsSatisfiedBy(candidate);

            // assert:
            Assert.IsFalse(satisfied);
            origin.VerifyAllExpectations();
            destination.VerifyAllExpectations();
            candidate.VerifyAllExpectations();
        }
예제 #4
0
        public void WillStopOverAt_06()
        {
            // arrange:
            VoyageNumber number   = new VoyageNumber("VYGTEST01");
            ISchedule    schedule = MockRepository.GenerateStrictMock <ISchedule>();

            schedule.Expect(s => s.MovementsCount).Return(3).Repeat.Any();
            UnLocode         loc3 = new UnLocode("ARLCB");
            UnLocode         loc4 = new UnLocode("ARLCC");
            ICarrierMovement mov3 = MockRepository.GenerateStrictMock <ICarrierMovement>();

            mov3.Expect(m => m.DepartureLocation).Return(loc3).Repeat.Any();
            mov3.Expect(m => m.ArrivalLocation).Return(loc4).Repeat.AtLeastOnce();
            schedule.Expect(s => s[2]).Return(mov3).Repeat.Any();
            ILocation location    = MockRepository.GenerateStrictMock <ILocation>();
            UnLocode  outLocation = new UnLocode("LCOUT");

            location.Expect(l => l.UnLocode).Return(outLocation).Repeat.AtLeastOnce();

            // act:
            StoppedVoyage state = new StoppedVoyage(number, schedule, 2);
            bool          willStopOverAtLocation = state.WillStopOverAt(location);

            // assert:
            Assert.IsFalse(willStopOverAtLocation);
            location.VerifyAllExpectations();
            schedule.VerifyAllExpectations();
            mov3.VerifyAllExpectations();
        }
예제 #5
0
        public void Equals_06()
        {
            // arrange:
            UnLocode  dpLocode         = new UnLocode("DPLOC");
            UnLocode  arLocode         = new UnLocode("ARLOC");
            ILocation targetDpLocation = MockRepository.GenerateStrictMock <ILocation>();
            ILocation targetArLocation = MockRepository.GenerateStrictMock <ILocation>();

            targetDpLocation.Expect(l => l.UnLocode).Return(dpLocode).Repeat.AtLeastOnce();
            targetArLocation.Expect(l => l.UnLocode).Return(arLocode).Repeat.AtLeastOnce();
            DateTime dpTime = DateTime.UtcNow - new TimeSpan(48, 0, 0);
            DateTime arTime = DateTime.UtcNow + new TimeSpan(48, 0, 0);

            ICarrierMovement mock = MockRepository.GenerateStrictMock <ICarrierMovement>();

            mock.Expect(m => m.DepartureLocation).Return(dpLocode).Repeat.Once();
            mock.Expect(m => m.ArrivalLocation).Return(arLocode).Repeat.Once();
            mock.Expect(m => m.ArrivalTime).Return(arTime).Repeat.Once();
            mock.Expect(m => m.DepartureTime).Return(dpTime).Repeat.Once();


            // act:
            ICarrierMovement target    = new CarrierMovement(targetDpLocation, dpTime, targetArLocation, arTime);
            bool             areEquals = target.Equals((object)mock);

            // assert:
            Assert.IsTrue(areEquals);
            targetDpLocation.VerifyAllExpectations();
            targetArLocation.VerifyAllExpectations();
            mock.VerifyAllExpectations();
        }
예제 #6
0
        public void Equals_05()
        {
            // arrange:
            UnLocode  first  = new UnLocode("CDFST");
            UnLocode  second = new UnLocode("CDSND");
            UnLocode  third  = new UnLocode("CDTRD");
            ILocation origin = MockRepository.GenerateStrictMock <ILocation>();

            origin.Expect(l => l.UnLocode).Return(first).Repeat.Any();
            ILocation destination = MockRepository.GenerateStrictMock <ILocation>();

            destination.Expect(l => l.UnLocode).Return(second).Repeat.Any();
            ILocation destination2 = MockRepository.GenerateStrictMock <ILocation>();

            destination2.Expect(l => l.UnLocode).Return(third).Repeat.Any();
            DateTime            arrivalDeadline = DateTime.UtcNow + TimeSpan.FromDays(5);
            IRouteSpecification specification1  = new RouteSpecification(origin, destination, arrivalDeadline);
            IRouteSpecification specification2  = new RouteSpecification(origin, destination2, arrivalDeadline);

            // assert:
            Assert.IsFalse(specification1.Equals(specification2));
            Assert.IsFalse(specification2.Equals(specification1));
            Assert.IsFalse(specification1.Equals((object)specification2));
            Assert.IsFalse(specification2.Equals((object)specification1));
            origin.VerifyAllExpectations();
            destination.VerifyAllExpectations();
        }
예제 #7
0
        public void DepartFrom_02(int index)
        {
            // arrange:
            VoyageNumber number   = new VoyageNumber("VYGTEST01");
            ISchedule    schedule = MockRepository.GenerateStrictMock <ISchedule>();

            schedule.Expect(s => s.MovementsCount).Return(3).Repeat.Any();
            UnLocode         initialLocation = new UnLocode("DPLOC");
            ICarrierMovement movement        = MockRepository.GenerateStrictMock <ICarrierMovement>();

            movement.Expect(m => m.DepartureLocation).Return(initialLocation).Repeat.Any();
            schedule.Expect(s => s[index]).Return(movement).Repeat.Any();
            ILocation location = MockRepository.GenerateStrictMock <ILocation>();

            location.Expect(l => l.UnLocode).Return(new UnLocode("ANTHR")).Repeat.Any();

            // act:
            StoppedVoyage state = new StoppedVoyage(number, schedule, index);

            // assert:
            Assert.Throws <ArgumentException>(delegate { state.DepartFrom(location); });
            schedule.VerifyAllExpectations();
            movement.VerifyAllExpectations();
            location.VerifyAllExpectations();
        }
예제 #8
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();
        }
예제 #9
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();
        }
예제 #10
0
        public void StopOverAt_Destination_01(int index, int movementsCount)
        {
            // arrange:
            VoyageNumber number   = new VoyageNumber("VYGTEST01");
            ISchedule    schedule = MockRepository.GenerateStrictMock <ISchedule>();

            schedule.Expect(s => s.MovementsCount).Return(movementsCount).Repeat.Any();
            UnLocode         arrivalLocation = new UnLocode("ARLOC");
            ICarrierMovement movement1       = MockRepository.GenerateStrictMock <ICarrierMovement>();

            movement1.Expect(m => m.ArrivalLocation).Return(arrivalLocation).Repeat.Times(3);
            schedule.Expect(s => s[index]).Return(movement1).Repeat.Times(3);
            ILocation location = MockRepository.GenerateStrictMock <ILocation>();

            location.Expect(l => l.UnLocode).Return(arrivalLocation).Repeat.Any();


            // act:
            MovingVoyage state   = new MovingVoyage(number, schedule, index);
            VoyageState  stopped = state.StopOverAt(location);

            // assert:
            Assert.IsInstanceOf <CompletedVoyage>(stopped);
            Assert.AreSame(state.NextExpectedLocation, stopped.LastKnownLocation);
            Assert.IsFalse(stopped.IsMoving);
            schedule.VerifyAllExpectations();
            movement1.VerifyAllExpectations();
            location.VerifyAllExpectations();
        }
예제 #11
0
        public void StopOverAt_01(int index)
        {
            // arrange:
            VoyageNumber number   = new VoyageNumber("VYGTEST01");
            ISchedule    schedule = MockRepository.GenerateStrictMock <ISchedule>();

            schedule.Expect(s => s.MovementsCount).Return(3).Repeat.Any();
            UnLocode         initialLocation = new UnLocode("DPLOC");
            ICarrierMovement movement        = MockRepository.GenerateStrictMock <ICarrierMovement>();

            movement.Expect(m => m.DepartureLocation).Return(initialLocation).Repeat.Once();
            schedule.Expect(s => s[index]).Return(movement).Repeat.Once();
            ILocation location = MockRepository.GenerateStrictMock <ILocation>();

            location.Expect(l => l.UnLocode).Return(initialLocation).Repeat.Any();


            // act:
            StoppedVoyage state   = new StoppedVoyage(number, schedule, index);
            VoyageState   arrived = state.StopOverAt(location);

            // assert:
            Assert.AreSame(state, arrived);
            schedule.VerifyAllExpectations();
            movement.VerifyAllExpectations();
            location.VerifyAllExpectations();
        }
예제 #12
0
        public void Ctor_09()
        {
            // arrange:
            UnLocode code1      = new UnLocode("UNFST");
            DateTime loadTime   = DateTime.UtcNow;
            DateTime unloadTime = loadTime + TimeSpan.FromDays(1);

            ILocation loc1 = MockRepository.GenerateStrictMock <ILocation>();

            loc1.Expect(l => l.UnLocode).Return(code1).Repeat.AtLeastOnce();

            ILocation loc2 = MockRepository.GenerateStrictMock <ILocation>();

            loc2.Expect(l => l.UnLocode).Return(new UnLocode("SNDLC")).Repeat.AtLeastOnce();
            IVoyage voyage = MockRepository.GenerateStrictMock <IVoyage>();

            voyage.Expect(v => v.Number).Return(new VoyageNumber("VYGTEST")).Repeat.Once();
            voyage.Expect(v => v.WillStopOverAt(loc1)).Return(true).Repeat.Once();
            voyage.Expect(v => v.WillStopOverAt(loc2)).Return(false).Repeat.Once();

            // assert:
            Assert.Throws <ArgumentException>(delegate { new Leg(voyage, loc1, loadTime, loc2, unloadTime); });
            voyage.VerifyAllExpectations();
            loc1.VerifyAllExpectations();
            loc2.VerifyAllExpectations();
        }
예제 #13
0
        public void WillStopOverAt_08()
        {
            // arrange:
            VoyageNumber number   = new VoyageNumber("VYGTEST01");
            ISchedule    schedule = MockRepository.GenerateStrictMock <ISchedule>();

            schedule.Expect(s => s.MovementsCount).Return(3).Repeat.Any();
            UnLocode         loc1 = new UnLocode("DPLOC");
            ICarrierMovement mov1 = MockRepository.GenerateStrictMock <ICarrierMovement>();

            mov1.Expect(m => m.DepartureLocation).Return(loc1).Repeat.AtLeastOnce();
            //mov1.Expect(m => m.ArrivalLocation).Return(loc2).Repeat.AtLeastOnce();
            schedule.Expect(s => s[0]).Return(mov1).Repeat.Any();
            ILocation location = MockRepository.GenerateStrictMock <ILocation>();

            location.Expect(l => l.UnLocode).Return(loc1).Repeat.AtLeastOnce();

            // act:
            StoppedVoyage state = new StoppedVoyage(number, schedule, 0);
            bool          willStopOverAtLocation = state.WillStopOverAt(location);

            // assert:
            Assert.IsTrue(willStopOverAtLocation);
            location.VerifyAllExpectations();
            schedule.VerifyAllExpectations();
            mov1.VerifyAllExpectations();
        }
예제 #14
0
        public void Ctor_01()
        {
            // arrange:
            UnLocode  dpLocode   = new UnLocode("DPLOC");
            ILocation dpLocation = MockRepository.GenerateStrictMock <ILocation>();

            dpLocation.Expect(l => l.UnLocode).Return(dpLocode).Repeat.AtLeastOnce();
            DateTime  dpTime     = DateTime.UtcNow - new TimeSpan(48, 0, 0);
            UnLocode  arLocode   = new UnLocode("ARLOC");
            ILocation arLocation = MockRepository.GenerateStrictMock <ILocation>();

            arLocation.Expect(l => l.UnLocode).Return(arLocode).Repeat.AtLeastOnce();
            DateTime arTime = DateTime.UtcNow + new TimeSpan(48, 0, 0);

            // act:
            ICarrierMovement target = new CarrierMovement(dpLocation, dpTime, arLocation, arTime);

            // assert:
            Assert.AreEqual(dpTime, target.DepartureTime);
            Assert.AreEqual(arTime, target.ArrivalTime);
            Assert.AreSame(dpLocode, target.DepartureLocation);
            Assert.AreSame(arLocode, target.ArrivalLocation);
            dpLocation.VerifyAllExpectations();
            arLocation.VerifyAllExpectations();
        }
예제 #15
0
        public void Equals_07()
        {
            // arrange:
            UnLocode  dpLocode         = new UnLocode("DPLOC");
            UnLocode  arLocode         = new UnLocode("ARLOC");
            ILocation targetDpLocation = MockRepository.GenerateStrictMock <ILocation>();
            ILocation targetArLocation = MockRepository.GenerateStrictMock <ILocation>();

            targetDpLocation.Expect(l => l.UnLocode).Return(dpLocode).Repeat.AtLeastOnce();
            targetArLocation.Expect(l => l.UnLocode).Return(arLocode).Repeat.AtLeastOnce();
            DateTime dpTime = DateTime.UtcNow - new TimeSpan(48, 0, 0);
            DateTime arTime = DateTime.UtcNow + new TimeSpan(48, 0, 0);

            // act:
            ICarrierMovement target1 = new CarrierMovement(targetDpLocation, dpTime, targetArLocation, arTime);
            ICarrierMovement target2 = new CarrierMovement(targetDpLocation, dpTime, targetArLocation, arTime);

            // assert:
            Assert.IsTrue(target1.Equals(target2));
            Assert.IsTrue(target2.Equals(target1));
            Assert.IsTrue(target1.Equals((object)target2));
            Assert.IsTrue(target2.Equals((object)target1));
            Assert.AreEqual(target1.GetHashCode(), target2.GetHashCode());
            targetDpLocation.VerifyAllExpectations();
            targetArLocation.VerifyAllExpectations();
        }
예제 #16
0
        public void DepartFrom_01(int index)
        {
            // arrange:
            VoyageNumber number   = new VoyageNumber("VYGTEST01");
            ISchedule    schedule = MockRepository.GenerateStrictMock <ISchedule>();

            schedule.Expect(s => s.MovementsCount).Return(3).Repeat.Any();
            UnLocode         initialLocation     = new UnLocode("DPLOC");
            UnLocode         destinationLocation = new UnLocode("ARLOC");
            ICarrierMovement movement            = MockRepository.GenerateStrictMock <ICarrierMovement>();

            movement.Expect(m => m.DepartureLocation).Return(initialLocation).Repeat.Any();
            movement.Expect(m => m.ArrivalLocation).Return(destinationLocation).Repeat.Any();
            schedule.Expect(s => s[index]).Return(movement).Repeat.Any();
            ILocation location = MockRepository.GenerateStrictMock <ILocation>();

            location.Expect(l => l.UnLocode).Return(initialLocation).Repeat.Any();

            // act:
            StoppedVoyage state  = new StoppedVoyage(number, schedule, index);
            VoyageState   moving = state.DepartFrom(location);

            // assert:
            Assert.IsInstanceOf <MovingVoyage>(moving);
            Assert.AreSame(state.LastKnownLocation, moving.LastKnownLocation);
            Assert.AreSame(state.NextExpectedLocation, moving.NextExpectedLocation);
            schedule.VerifyAllExpectations();
            movement.VerifyAllExpectations();
            location.VerifyAllExpectations();
        }
예제 #17
0
        public void Ctor_06()
        {
            // arrange:
            UnLocode  arLocode   = new UnLocode("ARLOC");
            ILocation arLocation = MockRepository.GenerateStrictMock <ILocation>();
            DateTime  dpTime     = DateTime.UtcNow - new TimeSpan(48, 0, 0);
            DateTime  arTime     = DateTime.UtcNow + new TimeSpan(48, 0, 0);

            arLocation.Expect(l => l.UnLocode).Return(arLocode).Repeat.AtLeastOnce();

            // act:
            new CarrierMovement(arLocation, dpTime, arLocation, arTime);
        }
예제 #18
0
        public void Equals_01()
        {
            // arrange:
            DateTime loadTime   = DateTime.UtcNow;
            DateTime unloadTime = DateTime.UtcNow + TimeSpan.FromDays(3);

            VoyageNumber voyageNumber = new VoyageNumber("VYGTEST");
            IVoyage      voyage       = MockRepository.GenerateStrictMock <IVoyage>();

            voyage.Expect(v => v.Number).Return(voyageNumber).Repeat.Any();

            UnLocode  code1 = new UnLocode("CODAA");
            ILocation loc1  = MockRepository.GenerateStrictMock <ILocation>();

            loc1.Expect(l => l.UnLocode).Return(code1).Repeat.Any();

            UnLocode  code2 = new UnLocode("CODAB");
            ILocation loc2  = MockRepository.GenerateStrictMock <ILocation>();

            loc2.Expect(l => l.UnLocode).Return(code2).Repeat.Any();

            voyage.Expect(v => v.WillStopOverAt(loc1)).Return(true).Repeat.AtLeastOnce();
            voyage.Expect(v => v.WillStopOverAt(loc2)).Return(true).Repeat.AtLeastOnce();

            // act:
            ILeg leg1 = new Leg(voyage, loc1, loadTime, loc2, unloadTime);
            ILeg leg2 = new Leg(voyage, loc1, loadTime, loc2, unloadTime);
            ILeg leg3 = MockRepository.GenerateStrictMock <ILeg>();

            leg3.Expect(l => l.Voyage).Return(voyageNumber).Repeat.AtLeastOnce();
            leg3.Expect(l => l.LoadLocation).Return(code1).Repeat.AtLeastOnce();
            leg3.Expect(l => l.UnloadLocation).Return(code2).Repeat.AtLeastOnce();
            leg3.Expect(l => l.LoadTime).Return(loadTime).Repeat.AtLeastOnce();
            leg3.Expect(l => l.UnloadTime).Return(unloadTime).Repeat.AtLeastOnce();

            // assert:
            Assert.AreEqual(leg1.GetHashCode(), leg2.GetHashCode());
            Assert.IsTrue(leg1.Equals(leg2));
            Assert.IsTrue(leg1.Equals(leg3));
            Assert.IsTrue(leg2.Equals(leg1));
            Assert.IsTrue(leg2.Equals(leg3));
            Assert.IsTrue(leg1.Equals((object)leg2));
            Assert.IsTrue(leg1.Equals((object)leg3));
            Assert.IsTrue(leg2.Equals((object)leg1));
            Assert.IsTrue(leg2.Equals((object)leg3));
            voyage.VerifyAllExpectations();
            loc1.VerifyAllExpectations();
            loc2.VerifyAllExpectations();
            leg3.VerifyAllExpectations();
        }
예제 #19
0
        public void Ctor_07()
        {
            // arrange:
            UnLocode  code   = new UnLocode("LOCCD");
            ILocation origin = MockRepository.GenerateStub <ILocation>();

            origin.Expect(l => l.UnLocode).Return(code).Repeat.AtLeastOnce();
            ILocation destination = MockRepository.GenerateStub <ILocation>();

            destination.Expect(l => l.UnLocode).Return(code).Repeat.AtLeastOnce();
            DateTime arrivalDeadline = DateTime.UtcNow - TimeSpan.FromDays(1);

            // assert:
            Assert.Throws <ArgumentException>(delegate { new RouteSpecification(origin, destination, arrivalDeadline); });
            origin.VerifyAllExpectations();
            destination.VerifyAllExpectations();
        }
예제 #20
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();
        }
예제 #21
0
        public void Claim_01()
        {
            // arrange:
            GList        mocks        = new GList();
            TrackingId   id           = new TrackingId("START");
            DateTime     loadTime     = DateTime.Now;
            VoyageNumber voyageNumber = new VoyageNumber("VYG001");
            UnLocode     locCode      = new UnLocode("CURLC");
            ILocation    location     = MockRepository.GenerateStrictMock <ILocation>();

            location.Expect(l => l.UnLocode).Return(locCode).Repeat.Any();
            mocks.Add(location);
            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();
            mocks.Add(specification);
            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(locCode).Repeat.AtLeastOnce();
            mocks.Add(voyage);
            CargoState state = new OnboardCarrierCargo(previousState, voyage, loadTime);

            // assert:
            Assert.Throws <InvalidOperationException>(delegate { state.Claim(location, DateTime.Now + TimeSpan.FromDays(1)); });
            foreach (object mock in mocks)
            {
                mock.VerifyAllExpectations();
            }
        }
예제 #22
0
        public void Ctor_05()
        {
            // arrange:
            UnLocode code       = new UnLocode("UNCOD");
            DateTime loadTime   = DateTime.UtcNow;
            DateTime unloadTime = DateTime.UtcNow + TimeSpan.FromDays(3);

            IVoyage voyage = MockRepository.GenerateStrictMock <IVoyage>();

            ILocation loc1 = MockRepository.GenerateStrictMock <ILocation>();

            loc1.Expect(l => l.UnLocode).Return(code).Repeat.Any();

            ILocation loc2 = MockRepository.GenerateStrictMock <ILocation>();

            loc2.Expect(l => l.UnLocode).Return(code).Repeat.Any();

            // assert:
            Assert.Throws <ArgumentException>(delegate { new Leg(voyage, loc1, loadTime, loc2, unloadTime); });
            loc1.VerifyAllExpectations();
            loc2.VerifyAllExpectations();
        }
예제 #23
0
        public void IsSatisfiedBy_04()
        {
            // arrange:
            UnLocode  first  = new UnLocode("CDFST");
            UnLocode  second = new UnLocode("CDSND");
            ILocation origin = MockRepository.GenerateStrictMock <ILocation>();

            origin.Expect(l => l.UnLocode).Return(first).Repeat.AtLeastOnce();
            ILocation destination = MockRepository.GenerateStrictMock <ILocation>();

            destination.Expect(l => l.UnLocode).Return(second).Repeat.AtLeastOnce();
            DateTime arrivalDeadline = DateTime.UtcNow + TimeSpan.FromDays(5);

            IRouteSpecification specification = new RouteSpecification(origin, destination, arrivalDeadline);

            // act:
            bool satisfied = specification.IsSatisfiedBy(null);

            // assert:
            Assert.IsFalse(satisfied);
            origin.VerifyAllExpectations();
            destination.VerifyAllExpectations();
        }
예제 #24
0
        public void Ctor_01()
        {
            // arrange:
            UnLocode  first  = new UnLocode("CDFST");
            UnLocode  second = new UnLocode("CDSND");
            ILocation origin = MockRepository.GenerateStrictMock <ILocation>();

            origin.Expect(l => l.UnLocode).Return(first).Repeat.AtLeastOnce();
            ILocation destination = MockRepository.GenerateStrictMock <ILocation>();

            destination.Expect(l => l.UnLocode).Return(second).Repeat.AtLeastOnce();
            DateTime arrivalDeadline = DateTime.UtcNow + TimeSpan.FromDays(5);

            // act:
            IRouteSpecification specification = new RouteSpecification(origin, destination, arrivalDeadline);

            // assert:
            Assert.IsNotNull(specification);
            Assert.AreSame(first, specification.Origin);
            Assert.AreSame(second, specification.Destination);
            Assert.AreEqual(arrivalDeadline, specification.ArrivalDeadline);
            origin.VerifyAllExpectations();
            destination.VerifyAllExpectations();
        }