Ejemplo n.º 1
0
        public void Equals_01()
        {
            // arrange:
            UnLocode loc1 = new UnLocode("CODAA");
            UnLocode loc2 = new UnLocode("CODAB");
            UnLocode loc3 = new UnLocode("CODAC");
            ILeg     leg  = MockRepository.GenerateStrictMock <ILeg>();

            leg.Expect(l => l.LoadLocation).Return(loc1).Repeat.Once();
            leg.Expect(l => l.UnloadLocation).Return(loc2).Repeat.Once();
            leg.Expect(l => l.UnloadTime).Return(DateTime.UtcNow).Repeat.Once();
            ILeg leg2 = MockRepository.GenerateStrictMock <ILeg>();

            leg2.Expect(l => l.LoadLocation).Return(loc2).Repeat.Once();
            leg2.Expect(l => l.UnloadLocation).Return(loc3).Repeat.Once();
            leg2.Expect(l => l.LoadTime).Return(DateTime.UtcNow + TimeSpan.FromDays(1)).Repeat.Once();


            // act:
            IItinerary tested = new Itinerary();

            tested = tested.Append(leg);
            tested = tested.Append(leg2);


            // assert:
            Assert.IsFalse(tested.Equals(null));
            Assert.IsTrue(tested.Equals(tested));
            Assert.IsTrue(tested.Equals((object)tested));
        }
Ejemplo n.º 2
0
		public IItinerary ReplaceSegment (IItinerary legs)
		{
			if(null == legs)
				throw new ArgumentNullException("legs");
			
			IItinerary newItinerary = null;
			int i = 0;
			while(i < _legs.Length)
			{
				if(null != newItinerary && newItinerary.FinalArrivalLocation.Equals(_legs[i].LoadLocation))
				{
					newItinerary = newItinerary.Append(_legs[i]);
				}
				else if(_legs[i].UnloadLocation.Equals(legs.InitialDepartureLocation))
				{
					ILeg[] newLegs = new ILeg[i + 1];
					Array.Copy(_legs, newLegs, i + 1);
					newItinerary = new Itinerary(newLegs);
					foreach(ILeg l in legs)
					{
						newItinerary = newItinerary.Append(l);
					}
				}
				
				++i;
			}
			if(null == newItinerary)
			{
				string message = string.Format("The legs departure location ({0}) is not in the itinerary.", legs.InitialDepartureLocation);
				throw new ArgumentOutOfRangeException("legs", message);
			}
			
			return newItinerary;
		}
Ejemplo n.º 3
0
        public void Append_01()
        {
            // arrange:
            UnLocode loc1        = new UnLocode("CODLD");
            UnLocode loc2        = new UnLocode("CODUN");
            DateTime arrivalDate = DateTime.UtcNow + TimeSpan.FromDays(10);
            ILeg     leg         = MockRepository.GenerateStrictMock <ILeg>();

            leg.Expect(l => l.LoadLocation).Return(loc1).Repeat.Once();
            leg.Expect(l => l.UnloadLocation).Return(loc2).Repeat.Once();
            leg.Expect(l => l.UnloadTime).Return(arrivalDate).Repeat.Once();
            Itinerary empty = new Itinerary();

            // act:
            IItinerary tested = empty.Append(leg);

            // assert:
            Assert.IsNotNull(tested);
            Assert.AreEqual(1, tested.Count());
            Assert.AreSame(leg, tested.First());
            Assert.AreSame(leg, tested.Last());
            Assert.AreEqual(loc1, tested.InitialDepartureLocation);
            Assert.AreEqual(loc2, tested.FinalArrivalLocation);
            Assert.AreEqual(arrivalDate, tested.FinalArrivalDate);
            leg.VerifyAllExpectations();
        }
Ejemplo n.º 4
0
 public LegFactory(ILeg _leg)
 {
     if (_leg == null)
     {
         throw new Exception("");              //throw any exception you feel proper here
     }
     this.leg = _leg;
 }
Ejemplo n.º 5
0
Archivo: Leg.cs Proyecto: 3j/dddsample
 public bool has_the_same_value_as(ILeg the_other_leg)
 {
     return the_other_leg != null &&
         underlying_voyage.has_the_same_identity_as(the_other_leg.voyage()) &&
         underlying_load_location.has_the_same_identity_as(the_other_leg.load_location()) &&
         underlying_unload_location.has_the_same_identity_as(the_other_leg.unload_location()) &&
         underlying_load_time.has_the_same_value_as(the_other_leg.load_time()) &&
         underlying_unload_time.has_the_same_value_as(the_other_leg.unload_time());
 }
Ejemplo n.º 6
0
        public void ReplaceSegment_04()
        {
            // arrange:
            ILeg       leg    = MockRepository.GenerateStrictMock <ILeg>();
            Itinerary  empty  = new Itinerary();
            IItinerary tested = empty.Append(leg);

            // act:
            Assert.Throws <ArgumentNullException>(delegate { tested.ReplaceSegment(null); });

            // assert:
            leg.VerifyAllExpectations();
        }
Ejemplo n.º 7
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();
        }
Ejemplo n.º 8
0
        public void Equals_06()
        {
            // arrange:
            UnLocode    loc1    = new UnLocode("CODAA");
            UnLocode    loc2    = new UnLocode("CODAB");
            UnLocode    loc3    = new UnLocode("CODAC");
            UnLocode    loc4    = new UnLocode("CODAD");
            List <ILeg> legs    = new List <ILeg>();
            ILeg        legCopy = MockRepository.GenerateStrictMock <ILeg>();

            legs.Add(legCopy);
            ILeg leg2Copy = MockRepository.GenerateStrictMock <ILeg>();

            legs.Add(leg2Copy);
            ILeg leg = MockRepository.GenerateStrictMock <ILeg>();

            leg.Expect(l => l.Equals(legCopy)).Return(true).Repeat.Any();
            leg.Expect(l => l.LoadLocation).Return(loc1).Repeat.Any();
            leg.Expect(l => l.UnloadLocation).Return(loc2).Repeat.Any();
            leg.Expect(l => l.UnloadTime).Return(DateTime.UtcNow).Repeat.Any();
            ILeg leg2 = MockRepository.GenerateStrictMock <ILeg>();

            leg2.Expect(l => l.Equals(leg2Copy)).Return(true).Repeat.Any();
            leg2.Expect(l => l.LoadLocation).Return(loc2).Repeat.Any();
            leg2.Expect(l => l.UnloadLocation).Return(loc3).Repeat.Any();
            leg2.Expect(l => l.LoadTime).Return(DateTime.UtcNow + TimeSpan.FromDays(1)).Repeat.Any();
            IItinerary candidate = MockRepository.GenerateStrictMock <IItinerary>();

            candidate.Expect(c => c.InitialDepartureLocation).Return(loc4).Repeat.Once();
            candidate.Expect(c => c.FinalArrivalLocation).Return(loc3).Repeat.Any();
            candidate.Expect(c => c.GetEnumerator()).Return(legs.GetEnumerator()).Repeat.Any();

            // act:
            IItinerary tested = new Itinerary();

            tested = tested.Append(leg);
            tested = tested.Append(leg2);

            // assert:
            Assert.IsFalse(tested.Equals(candidate));
            candidate.VerifyAllExpectations();
            leg.VerifyAllExpectations();
            leg2.VerifyAllExpectations();
            foreach (ILeg l in legs)
            {
                l.VerifyAllExpectations();
            }
        }
Ejemplo n.º 9
0
 public bool Equals(ILeg other)
 {
     if (null == other)
     {
         return(false);
     }
     if (object.ReferenceEquals(this, other))
     {
         return(true);
     }
     return(_voyage.Equals(other.Voyage) &&
            _loadLocation.Equals(other.LoadLocation) &&
            _unloadLocation.Equals(other.UnloadLocation) &&
            _loadTime.Equals(other.LoadTime) &&
            _unloadTime.Equals(other.UnloadTime));
 }
Ejemplo n.º 10
0
		public IItinerary Append (ILeg leg)
		{
			if(null == leg)
				throw new ArgumentNullException("leg");
			if(_legs.Length > 0)
			{
				if(leg.LoadLocation != _legs[_legs.Length - 1].UnloadLocation)
					throw new ArgumentException("Invalid load location.", "leg");
				if(leg.LoadTime < _legs[_legs.Length - 1].UnloadTime)
					throw new ArgumentException("Invalid load time.", "leg");
			}
			ILeg[] newLegs = new ILeg[_legs.Length + 1];
			Array.Copy(_legs, newLegs, _legs.Length);
			newLegs[_legs.Length] = leg;
			return new Itinerary(newLegs);
		}
Ejemplo n.º 11
0
        public void Append_04()
        {
            // arrange:
            UnLocode loc2 = new UnLocode("CODAB");
            UnLocode loc3 = new UnLocode("CDOUT");
            ILeg     leg  = MockRepository.GenerateStrictMock <ILeg>();

            leg.Expect(l => l.UnloadLocation).Return(loc2).Repeat.Once();
            ILeg leg2 = MockRepository.GenerateStrictMock <ILeg>();

            leg2.Expect(l => l.LoadLocation).Return(loc3).Repeat.Once();
            IItinerary initial = new Itinerary();

            initial = initial.Append(leg);

            // assert:
            Assert.Throws <ArgumentException>(delegate { initial.Append(leg2); });
            leg.VerifyAllExpectations();
            leg2.VerifyAllExpectations();
        }
Ejemplo n.º 12
0
 public IItinerary Append(ILeg leg)
 {
     if (null == leg)
     {
         throw new ArgumentNullException("leg");
     }
     if (_legs.Length > 0)
     {
         if (leg.LoadLocation != _legs[_legs.Length - 1].UnloadLocation)
         {
             throw new ArgumentException("Invalid load location.", "leg");
         }
         if (leg.LoadTime < _legs[_legs.Length - 1].UnloadTime)
         {
             throw new ArgumentException("Invalid load time.", "leg");
         }
     }
     ILeg[] newLegs = new ILeg[_legs.Length + 1];
     Array.Copy(_legs, newLegs, _legs.Length);
     newLegs[_legs.Length] = leg;
     return(new Itinerary(newLegs));
 }
Ejemplo n.º 13
0
        public void Append_05()
        {
            // arrange:
            UnLocode loc1 = new UnLocode("CODAA");
            UnLocode loc2 = new UnLocode("CODAB");
            ILeg     leg  = MockRepository.GenerateStrictMock <ILeg>();

            leg.Expect(l => l.LoadLocation).Return(loc1).Repeat.Any();
            leg.Expect(l => l.UnloadLocation).Return(loc2).Repeat.Once();
            leg.Expect(l => l.UnloadTime).Return(DateTime.UtcNow).Repeat.Once();
            ILeg leg2 = MockRepository.GenerateStrictMock <ILeg>();

            leg2.Expect(l => l.LoadLocation).Return(loc2).Repeat.Any();
            leg2.Expect(l => l.LoadTime).Return(DateTime.UtcNow - TimeSpan.FromDays(1)).Repeat.Once();
            IItinerary initial = new Itinerary();

            initial = initial.Append(leg);

            // assert:
            Assert.Throws <ArgumentException>(delegate { initial.Append(leg2); });
            leg.VerifyAllExpectations();
            leg2.VerifyAllExpectations();
        }
Ejemplo n.º 14
0
        public IItinerary ReplaceSegment(IItinerary legs)
        {
            if (null == legs)
            {
                throw new ArgumentNullException("legs");
            }

            IItinerary newItinerary = null;
            int        i            = 0;

            while (i < _legs.Length)
            {
                if (null != newItinerary && newItinerary.FinalArrivalLocation.Equals(_legs[i].LoadLocation))
                {
                    newItinerary = newItinerary.Append(_legs[i]);
                }
                else if (_legs[i].UnloadLocation.Equals(legs.InitialDepartureLocation))
                {
                    ILeg[] newLegs = new ILeg[i + 1];
                    Array.Copy(_legs, newLegs, i + 1);
                    newItinerary = new Itinerary(newLegs);
                    foreach (ILeg l in legs)
                    {
                        newItinerary = newItinerary.Append(l);
                    }
                }

                ++i;
            }
            if (null == newItinerary)
            {
                string message = string.Format("The legs departure location ({0}) is not in the itinerary.", legs.InitialDepartureLocation);
                throw new ArgumentOutOfRangeException("legs", message);
            }

            return(newItinerary);
        }
Ejemplo n.º 15
0
 public void SetLeftLeg2(ILeg leg)
 {
     _leftLeg2 = leg;
 }
Ejemplo n.º 16
0
 public void SetLeftLeg(ILeg leg)
 {
     _leftLeg = leg;
 }
Ejemplo n.º 17
0
		public bool Equals (ILeg other)
		{
			if(null == other)
				return false;
			if(object.ReferenceEquals(this, other))
				return true;
			return _voyage.Equals(other.Voyage) 
					&& _loadLocation.Equals(other.LoadLocation) 
					&& _unloadLocation.Equals(other.UnloadLocation) 
					&& _loadTime.Equals(other.LoadTime) 
					&& _unloadTime.Equals(other.UnloadTime);
		}
Ejemplo n.º 18
0
		private Itinerary (ILeg[] legs)
		{
			_legs = legs;
		}
Ejemplo n.º 19
0
        public void Equals_02()
        {
            // arrange:
            UnLocode    loc1    = new UnLocode("CODAA");
            UnLocode    loc2    = new UnLocode("CODAB");
            UnLocode    loc3    = new UnLocode("CODAC");
            List <ILeg> legs    = new List <ILeg>();
            ILeg        legCopy = MockRepository.GenerateStrictMock <ILeg>();

            legs.Add(legCopy);
            ILeg leg2Copy = MockRepository.GenerateStrictMock <ILeg>();

            legs.Add(leg2Copy);
            ILeg leg = MockRepository.GenerateStrictMock <ILeg, IObject>();

            leg.Expect(l => l.Equals(leg)).Return(true).Repeat.AtLeastOnce();
            leg.Expect(l => l.Equals(legCopy)).Return(true).Repeat.AtLeastOnce();
            leg.Expect(l => l.LoadLocation).Return(loc1).Repeat.AtLeastOnce();
            leg.Expect(l => l.UnloadLocation).Return(loc2).Repeat.AtLeastOnce();
            leg.Expect(l => l.UnloadTime).Return(DateTime.UtcNow).Repeat.AtLeastOnce();
            leg.Expect(l => l.GetHashCode()).Return(543210).Repeat.AtLeastOnce();
            ILeg leg2 = MockRepository.GenerateStrictMock <ILeg, IObject>();

            leg2.Expect(l => l.Equals(leg2)).Return(true).Repeat.AtLeastOnce();
            leg2.Expect(l => l.Equals(leg2Copy)).Return(true).Repeat.AtLeastOnce();
            leg2.Expect(l => l.LoadLocation).Return(loc2).Repeat.AtLeastOnce();
            leg2.Expect(l => l.UnloadLocation).Return(loc3).Repeat.AtLeastOnce();
            leg2.Expect(l => l.LoadTime).Return(DateTime.UtcNow + TimeSpan.FromDays(1)).Repeat.AtLeastOnce();
            IItinerary candidate = MockRepository.GenerateStrictMock <IItinerary>();

            candidate.Expect(c => c.InitialDepartureLocation).Return(loc1).Repeat.AtLeastOnce();
            candidate.Expect(c => c.FinalArrivalLocation).Return(loc3).Repeat.AtLeastOnce();
            candidate.Expect(c => c.GetEnumerator()).Return(legs.GetEnumerator()).Repeat.Once();
            candidate.Expect(c => c.GetEnumerator()).Return(legs.GetEnumerator()).Repeat.Once();
            candidate.Expect(c => c.GetEnumerator()).Return(legs.GetEnumerator()).Repeat.Once();
            candidate.Expect(c => c.GetEnumerator()).Return(legs.GetEnumerator()).Repeat.Once();

            // act:
            IItinerary tested = new Itinerary();

            tested = tested.Append(leg);
            tested = tested.Append(leg2);
            IItinerary tested2 = new Itinerary();

            tested2 = tested2.Append(leg);
            tested2 = tested2.Append(leg2);

            // assert:
            Assert.IsTrue(tested.Equals(candidate));
            Assert.IsTrue(tested.Equals((object)candidate));
            Assert.IsTrue(tested.Equals(tested2));
            Assert.IsTrue(tested.Equals((object)tested2));
            Assert.IsTrue(tested2.Equals(tested));
            Assert.IsTrue(tested2.Equals((object)tested));
            Assert.AreEqual(tested.GetHashCode(), tested2.GetHashCode());
            CollectionAssert.AreEqual(tested, tested.AsWeakEnumerable());
            CollectionAssert.AreEqual(tested, tested2);
            candidate.VerifyAllExpectations();
            leg.VerifyAllExpectations();
            leg2.VerifyAllExpectations();
            foreach (ILeg l in legs)
            {
                l.VerifyAllExpectations();
            }
        }
Ejemplo n.º 20
0
        public void ReplaceSegment_05()
        {
            // arrange:
            UnLocode loc1 = new UnLocode("CODAA");
            UnLocode loc2 = new UnLocode("CODAB");
            UnLocode loc3 = new UnLocode("CODAC");
            UnLocode loc4 = new UnLocode("CODAD");
            UnLocode loc5 = new UnLocode("CODAE");
            UnLocode loc6 = new UnLocode("CODAF");

            List <ILeg> newLegs = new List <ILeg>();
            ILeg        newLeg1 = MockRepository.GenerateStrictMock <ILeg>();

            newLeg1.Expect(l => l.LoadLocation).Return(new UnLocode("OTHER")).Repeat.Any();
            newLeg1.Expect(l => l.LoadTime).Return(DateTime.UtcNow + TimeSpan.FromDays(1)).Repeat.Any();
            newLeg1.Expect(l => l.UnloadTime).Return(DateTime.UtcNow + TimeSpan.FromDays(3)).Repeat.Any();
            newLeg1.Expect(l => l.UnloadLocation).Return(loc5).Repeat.Any();
            newLegs.Add(newLeg1);
            ILeg newLeg2 = MockRepository.GenerateStrictMock <ILeg>();

            newLeg2.Expect(l => l.LoadLocation).Return(loc5).Repeat.Any();
            newLeg2.Expect(l => l.LoadTime).Return(DateTime.UtcNow + TimeSpan.FromDays(4)).Repeat.Any();
            newLeg2.Expect(l => l.UnloadTime).Return(DateTime.UtcNow + TimeSpan.FromDays(6)).Repeat.Any();
            newLeg2.Expect(l => l.UnloadLocation).Return(loc6).Repeat.Any();
            newLegs.Add(newLeg2);
            ILeg newLeg3 = MockRepository.GenerateStrictMock <ILeg>();

            newLeg3.Expect(l => l.LoadLocation).Return(loc6).Repeat.Any();
            newLeg3.Expect(l => l.LoadTime).Return(DateTime.UtcNow + TimeSpan.FromDays(10)).Repeat.Any();
            newLeg3.Expect(l => l.UnloadLocation).Return(loc3).Repeat.Any();
            newLeg3.Expect(l => l.UnloadTime).Return(DateTime.UtcNow + TimeSpan.FromDays(13)).Repeat.Any();
            newLegs.Add(newLeg3);
            IItinerary newSegment = MockRepository.GenerateStrictMock <IItinerary>();

            newSegment.Expect(s => s.GetEnumerator()).Return(newLegs.GetEnumerator()).Repeat.Any();
            newSegment.Expect(s => s.InitialDepartureLocation).Return(new UnLocode("OTHER")).Repeat.Any();
            newSegment.Expect(s => s.FinalArrivalLocation).Return(loc3).Repeat.Any();

            ILeg leg = MockRepository.GenerateStrictMock <ILeg>();

            leg.Expect(l => l.LoadLocation).Return(loc1).Repeat.Any();
            leg.Expect(l => l.UnloadLocation).Return(loc2).Repeat.Any();
            leg.Expect(l => l.UnloadTime).Return(DateTime.UtcNow).Repeat.Any();
            ILeg leg2 = MockRepository.GenerateStrictMock <ILeg>();

            leg2.Expect(l => l.LoadLocation).Return(loc2).Repeat.Any();
            leg2.Expect(l => l.UnloadLocation).Return(loc3).Repeat.Any();
            leg2.Expect(l => l.LoadTime).Return(DateTime.UtcNow + TimeSpan.FromHours(5)).Repeat.Any();
            leg2.Expect(l => l.UnloadTime).Return(DateTime.UtcNow + TimeSpan.FromHours(20)).Repeat.Any();
            ILeg leg3 = MockRepository.GenerateStrictMock <ILeg>();

            leg3.Expect(l => l.LoadLocation).Return(loc3).Repeat.Any();
            leg3.Expect(l => l.UnloadLocation).Return(loc4).Repeat.Any();
            leg3.Expect(l => l.LoadTime).Return(DateTime.UtcNow + TimeSpan.FromDays(30)).Repeat.Any();
            leg3.Expect(l => l.UnloadTime).Return(DateTime.UtcNow + TimeSpan.FromHours(32)).Repeat.Any();
            IItinerary tested = new Itinerary();

            tested = tested.Append(leg);
            tested = tested.Append(leg2);
            tested = tested.Append(leg3);

            // act:
            Assert.Throws <ArgumentOutOfRangeException>(delegate { tested.ReplaceSegment(newSegment); });

            // assert:
            leg.VerifyAllExpectations();
            leg2.VerifyAllExpectations();
            leg3.VerifyAllExpectations();
            foreach (ILeg l in newLegs)
            {
                l.VerifyAllExpectations();
            }
        }
Ejemplo n.º 21
0
        public void ReplaceSegment_02()
        {
            // arrange:
            UnLocode loc1 = new UnLocode("CODAA");
            UnLocode loc2 = new UnLocode("CODAB");
            UnLocode loc3 = new UnLocode("CODAC");
            UnLocode loc4 = new UnLocode("CODAD");
            UnLocode loc5 = new UnLocode("CODAE");
            UnLocode loc6 = new UnLocode("CODAF");

            List <ILeg> newLegs = new List <ILeg>();
            ILeg        newLeg1 = MockRepository.GenerateStrictMock <ILeg>();

            newLeg1.Expect(l => l.LoadLocation).Return(loc3).Repeat.AtLeastOnce();
            newLeg1.Expect(l => l.LoadTime).Return(DateTime.UtcNow + TimeSpan.FromDays(1)).Repeat.AtLeastOnce();
            newLeg1.Expect(l => l.UnloadTime).Return(DateTime.UtcNow + TimeSpan.FromDays(3)).Repeat.Any();
            newLeg1.Expect(l => l.UnloadLocation).Return(loc4).Repeat.AtLeastOnce();
            newLegs.Add(newLeg1);
            ILeg newLeg2 = MockRepository.GenerateStrictMock <ILeg>();

            newLeg2.Expect(l => l.LoadLocation).Return(loc4).Repeat.AtLeastOnce();
            newLeg2.Expect(l => l.LoadTime).Return(DateTime.UtcNow + TimeSpan.FromDays(4)).Repeat.Any();
            newLeg2.Expect(l => l.UnloadTime).Return(DateTime.UtcNow + TimeSpan.FromDays(6)).Repeat.Any();
            newLeg2.Expect(l => l.UnloadLocation).Return(loc5).Repeat.AtLeastOnce();
            newLegs.Add(newLeg2);
            ILeg newLeg3 = MockRepository.GenerateStrictMock <ILeg>();

            newLeg3.Expect(l => l.LoadLocation).Return(loc5).Repeat.AtLeastOnce();
            newLeg3.Expect(l => l.LoadTime).Return(DateTime.UtcNow + TimeSpan.FromDays(10)).Repeat.Any();
            newLeg3.Expect(l => l.UnloadLocation).Return(loc6).Repeat.AtLeastOnce();
            newLeg3.Expect(l => l.UnloadTime).Return(DateTime.UtcNow + TimeSpan.FromDays(13)).Repeat.Any();
            newLegs.Add(newLeg3);
            IItinerary newSegment = MockRepository.GenerateStrictMock <IItinerary>();

            newSegment.Expect(s => s.GetEnumerator()).Return(newLegs.GetEnumerator()).Repeat.AtLeastOnce();
            newSegment.Expect(s => s.InitialDepartureLocation).Return(loc3).Repeat.AtLeastOnce();
            newSegment.Expect(s => s.FinalArrivalLocation).Return(loc6).Repeat.Any();

            ILeg leg = MockRepository.GenerateStrictMock <ILeg>();

            leg.Expect(l => l.LoadLocation).Return(loc1).Repeat.Any();
            leg.Expect(l => l.UnloadLocation).Return(loc2).Repeat.Any();
            leg.Expect(l => l.UnloadTime).Return(DateTime.UtcNow).Repeat.Any();
            ILeg leg2 = MockRepository.GenerateStrictMock <ILeg>();

            leg2.Expect(l => l.LoadLocation).Return(loc2).Repeat.Any();
            leg2.Expect(l => l.UnloadLocation).Return(loc3).Repeat.Any();
            leg2.Expect(l => l.LoadTime).Return(DateTime.UtcNow + TimeSpan.FromHours(5)).Repeat.Any();
            leg2.Expect(l => l.UnloadTime).Return(DateTime.UtcNow + TimeSpan.FromHours(20)).Repeat.Any();
            IItinerary tested = new Itinerary();

            tested = tested.Append(leg);
            tested = tested.Append(leg2);

            // act:
            IItinerary replaced = tested.ReplaceSegment(newSegment);

            // assert:
            Assert.IsNotNull(replaced);
            Assert.AreEqual(5, replaced.Count());
            Assert.AreEqual(loc1, replaced.InitialDepartureLocation);
            Assert.AreEqual(loc6, replaced.FinalArrivalLocation);
            leg.VerifyAllExpectations();
            leg2.VerifyAllExpectations();
            foreach (ILeg l in newLegs)
            {
                l.VerifyAllExpectations();
            }
        }