예제 #1
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();
        }
예제 #2
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();
        }
예제 #3
0
        public void Ctor_withValidArguments_works()
        {
            // arrange:
            VoyageNumber number    = new VoyageNumber("VYG01");
            UnLocode     departure = new UnLocode("DPLOC");
            UnLocode     arrival   = new UnLocode("ARLOC");
            ISchedule    schedule  = MockRepository.GenerateStrictMock <ISchedule>();

            schedule.Expect(s => s.MovementsCount).Return(3).Repeat.Any();
            ICarrierMovement movement = MockRepository.GenerateStrictMock <ICarrierMovement>();

            movement.Expect(m => m.DepartureLocation).Return(departure).Repeat.Once();
            movement.Expect(m => m.ArrivalLocation).Return(arrival).Repeat.Once();
            schedule.Expect(s => s[0]).Return(movement).Repeat.AtLeastOnce();

            // act:
            IVoyage voyage = new Challenge00.DDDSample.Voyage.Voyage(number, schedule);

            // assert:
            Assert.AreEqual(number, voyage.Number);
            Assert.AreSame(departure, voyage.LastKnownLocation);
            Assert.AreSame(arrival, voyage.NextExpectedLocation);
            Assert.AreSame(schedule, voyage.Schedule);
            Assert.IsFalse(voyage.IsMoving);
        }
예제 #4
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();
        }
예제 #5
0
        public void Equals_01(int index)
        {
            // arrange:
            VoyageNumber     number          = new VoyageNumber("VYGTEST01");
            UnLocode         initialLocation = new UnLocode("DPLOC");
            ICarrierMovement movement        = MockRepository.GenerateStrictMock <ICarrierMovement, IObject>();

            movement.Expect(m => m.DepartureLocation).Return(initialLocation).Repeat.Any();
            ISchedule schedule = MockRepository.GenerateStrictMock <ISchedule>();

            schedule.Expect(s => s.MovementsCount).Return(3).Repeat.Any();
            schedule.Expect(s => s.Equals(schedule)).Return(true).Repeat.Any();
            schedule.Expect(s => s[index]).Return(movement).Repeat.Any();

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

            // assert:
            Assert.IsFalse(state1.Equals(null));
            Assert.IsTrue(state1.Equals(state1));
            Assert.IsTrue(state1.Equals(state2));
            Assert.IsTrue(state2.Equals(state1));
            Assert.IsTrue(state1.Equals((object)state1));
            Assert.IsTrue(state1.Equals((object)state2));
            Assert.IsTrue(state2.Equals((object)state1));
            Assert.AreEqual(state1.GetHashCode(), state2.GetHashCode());
            schedule.VerifyAllExpectations();
            movement.VerifyAllExpectations();
        }
예제 #6
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();
        }
예제 #7
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();
        }
예제 #8
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();
        }
예제 #9
0
        public void Equals_05()
        {
            // arrange:
            VoyageNumber number   = new VoyageNumber("VYGTEST01");
            ISchedule    schedule = MockRepository.GenerateStrictMock <ISchedule>();

            schedule.Expect(s => s.MovementsCount).Return(3).Repeat.Any();
            schedule.Expect(s => s.Equals(schedule)).Return(true).Repeat.Any();

            // act:
            CompletedVoyage state1 = new CompletedVoyage(number, schedule);
            VoyageState     state2 = new StoppedVoyage(number, schedule, 2);

            // assert:
            Assert.IsFalse(state1.Equals(state2));
            schedule.VerifyAllExpectations();
        }
예제 #10
0
        public void Equals_02(int index)
        {
            // arrange:
            VoyageNumber number   = new VoyageNumber("VYGTEST01");
            ISchedule    schedule = MockRepository.GenerateStrictMock <ISchedule>();

            schedule.Expect(s => s.MovementsCount).Return(4).Repeat.Any();
            schedule.Expect(s => s.Equals(schedule)).Return(true).Repeat.Any();

            // act:
            MovingVoyage state1 = new MovingVoyage(number, schedule, index);
            MovingVoyage state2 = new MovingVoyage(number, schedule, index + 1);

            // assert:
            Assert.IsFalse(state1.Equals(state2));
            Assert.IsFalse(state2.Equals(state1));
            schedule.VerifyAllExpectations();
        }
예제 #11
0
        public void Ctor_03()
        {
            // arrange:
            ISchedule schedule = MockRepository.GenerateStrictMock <ISchedule>();

            schedule.Expect(s => s.MovementsCount).Return(3).Repeat.Any();

            // act:
            new CompletedVoyage(null, schedule);
        }
예제 #12
0
        public void Ctor_03(int index)
        {
            // arrange:
            VoyageNumber number   = new VoyageNumber("VYGTEST01");
            ISchedule    schedule = MockRepository.GenerateStrictMock <ISchedule>();

            schedule.Expect(s => s.MovementsCount).Return(3).Repeat.Any();

            // act:
            new StoppedVoyage(number, schedule, index);
        }
예제 #13
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();
        }
예제 #14
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:
            MovingVoyage state = new MovingVoyage(number, schedule, index);

            // assert:
            Assert.AreSame(initialLocation, state.LastKnownLocation);
            movement.VerifyAllExpectations();
            schedule.VerifyAllExpectations();
        }
예제 #15
0
        public void Equals_03(int index)
        {
            // arrange:
            VoyageNumber number    = new VoyageNumber("VYGTEST01");
            ISchedule    schedule1 = MockRepository.GenerateStrictMock <ISchedule>();
            ISchedule    schedule2 = MockRepository.GenerateStrictMock <ISchedule>();

            schedule1.Expect(s => s.MovementsCount).Return(3).Repeat.Any();
            schedule1.Expect(s => s.Equals(schedule2)).Return(false).Repeat.Any();
            schedule2.Expect(s => s.MovementsCount).Return(3).Repeat.Any();
            schedule2.Expect(s => s.Equals(schedule1)).Return(false).Repeat.Any();

            // act:
            StoppedVoyage state1 = new StoppedVoyage(number, schedule1, index);
            StoppedVoyage state2 = new StoppedVoyage(number, schedule2, index);

            // assert:
            Assert.IsFalse(state1.Equals(state2));
            Assert.IsFalse(state2.Equals(state1));
            schedule1.VerifyAllExpectations();
            schedule2.VerifyAllExpectations();
        }
예제 #16
0
        public void Ctor_01()
        {
            // arrange:
            VoyageNumber number   = new VoyageNumber("VYGTEST01");
            ISchedule    schedule = MockRepository.GenerateStrictMock <ISchedule>();

            schedule.Expect(s => s.MovementsCount).Return(3).Repeat.Any();

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

            // assert:
            Assert.AreSame(schedule, state.Schedule);
            Assert.IsFalse(state.IsMoving);
        }
예제 #17
0
        public void WillStopOverAt_01()
        {
            // arrange:
            VoyageNumber number   = new VoyageNumber("VYGTEST01");
            ISchedule    schedule = MockRepository.GenerateStrictMock <ISchedule>();

            schedule.Expect(s => s.MovementsCount).Return(3).Repeat.Any();
            ILocation location = MockRepository.GenerateStrictMock <ILocation>();

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

            // assert:
            Assert.IsFalse(willStopOverAtLocation);
            location.VerifyAllExpectations();
            schedule.VerifyAllExpectations();
        }