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); }
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(); }
public void Equals_04() { // arrange: ICarrierMovement m1 = MockRepository.GenerateStrictMock <ICarrierMovement, IObject>(); ICarrierMovement m2 = MockRepository.GenerateStrictMock <ICarrierMovement, IObject>(); m1.Expect(m => m.Equals(m2)).Return(true).Repeat.AtLeastOnce(); m2.Expect(m => m.Equals(m1)).Return(true).Repeat.AtLeastOnce(); m1.Expect(m => m.GetHashCode()).Return(543210).Repeat.AtLeastOnce(); m2.Expect(m => m.GetHashCode()).Return(543210).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.IsTrue(equals1); Assert.IsTrue(equals2); Assert.AreEqual(schedule1.GetHashCode(), schedule2.GetHashCode()); m1.VerifyAllExpectations(); m2.VerifyAllExpectations(); }
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(); }
public void Append_03() { // arrange: UnLocode c1 = new UnLocode("LOCDA"); UnLocode c2 = new UnLocode("LOCDA"); ICarrierMovement m1 = MockRepository.GenerateStrictMock <ICarrierMovement>(); m1.Expect(m => m.ArrivalLocation).Return(c1).Repeat.Any(); m1.Expect(m => m.ArrivalTime).Return(DateTime.UtcNow + new TimeSpan(48, 0, 0)).Repeat.Any(); ICarrierMovement m2 = MockRepository.GenerateStrictMock <ICarrierMovement>(); m2.Expect(m => m.DepartureLocation).Return(c2).Repeat.Any(); m2.Expect(m => m.DepartureTime).Return(DateTime.UtcNow + new TimeSpan(72, 0, 0)).Repeat.Any(); ISchedule empty = new Schedule(); ISchedule schedule1 = empty.Append(m1); // act: ISchedule schedule2 = schedule1.Append(m2); // assert: Assert.IsFalse(schedule2.Equals(empty)); Assert.IsFalse(schedule2.Equals(schedule1)); Assert.AreSame(m1, schedule2[0]); Assert.AreSame(m2, schedule2[1]); Assert.AreEqual(2, schedule2.Count()); Assert.AreEqual(2, schedule2.MovementsCount); m1.VerifyAllExpectations(); m2.VerifyAllExpectations(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
public void Append_05() { // arrange: UnLocode c1 = new UnLocode("LOCDA"); ICarrierMovement m1 = MockRepository.GenerateStrictMock <ICarrierMovement>(); m1.Expect(m => m.ArrivalLocation).Return(c1).Repeat.Any(); m1.Expect(m => m.ArrivalTime).Return(DateTime.UtcNow + new TimeSpan(48, 0, 0)).Repeat.Any(); ICarrierMovement m2 = MockRepository.GenerateStrictMock <ICarrierMovement>(); m2.Expect(m => m.DepartureLocation).Return(c1).Repeat.Any(); m2.Expect(m => m.DepartureTime).Return(DateTime.UtcNow).Repeat.Any(); ISchedule empty = new Schedule(); ISchedule schedule1 = empty.Append(m1); // act: schedule1.Append(m2); }
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(); }
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(); }
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(); }