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(); }
public bool Equals(IItinerary other) { if (object.ReferenceEquals(other, null)) { return(false); } if (object.ReferenceEquals(this, other)) { return(true); } if (_legs.Length != other.Count()) { return(false); } if (_legs.Length == 0) { return(true); } if (!InitialDepartureLocation.Equals(other.InitialDepartureLocation)) { return(false); } if (!FinalArrivalLocation.Equals(other.FinalArrivalLocation)) { return(false); } int i = 0; foreach (ILeg l in other) { if (!_legs[i].Equals(l)) { return(false); } ++i; } return(true); }
public bool Equals(IItinerary other) { if(object.ReferenceEquals(other, null)) return false; if(object.ReferenceEquals(this, other)) return true; if(_legs.Length != other.Count()) return false; if(_legs.Length == 0) return true; if(! InitialDepartureLocation.Equals(other.InitialDepartureLocation)) return false; if(! FinalArrivalLocation.Equals(other.FinalArrivalLocation)) return false; int i = 0; foreach(ILeg l in other) { if(! _legs[i].Equals(l)) return false; ++i; } return true; }
public void ReplaceSegment_03() { // 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(loc2).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(loc5).Repeat.AtLeastOnce(); newLegs.Add(newLeg1); ILeg newLeg2 = MockRepository.GenerateStrictMock <ILeg>(); newLeg2.Expect(l => l.LoadLocation).Return(loc5).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(loc6).Repeat.AtLeastOnce(); newLegs.Add(newLeg2); ILeg newLeg3 = MockRepository.GenerateStrictMock <ILeg>(); newLeg3.Expect(l => l.LoadLocation).Return(loc6).Repeat.AtLeastOnce(); newLeg3.Expect(l => l.LoadTime).Return(DateTime.UtcNow + TimeSpan.FromDays(10)).Repeat.Any(); newLeg3.Expect(l => l.UnloadLocation).Return(loc3).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(loc2).Repeat.AtLeastOnce(); 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: IItinerary replaced = tested.ReplaceSegment(newSegment); // assert: Assert.IsNotNull(replaced); Assert.AreEqual(5, replaced.Count()); Assert.AreEqual(loc1, replaced.InitialDepartureLocation); Assert.AreEqual(loc4, replaced.FinalArrivalLocation); leg.VerifyAllExpectations(); leg2.VerifyAllExpectations(); leg3.VerifyAllExpectations(); foreach (ILeg l in newLegs) { l.VerifyAllExpectations(); } }