Example #1
0
        public void WillStopOverAt_02()
        {
            // arrange:
            VoyageNumber number   = new VoyageNumber("VYGTEST01");
            ISchedule    schedule = MockRepository.GenerateStrictMock <ISchedule>();

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

            mov2.Expect(m => m.DepartureLocation).Return(loc2).Repeat.Any();
            mov2.Expect(m => m.ArrivalLocation).Return(loc3).Repeat.AtLeastOnce();
            schedule.Expect(s => s[1]).Return(mov2).Repeat.Any();
            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>();

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

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

            // assert:
            Assert.IsTrue(willStopOverAtLocation);
            location.VerifyAllExpectations();
            schedule.VerifyAllExpectations();
            mov2.VerifyAllExpectations();
            mov3.VerifyAllExpectations();
        }
Example #2
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:
            MovingVoyage state = new MovingVoyage(number, schedule, index);

            // assert:
            Assert.Throws <ArgumentException>(delegate { state.DepartFrom(location); });
            schedule.VerifyAllExpectations();
            movement.VerifyAllExpectations();
            location.VerifyAllExpectations();
        }
Example #3
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:
            MovingVoyage state  = new MovingVoyage(number, schedule, index);
            VoyageState  moving = state.DepartFrom(location);

            // assert:
            Assert.AreSame(state, moving);
            schedule.VerifyAllExpectations();
            movement.VerifyAllExpectations();
            location.VerifyAllExpectations();
        }
Example #4
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();
        }
Example #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();
        }
Example #6
0
        public void NextExpectedLocation_01()
        {
            // arrange:
            VoyageNumber number   = new VoyageNumber("VYGTEST01");
            ISchedule    schedule = MockRepository.GenerateStrictMock <ISchedule>();

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

            movement.Expect(m => m.ArrivalLocation).Return(arrivalLocation).Repeat.Once();
            schedule.Expect(s => s[2]).Return(movement).Repeat.Once();

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

            // assert:
            Assert.AreSame(arrivalLocation, state.NextExpectedLocation);
            movement.VerifyAllExpectations();
            schedule.VerifyAllExpectations();
        }
Example #7
0
        public void LastKnownLocation_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();

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

            // assert:
            Assert.AreSame(initialLocation, state.LastKnownLocation);
            movement.VerifyAllExpectations();
            schedule.VerifyAllExpectations();
        }
Example #8
0
        public void Equals_05()
        {
            // arrange:
            ICarrierMovement m1 = MockRepository.GenerateStrictMock <ICarrierMovement>();
            ICarrierMovement m2 = MockRepository.GenerateStrictMock <ICarrierMovement>();

            m1.Expect(m => m.Equals(m2)).Return(false).Repeat.AtLeastOnce();
            m2.Expect(m => m.Equals(m1)).Return(false).Repeat.AtLeastOnce();

            ISchedule empty     = new Schedule();
            ISchedule schedule1 = empty.Append(m1);
            ISchedule schedule2 = empty.Append(m2);

            // act:
            bool equals1 = schedule1.Equals(schedule2);
            bool equals2 = schedule2.Equals(schedule1);

            // assert:
            Assert.IsFalse(equals1);
            Assert.IsFalse(equals2);
            m1.VerifyAllExpectations();
            m2.VerifyAllExpectations();
        }