public void Recieve_02() { // arrange: TrackingId id = new TrackingId("CRG01"); UnLocode start = new UnLocode("START"); UnLocode other = new UnLocode("OTHER"); IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>(); ILocation location = MockRepository.GenerateMock <ILocation>(); location.Expect(l => l.UnLocode).Return(other).Repeat.AtLeastOnce(); IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>(); itinerary.Expect(i => i.InitialDepartureLocation).Return(start).Repeat.AtLeastOnce(); itinerary.Expect(i => i.Equals(null)).Return(false).Repeat.Any(); itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow + TimeSpan.FromDays(1)).Repeat.Any(); specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Once(); CargoState state = new NewCargo(id, specification); state = state.AssignToRoute(itinerary); // assert: Assert.Throws <ArgumentException>(delegate { state.Recieve(location, DateTime.UtcNow); }); location.VerifyAllExpectations(); itinerary.VerifyAllExpectations(); specification.VerifyAllExpectations(); }
protected InPortCargo(InPortCargo previousState, IItinerary newItinerary) : base(previousState, newItinerary) { _lastKnownLocation = previousState._lastKnownLocation; _date = previousState._date; _customCleared = previousState._customCleared; }
public void Ctor_02() { // arrange: GList mocks = new GList(); TrackingId id = new TrackingId("START"); DateTime loadTime = DateTime.Now; IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>(); itinerary.Expect(i => i.Equals(null)).IgnoreArguments().Return(false).Repeat.Any(); itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow + TimeSpan.FromDays(1)).Repeat.Any(); itinerary.Expect(i => i.FinalArrivalLocation).Return(new UnLocode("ENDLC")).Repeat.Any(); mocks.Add(itinerary); IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>(); specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any(); CargoState previousState = MockRepository.GenerateStrictMock <CargoState>(id, specification); mocks.Add(previousState); previousState = MockRepository.GenerateStrictMock <CargoState>(previousState, itinerary); mocks.Add(previousState); // assert: Assert.Throws <ArgumentNullException>(delegate { new OnboardCarrierCargo(previousState, null, loadTime); }); foreach (object mock in mocks) { mock.VerifyAllExpectations(); } }
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; }
public void AssignToRoute_01() { // arrange: TrackingId id = new TrackingId("CRG01"); IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>(); itinerary.Expect(i => i.Equals(null)).Return(false); itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.Now + TimeSpan.FromDays(60)).Repeat.AtLeastOnce(); IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>(); specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Once(); NewCargo state = new NewCargo(id, specification); // act: CargoState newState = state.AssignToRoute(itinerary); // assert: Assert.IsNotNull(newState); Assert.IsTrue(state.CalculationDate <= newState.CalculationDate); Assert.AreEqual(RoutingStatus.Routed, newState.RoutingStatus); Assert.AreSame(itinerary, newState.Itinerary); Assert.AreNotSame(state, newState); Assert.IsFalse(state.Equals(newState)); Assert.IsFalse(newState.Equals(state)); itinerary.VerifyAllExpectations(); specification.VerifyAllExpectations(); }
public void Recieve_01() { // arrange: TrackingId id = new TrackingId("CRG01"); UnLocode code = new UnLocode("START"); IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>(); ILocation location = MockRepository.GenerateMock <ILocation>(); location.Expect(l => l.UnLocode).Return(code).Repeat.AtLeastOnce(); IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>(); itinerary.Expect(i => i.InitialDepartureLocation).Return(code).Repeat.AtLeastOnce(); itinerary.Expect(i => i.Equals(null)).Return(false).Repeat.Any(); itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow + TimeSpan.FromDays(1)).Repeat.Any(); specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Once(); CargoState state = new NewCargo(id, specification); state = state.AssignToRoute(itinerary); // act: CargoState newState = state.Recieve(location, DateTime.UtcNow); // assert: Assert.IsNotNull(newState); Assert.IsInstanceOf <InPortCargo>(newState); Assert.AreSame(code, newState.LastKnownLocation); Assert.IsTrue(newState.EstimatedTimeOfArrival.HasValue); Assert.IsTrue(TransportStatus.InPort == newState.TransportStatus); location.VerifyAllExpectations(); itinerary.VerifyAllExpectations(); specification.VerifyAllExpectations(); }
public void Ctor_01() { // arrange: UnLocode final = new UnLocode("FINAL"); TrackingId id = new TrackingId("CLAIM"); IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>(); itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow).Repeat.AtLeastOnce(); itinerary.Expect(i => i.FinalArrivalLocation).Return(final).Repeat.AtLeastOnce(); IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>(); specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any(); CargoState previousState = MockRepository.GenerateStrictMock <CargoState>(id, specification); previousState = MockRepository.GenerateStrictMock <CargoState>(previousState, itinerary); previousState.Expect(s => s.IsUnloadedAtDestination).Return(true).Repeat.AtLeastOnce(); previousState.Expect(s => s.TransportStatus).Return(TransportStatus.InPort).Repeat.AtLeastOnce(); DateTime claimDate = DateTime.UtcNow; // act: ClaimedCargo state = new ClaimedCargo(previousState, claimDate); // assert: Assert.AreEqual(TransportStatus.Claimed, state.TransportStatus); Assert.AreEqual(RoutingStatus.Routed, state.RoutingStatus); Assert.AreSame(final, state.LastKnownLocation); Assert.AreSame(specification, state.RouteSpecification); Assert.IsNull(state.CurrentVoyage); Assert.IsTrue(state.IsUnloadedAtDestination); itinerary.VerifyAllExpectations(); specification.VerifyAllExpectations(); previousState.VerifyAllExpectations(); }
public void IsSatisfiedBy_06() { // arrange: UnLocode first = new UnLocode("CDFST"); UnLocode second = new UnLocode("CDSND"); UnLocode third = new UnLocode("CDTRD"); ILocation origin = MockRepository.GenerateStrictMock <ILocation>(); origin.Expect(l => l.UnLocode).Return(first).Repeat.AtLeastOnce(); ILocation destination = MockRepository.GenerateStrictMock <ILocation>(); destination.Expect(l => l.UnLocode).Return(second).Repeat.AtLeastOnce(); DateTime arrivalDeadline = DateTime.UtcNow + TimeSpan.FromDays(5); IItinerary candidate = MockRepository.GenerateStrictMock <IItinerary>(); candidate.Expect(i => i.InitialDepartureLocation).Return(first).Repeat.Once(); candidate.Expect(i => i.FinalArrivalLocation).Return(third).Repeat.Once(); candidate.Expect(i => i.FinalArrivalDate).Return(arrivalDeadline - TimeSpan.FromHours(1)).Repeat.Any(); IRouteSpecification specification = new RouteSpecification(origin, destination, arrivalDeadline); // act: bool satisfied = specification.IsSatisfiedBy(candidate); // assert: Assert.IsFalse(satisfied); origin.VerifyAllExpectations(); destination.VerifyAllExpectations(); candidate.VerifyAllExpectations(); }
public void AssignToRoute_03() { // arrange: TrackingId id = new TrackingId("CRG01"); IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>(); DateTime finalArrival1 = DateTime.Now + TimeSpan.FromDays(30); itinerary.Expect(i => i.Equals(null)).Return(false).Repeat.AtLeastOnce(); itinerary.Expect(i => i.FinalArrivalDate).Return(finalArrival1).Repeat.AtLeastOnce(); IItinerary itinerary2 = MockRepository.GenerateStrictMock <IItinerary>(); itinerary2.Expect(i => i.Equals(itinerary)).Return(true).Repeat.AtLeastOnce(); IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>(); specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Once(); CargoState initialState = new NewCargo(id, specification); CargoState state = initialState.AssignToRoute(itinerary); // act: CargoState newState = state.AssignToRoute(itinerary2); // assert: Assert.AreEqual(finalArrival1, newState.EstimatedTimeOfArrival); Assert.AreEqual(initialState.GetType(), state.GetType()); Assert.AreNotSame(initialState, state); Assert.IsNotNull(newState); Assert.AreSame(state, newState); }
public void Ctor_05() { // arrange: TrackingId id = new TrackingId("CLAIM"); IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>(); itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow).Repeat.AtLeastOnce(); IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>(); specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any(); CargoState previousState = MockRepository.GenerateStrictMock <CargoState>(id, specification); previousState = MockRepository.GenerateStrictMock <CargoState>(previousState, itinerary); previousState.Expect(s => s.IsUnloadedAtDestination).Return(false).Repeat.AtLeastOnce(); previousState.Expect(s => s.TransportStatus).Return(TransportStatus.InPort).Repeat.AtLeastOnce(); DateTime claimDate = DateTime.UtcNow; // act: Assert.Throws <ArgumentException>(delegate { new ClaimedCargo(previousState, claimDate); }); // assert: itinerary.VerifyAllExpectations(); specification.VerifyAllExpectations(); previousState.VerifyAllExpectations(); }
public void Equals_onDifferentVoyage_isFalse_02() { // arrange: DateTime arrivalDate = DateTime.Now + TimeSpan.FromDays(30); TrackingId identifier = new TrackingId("CARGO01"); IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>(); itinerary.Expect(i => i.Equals(null)).Return(false).Repeat.Any(); itinerary.Expect(i => i.FinalArrivalDate).Return(arrivalDate).Repeat.Any(); itinerary.Expect(i => i.Equals(itinerary)).Return(true).Repeat.Any(); IRouteSpecification route = MockRepository.GenerateStrictMock <IRouteSpecification>(); route.Expect(s => s.Equals(route)).Return(true).Repeat.Any(); route.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any(); FakeState state1 = new FakeState(identifier, route); state1 = new FakeState(state1, itinerary); state1._currentVoyage = null; FakeState state2 = new FakeState2(identifier, route); state2 = new FakeState(state2, itinerary); // act: // assert: Assert.IsFalse(state1.Equals(state2)); }
public void Equals_withDifferentItineraries_isFalse() { // arrange: DateTime arrivalDate = DateTime.Now + TimeSpan.FromDays(30); TrackingId identifier = new TrackingId("CARGO01"); IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>(); itinerary.Expect(i => i.Equals(null)).Return(false).Repeat.Any(); itinerary.Expect(i => i.FinalArrivalDate).Return(arrivalDate).Repeat.Any(); IRouteSpecification route = MockRepository.GenerateStrictMock <IRouteSpecification>(); route.Expect(s => s.Equals(route)).Return(true).Repeat.Any(); route.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any(); FakeState state1 = new FakeState(identifier, route); state1 = new FakeState(state1, itinerary); state1._lastKnownLocation = new Challenge00.DDDSample.Location.UnLocode("TESTA"); FakeState state2 = new FakeState2(identifier, route); state2._lastKnownLocation = new Challenge00.DDDSample.Location.UnLocode("TESTA"); // act: // assert: Assert.IsFalse(state1.Equals(state2)); }
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 void Recieve_04() { // arrange: TrackingId id = new TrackingId("CRG01"); IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>(); itinerary.Expect(i => i.Equals(null)).Return(false).Repeat.Any(); itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow + TimeSpan.FromDays(1)).Repeat.Any(); IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>(); specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.AtLeastOnce(); IRouteSpecification specification2 = MockRepository.GenerateStrictMock <IRouteSpecification>(); specification2.Expect(s => s.IsSatisfiedBy(itinerary)).Return(false).Repeat.AtLeastOnce(); specification.Expect(s => s.Equals(specification2)).Return(false).Repeat.Any(); specification2.Expect(s => s.Equals(specification)).Return(false).Repeat.Any(); ILocation location = MockRepository.GenerateMock <ILocation>(); CargoState initialState = new NewCargo(id, specification); CargoState routedState = initialState.AssignToRoute(itinerary); CargoState misroutedState = routedState.SpecifyNewRoute(specification2); // assert: Assert.AreEqual(initialState.GetType(), routedState.GetType()); Assert.AreNotSame(initialState, routedState); Assert.AreEqual(routedState.GetType(), misroutedState.GetType()); Assert.AreNotSame(routedState, misroutedState); Assert.IsTrue(RoutingStatus.Misrouted == misroutedState.RoutingStatus); Assert.Throws <InvalidOperationException>(delegate { misroutedState.Recieve(location, DateTime.UtcNow); }); location.VerifyAllExpectations(); specification.VerifyAllExpectations(); specification2.VerifyAllExpectations(); itinerary.VerifyAllExpectations(); }
public override CargoState AssignToRoute (IItinerary itinerary) { if(null == itinerary) throw new ArgumentNullException("itinerary"); if(itinerary.Equals(this.Itinerary)) return this; return new NewCargo(this, itinerary); }
public bool is_satisfied_by(IItinerary the_itinerary) { return the_itinerary != null && underlying_origin_location.has_the_same_identity_as( the_itinerary.initial_departure_load_location()) && underlying_destination_location.has_the_same_identity_as( the_itinerary.final_arrival_unload_location()) && underlying_arrival_deadline.is_posterior_to( the_itinerary.final_arrival_date()); }
public override CargoState AssignToRoute(IItinerary itinerary) { if (null == itinerary) { throw new ArgumentNullException("itinerary"); } if (itinerary.Equals(this.Itinerary)) { return(this); } return(new NewCargo(this, itinerary)); }
public virtual bool IsSatisfiedBy (IItinerary candidate) { if(null == candidate) return false; if(!_origin.Equals(candidate.InitialDepartureLocation)) return false; if(!_destination.Equals(candidate.FinalArrivalLocation)) return false; if(_arrivalDeadline < candidate.FinalArrivalDate) return false; return true; }
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(); }
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(); } }
protected CargoState(CargoState previousState, IItinerary newItinerary) : this(previousState) { if (null == newItinerary) { throw new ArgumentNullException("newItinerary"); } if (!previousState.RouteSpecification.IsSatisfiedBy(newItinerary)) { string message = string.Format("The itinerary provided do not satisfy the route of {0}.", Identifier); throw new ArgumentException(message, "itinerary"); } Itinerary = newItinerary; _routingStatus = RoutingStatus.Routed; _estimatedTimeOfArrival = this.Itinerary.FinalArrivalDate; }
public void StateTransitions_01() { // arrange: UnLocode final = new UnLocode("FINAL"); TrackingId id = new TrackingId("CLAIM"); ILocation finalLocation = MockRepository.GenerateStrictMock <ILocation>(); finalLocation.Expect(l => l.UnLocode).Return(final).Repeat.AtLeastOnce(); ILocation otherLocation = MockRepository.GenerateStrictMock <ILocation>(); otherLocation.Expect(l => l.UnLocode).Return(new UnLocode("OTHER")).Repeat.AtLeastOnce(); IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>(); itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow).Repeat.Any(); itinerary.Expect(i => i.FinalArrivalLocation).Return(final).Repeat.Any(); IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>(); specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any(); CargoState previousState = MockRepository.GenerateStrictMock <CargoState>(id, specification); previousState = MockRepository.GenerateStrictMock <CargoState>(previousState, itinerary); previousState.Expect(s => s.IsUnloadedAtDestination).Return(true).Repeat.Any(); previousState.Expect(s => s.TransportStatus).Return(TransportStatus.InPort).Repeat.Any(); IVoyage voyage = MockRepository.GenerateStrictMock <IVoyage>(); DateTime claimDate = DateTime.UtcNow; ClaimedCargo state = new ClaimedCargo(previousState, claimDate); // act: CargoState newState = state.Claim(finalLocation, claimDate); // assert: Assert.AreSame(state, newState); Assert.Throws <ArgumentNullException>(delegate { state.Claim(null, DateTime.UtcNow); }); Assert.Throws <InvalidOperationException>(delegate { state.Claim(finalLocation, DateTime.UtcNow + TimeSpan.FromSeconds(10)); }); Assert.Throws <InvalidOperationException>(delegate { state.Claim(otherLocation, claimDate); }); Assert.Throws <InvalidOperationException>(delegate { state.LoadOn(voyage, DateTime.UtcNow + TimeSpan.FromSeconds(10)); }); Assert.Throws <InvalidOperationException>(delegate { state.Unload(voyage, DateTime.UtcNow + TimeSpan.FromSeconds(10)); }); Assert.Throws <InvalidOperationException>(delegate { state.SpecifyNewRoute(MockRepository.GenerateStrictMock <IRouteSpecification>()); }); Assert.Throws <InvalidOperationException>(delegate { state.AssignToRoute(MockRepository.GenerateStrictMock <IItinerary>()); }); Assert.Throws <InvalidOperationException>(delegate { state.Recieve(MockRepository.GenerateStrictMock <ILocation>(), DateTime.UtcNow + TimeSpan.FromSeconds(10) + TimeSpan.FromSeconds(10)); }); Assert.Throws <InvalidOperationException>(delegate { state.ClearCustoms(MockRepository.GenerateStrictMock <ILocation>(), DateTime.UtcNow + TimeSpan.FromSeconds(10)); }); itinerary.VerifyAllExpectations(); specification.VerifyAllExpectations(); }
public void Unload_04() { // arrange: GList mocks = new GList(); UnLocode code = new UnLocode("START"); VoyageNumber voyageNumber = new VoyageNumber("ATEST"); DateTime arrival = DateTime.UtcNow; TrackingId id = new TrackingId("CARGO01"); IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>(); itinerary.Expect(i => i.Equals(null)).IgnoreArguments().Return(false).Repeat.Any(); itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow + TimeSpan.FromDays(1)).Repeat.Any(); itinerary.Expect(i => i.FinalArrivalLocation).Return(code).Repeat.Any(); mocks.Add(itinerary); IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>(); specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any(); mocks.Add(specification); IVoyage voyage = MockRepository.GenerateStrictMock <IVoyage>(); voyage.Expect(v => v.Number).Return(voyageNumber).Repeat.Any(); voyage.Expect(v => v.LastKnownLocation).Return(code).Repeat.AtLeastOnce(); voyage.Expect(v => v.IsMoving).Return(false).Repeat.AtLeastOnce(); mocks.Add(voyage); CargoState previousState = MockRepository.GenerateStrictMock <CargoState>(id, specification); mocks.Add(previousState); previousState = MockRepository.GenerateStrictMock <CargoState>(previousState, itinerary); mocks.Add(previousState); previousState.Expect(s => s.LastKnownLocation).Return(code).Repeat.Any(); OnboardCarrierCargo state = new OnboardCarrierCargo(previousState, voyage, arrival); // act: CargoState newState = state.Unload(voyage, arrival + TimeSpan.FromDays(2)); // assert: Assert.IsNotNull(newState); Assert.IsInstanceOf <InPortCargo>(newState); Assert.AreSame(code, newState.LastKnownLocation); foreach (object mock in mocks) { mock.VerifyAllExpectations(); } }
public void AssignToRoute_02() { // arrange: TrackingId id = new TrackingId("CRG01"); IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>(); itinerary.Expect(i => i.Equals(null)).Return(false); IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>(); specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(false).Repeat.Once(); NewCargo state = new NewCargo(id, specification); // act: Assert.Throws <ArgumentException>(delegate { state.AssignToRoute(itinerary); }); // assert: itinerary.VerifyAllExpectations(); specification.VerifyAllExpectations(); }
public void LoadOn_02() { // arrange: GList mocks = new GList(); UnLocode code = new UnLocode("START"); VoyageNumber voyageNumber = new VoyageNumber("ATEST"); DateTime arrival = DateTime.UtcNow; TrackingId id = new TrackingId("CARGO01"); IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>(); itinerary.Expect(i => i.Equals(null)).IgnoreArguments().Return(false).Repeat.Any(); itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow + TimeSpan.FromDays(1)).Repeat.Any(); itinerary.Expect(i => i.FinalArrivalLocation).Return(code).Repeat.Any(); mocks.Add(itinerary); IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>(); specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any(); mocks.Add(specification); IVoyage voyage = MockRepository.GenerateStrictMock <IVoyage>(); voyage.Expect(v => v.Number).Return(voyageNumber).Repeat.Any(); voyage.Expect(v => v.LastKnownLocation).Return(code).Repeat.AtLeastOnce(); mocks.Add(voyage); IVoyage voyage2 = MockRepository.GenerateStrictMock <IVoyage>(); voyage2.Expect(v => v.Number).Return(new VoyageNumber("VYGOTHER")).Repeat.Any(); mocks.Add(voyage2); CargoState previousState = MockRepository.GenerateStrictMock <CargoState>(id, specification); mocks.Add(previousState); previousState = MockRepository.GenerateStrictMock <CargoState>(previousState, itinerary); mocks.Add(previousState); previousState.Expect(s => s.LastKnownLocation).Return(code).Repeat.Any(); OnboardCarrierCargo state = new OnboardCarrierCargo(previousState, voyage, arrival); // assert: Assert.Throws <InvalidOperationException>(delegate { state.LoadOn(voyage2, arrival + TimeSpan.FromDays(2)); }); foreach (object mock in mocks) { mock.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 virtual bool IsSatisfiedBy(IItinerary candidate) { if (null == candidate) { return(false); } if (!_origin.Equals(candidate.InitialDepartureLocation)) { return(false); } if (!_destination.Equals(candidate.FinalArrivalLocation)) { return(false); } if (_arrivalDeadline < candidate.FinalArrivalDate) { return(false); } return(true); }
public void ClearCustoms_01() { // arrange: GList mocks = new GList(); TrackingId id = new TrackingId("START"); DateTime loadTime = DateTime.Now; VoyageNumber voyageNumber = new VoyageNumber("VYG001"); UnLocode locCode = new UnLocode("CURLC"); ILocation location = MockRepository.GenerateStrictMock <ILocation>(); location.Expect(l => l.UnLocode).Return(locCode).Repeat.Any(); mocks.Add(location); IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>(); itinerary.Expect(i => i.Equals(null)).IgnoreArguments().Return(false).Repeat.Any(); itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow + TimeSpan.FromDays(1)).Repeat.Any(); itinerary.Expect(i => i.FinalArrivalLocation).Return(new UnLocode("ENDLC")).Repeat.Any(); mocks.Add(itinerary); IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>(); specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any(); mocks.Add(specification); CargoState previousState = MockRepository.GenerateStrictMock <CargoState>(id, specification); mocks.Add(previousState); previousState = MockRepository.GenerateStrictMock <CargoState>(previousState, itinerary); mocks.Add(previousState); IVoyage voyage = MockRepository.GenerateStrictMock <IVoyage>(); voyage.Expect(v => v.Number).Return(voyageNumber).Repeat.AtLeastOnce(); voyage.Expect(v => v.LastKnownLocation).Return(locCode).Repeat.AtLeastOnce(); mocks.Add(voyage); CargoState state = new OnboardCarrierCargo(previousState, voyage, loadTime); // assert: Assert.Throws <InvalidOperationException>(delegate { state.ClearCustoms(location, DateTime.Now + TimeSpan.FromDays(1)); }); foreach (object mock in mocks) { mock.VerifyAllExpectations(); } }
public void Ctor_01() { // arrange: GList mocks = new GList(); TrackingId id = new TrackingId("START"); DateTime loadTime = DateTime.Now; VoyageNumber voyageNumber = new VoyageNumber("VYG001"); UnLocode location = new UnLocode("CURLC"); IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>(); itinerary.Expect(i => i.Equals(null)).IgnoreArguments().Return(false).Repeat.Any(); itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow + TimeSpan.FromDays(1)).Repeat.Any(); itinerary.Expect(i => i.FinalArrivalLocation).Return(new UnLocode("ENDLC")).Repeat.Any(); mocks.Add(itinerary); IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>(); specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any(); CargoState previousState = MockRepository.GenerateStrictMock <CargoState>(id, specification); mocks.Add(previousState); previousState = MockRepository.GenerateStrictMock <CargoState>(previousState, itinerary); mocks.Add(previousState); IVoyage voyage = MockRepository.GenerateStrictMock <IVoyage>(); voyage.Expect(v => v.Number).Return(voyageNumber).Repeat.AtLeastOnce(); voyage.Expect(v => v.LastKnownLocation).Return(location).Repeat.AtLeastOnce(); mocks.Add(voyage); // act: CargoState state = new OnboardCarrierCargo(previousState, voyage, loadTime); // assert: Assert.IsNotNull(state); Assert.AreSame(voyageNumber, state.CurrentVoyage); Assert.AreEqual(TransportStatus.OnboardCarrier, state.TransportStatus); Assert.AreSame(location, state.LastKnownLocation); foreach (object mock in mocks) { mock.VerifyAllExpectations(); } }
/// <summary> /// Send request message back to caller as response /// </summary> /// <param name="pipelineContext">Pipeline context</param> /// <param name="inputMessage">Input message</param> /// <returns>Original input message</returns> protected override IBaseMessage Execute(IPipelineContext pipelineContext, IBaseMessage inputMessage) { var callToken = TraceProvider.Logger.TraceIn(this.Name); try { // delegate work to the BizTalk Xml Dissassembler TraceProvider.Logger.TraceInfo("Checking if itinerary should be terminated"); var IsTerminateItinerary = inputMessage.Context.Read("IsTerminateItinerary", "https://DE.DAXFSA.Framework.Properties.ESBGlobalProperties"); if (IsTerminateItinerary != null && (bool)IsTerminateItinerary) { IItinerary itinerary = ItineraryOMFactory.Create(inputMessage); if (itinerary != null) { MethodInfo CompleteItinerary_MI = itinerary.GetType().GetMethod("CompleteItinerary", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); if (CompleteItinerary_MI != null) { CompleteItinerary_MI.Invoke(itinerary, new object[] { null }); } } return(null); } return(inputMessage); } catch (Exception ex) { // put component name as a source information in this exception, // so the event log in message could reflect this ex.Source = this.Name; TraceProvider.Logger.TraceError(ex); throw ex; } finally { TraceProvider.Logger.TraceOut(callToken); } }
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); }
public void AssignToRoute(IItinerary itinerary) { // Thread safe, lock free sincronization CargoState stateBeforeTransition; CargoState previousState = CurrentState; do { stateBeforeTransition = previousState; CargoState newValue = stateBeforeTransition.AssignToRoute(itinerary); previousState = Interlocked.CompareExchange <CargoState>(ref this.CurrentState, newValue, stateBeforeTransition); }while (previousState != stateBeforeTransition); if (!previousState.Equals(this.CurrentState)) { ChangeEventArgs <IItinerary> args = new ChangeEventArgs <IItinerary>(previousState.Itinerary, CurrentState.Itinerary); EventHandler <ChangeEventArgs <IItinerary> > handler = ItineraryChanged; if (null != handler) { handler(this, args); } } }
public void Ctor_02() { // arrange: System.Collections.Generic.List <object> mocks = new System.Collections.Generic.List <object>(); TrackingId id = new TrackingId("CLAIM"); IItinerary itinerary = MockRepository.GenerateStrictMock <IItinerary>(); itinerary.Expect(i => i.FinalArrivalDate).Return(DateTime.UtcNow).Repeat.AtLeastOnce(); mocks.Add(itinerary); IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>(); specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.Any(); mocks.Add(specification); IRouteSpecification specification2 = MockRepository.GenerateStrictMock <IRouteSpecification>(); specification2.Expect(s => s.IsSatisfiedBy(itinerary)).Return(false).Repeat.Any(); mocks.Add(specification2); CargoState previousState = MockRepository.GenerateStrictMock <CargoState>(id, specification); mocks.Add(previousState); previousState = MockRepository.GenerateStrictMock <CargoState>(previousState, itinerary); mocks.Add(previousState); previousState = MockRepository.GenerateStrictMock <CargoState>(previousState, specification2); mocks.Add(previousState); DateTime claimDate = DateTime.UtcNow; // act: Assert.Throws <ArgumentException>(delegate { new ClaimedCargo(previousState, claimDate); }); // assert: foreach (object mock in mocks) { mock.VerifyAllExpectations(); } }
protected NewCargo(CargoState previousState, IItinerary newItinerary) : base(previousState, newItinerary) { }
public bool has_the_same_value_as(IItinerary the_other_itinerary) { return the_other_itinerary != null && underlying_leg_collection.Equals(the_other_itinerary.associated_legs()); }
public override CargoState AssignToRoute (IItinerary itinerary) { string message = string.Format("The cargo {0} has been loaded on the {1} voyage.", Identifier, _voyage); throw new InvalidOperationException(message); }
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 FakeState2(CargoState previousState, IItinerary itinerary) : base(previousState, itinerary) { }
public override CargoState AssignToRoute (IItinerary itinerary) { throw new System.NotImplementedException(); }