예제 #1
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);
        }
예제 #2
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();
        }
예제 #3
0
		public void Voyage_LiveCycle_01 ()
		{
			// 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;
			
			// act:
			Challenge00.DDDSample.Voyage.Voyage voyage = new Challenge00.DDDSample.Voyage.Voyage(number, schedule);
			voyage.Departed += delegate(object sender, VoyageEventArgs e) {
				departedEvent = e;
			};
			voyage.Stopped += delegate(object sender, VoyageEventArgs e) {
				stoppedEvent = e;
			};
			
			// assert:
			Assert.AreSame(number, voyage.Number);
			Assert.IsFalse(voyage.IsMoving);
			Assert.AreEqual(code1, voyage.LastKnownLocation);
			Assert.AreEqual(code2, voyage.NextExpectedLocation);
			Assert.IsNull(departedEvent);
			Assert.IsNull(stoppedEvent);
			loc1.VerifyAllExpectations();
			loc2.VerifyAllExpectations();
			loc3.VerifyAllExpectations();
		}
예제 #4
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);
		}