public void Recieve_atInitialLocation_setTransportStatusInPort() { // arrange: GList mocks = new GList(); TrackingId identifier = new TrackingId("CARGO01"); DateTime arrivalDate = DateTime.Now + TimeSpan.FromDays(30); DateTime recieveDate = DateTime.Now + TimeSpan.FromDays(1); UnLocode recUnLocode = new UnLocode("RECLC"); ILocation recLocation = MockRepository.GenerateStrictMock<ILocation>(); recLocation.Expect(l => l.UnLocode).Return(recUnLocode).Repeat.AtLeastOnce(); mocks.Add(recLocation); 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.InitialDepartureLocation).Return(recUnLocode).Repeat.Any(); mocks.Add(itinerary); IRouteSpecification route = MockRepository.GenerateStrictMock<IRouteSpecification>(); route.Expect(r => r.IsSatisfiedBy(itinerary)).Return(true).Repeat.AtLeastOnce(); mocks.Add(route); // act: TCargo underTest = new TCargo(identifier, route); underTest.AssignToRoute(itinerary); underTest.Recieve(recLocation, recieveDate); // assert: Assert.AreEqual(RoutingStatus.Routed, underTest.Delivery.RoutingStatus); Assert.AreEqual(TransportStatus.InPort, underTest.Delivery.TransportStatus); foreach(object mock in mocks) mock.VerifyAllExpectations(); }
public void Recieve_atInitialLocation_fireRecieved() { // arrange: GList mocks = new GList(); TrackingId identifier = new TrackingId("CARGO01"); DateTime arrivalDate = DateTime.Now + TimeSpan.FromDays(30); DateTime recieveDate = DateTime.Now + TimeSpan.FromDays(1); UnLocode recUnLocode = new UnLocode("RECLC"); ILocation recLocation = MockRepository.GenerateStrictMock<ILocation>(); recLocation.Expect(l => l.UnLocode).Return(recUnLocode).Repeat.AtLeastOnce(); mocks.Add(recLocation); 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.InitialDepartureLocation).Return(recUnLocode).Repeat.Any(); mocks.Add(itinerary); IRouteSpecification route = MockRepository.GenerateStrictMock<IRouteSpecification>(); route.Expect(r => r.IsSatisfiedBy(itinerary)).Return(true).Repeat.AtLeastOnce(); mocks.Add(route); HandlingEventArgs eventArguments = null; ICargo eventSender = null; // act: TCargo underTest = new TCargo(identifier, route); underTest.AssignToRoute(itinerary); underTest.Recieved += delegate(object sender, HandlingEventArgs e) { eventArguments = e; eventSender = sender as ICargo; }; underTest.Recieve(recLocation, recieveDate); // assert: Assert.IsNotNull(eventArguments); Assert.AreSame(underTest.Delivery.LastKnownLocation, eventArguments.Delivery.LastKnownLocation); Assert.AreSame(eventSender, underTest); foreach(object mock in mocks) mock.VerifyAllExpectations(); }
public void AssignToRoute_withAnotherItinerary_checkTheRouteSpecification() { // arrange: GList mocks = new GList(); TrackingId identifier = new TrackingId("CARGO01"); DateTime arrivalDate = DateTime.Now + TimeSpan.FromDays(30); IItinerary itinerary = MockRepository.GenerateStrictMock<IItinerary>(); itinerary.Expect(i => i.Equals((IItinerary)null)).Return(false).Repeat.Any(); itinerary.Expect(i => i.FinalArrivalDate).Return(arrivalDate).Repeat.Any(); mocks.Add(itinerary); IItinerary itinerary2 = MockRepository.GenerateStrictMock<IItinerary>(); itinerary2.Expect(i => i.Equals((IItinerary)itinerary)).Return(false).Repeat.Any(); itinerary2.Expect(i => i.FinalArrivalDate).Return(arrivalDate).Repeat.Any(); mocks.Add(itinerary2); itinerary.Expect(i => i.Equals((IItinerary)itinerary2)).Return(false).Repeat.Any(); IRouteSpecification route = MockRepository.GenerateStrictMock<IRouteSpecification>(); route.Expect(r => r.IsSatisfiedBy(itinerary)).Return(true).Repeat.AtLeastOnce(); route.Expect(r => r.IsSatisfiedBy(itinerary2)).Return(true).Repeat.AtLeastOnce(); route.Expect(s => s.Equals(route)).Return(true).Repeat.Any(); mocks.Add(route); // act: TCargo underTest = new TCargo(identifier, route); underTest.AssignToRoute(itinerary); Assert.AreSame(itinerary, underTest.Itinerary); underTest.AssignToRoute(itinerary2); // assert: foreach(object mock in mocks) mock.VerifyAllExpectations(); }
public void SpecifyNewRoute_withASpecificationNotMatchingTheItinerary_setTheRoutingStatusMisrouted() { // arrange: GList mocks = new GList(); TrackingId identifier = new TrackingId("CARGO01"); DateTime arrivalDate = DateTime.Now + TimeSpan.FromDays(30); IItinerary itinerary = MockRepository.GenerateStrictMock<IItinerary>(); itinerary.Expect(i => i.Equals(null)).Return(false).Repeat.Any(); itinerary.Expect(i => i.FinalArrivalDate).Return(arrivalDate).Repeat.Any(); mocks.Add(itinerary); IRouteSpecification route = MockRepository.GenerateStrictMock<IRouteSpecification>(); IRouteSpecification route2 = MockRepository.GenerateStrictMock<IRouteSpecification>(); route.Expect(r => r.Equals(route2)).Return(false).Repeat.AtLeastOnce(); route.Expect(r => r.IsSatisfiedBy(itinerary)).Return(true).Repeat.AtLeastOnce(); route2.Expect(r => r.IsSatisfiedBy(itinerary)).Return(false).Repeat.AtLeastOnce(); mocks.Add(route); mocks.Add(route2); // act: TCargo underTest = new TCargo(identifier, route); underTest.AssignToRoute(itinerary); underTest.SpecifyNewRoute(route2); // assert: Assert.AreEqual(RoutingStatus.Misrouted, underTest.Delivery.RoutingStatus); Assert.AreSame(route2, underTest.RouteSpecification); foreach(object mock in mocks) mock.VerifyAllExpectations(); }
public void Claim_atFinalArrivalLocation_dontCallUnsubscribedHandlersOf_Claimed() { // arrange: GList mocks = new GList(); TrackingId identifier = new TrackingId("CARGO01"); VoyageNumber voyageNumber = new VoyageNumber("VYG001"); DateTime arrivalDate = DateTime.Now + TimeSpan.FromDays(30); DateTime recieveDate = DateTime.Now + TimeSpan.FromDays(1); UnLocode recUnLocode = new UnLocode("RECLC"); UnLocode endUnLocode = new UnLocode("FINAL"); IVoyage voyage = MockRepository.GenerateStrictMock<IVoyage>(); voyage.Expect(v => v.IsMoving).Return(false).Repeat.AtLeastOnce(); voyage.Expect(v => v.Number).Return(voyageNumber).Repeat.AtLeastOnce(); voyage.Expect(v => v.LastKnownLocation).Return(recUnLocode).Repeat.Twice(); voyage.Expect(v => v.LastKnownLocation).Return(endUnLocode).Repeat.Once(); mocks.Add(voyage); ILocation recLocation = MockRepository.GenerateStrictMock<ILocation>(); recLocation.Expect(l => l.UnLocode).Return(recUnLocode).Repeat.AtLeastOnce(); mocks.Add(recLocation); ILocation clmLocation = MockRepository.GenerateStrictMock<ILocation>(); clmLocation.Expect(l => l.UnLocode).Return(endUnLocode).Repeat.AtLeastOnce(); mocks.Add(clmLocation); 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.FinalArrivalLocation).Return(endUnLocode).Repeat.Any(); itinerary.Expect(i => i.InitialDepartureLocation).Return(recUnLocode).Repeat.Any(); mocks.Add(itinerary); IRouteSpecification route = MockRepository.GenerateStrictMock<IRouteSpecification>(); route.Expect(r => r.IsSatisfiedBy(itinerary)).Return(true).Repeat.AtLeastOnce(); mocks.Add(route); HandlingEventArgs eventArguments = null; ICargo eventSender = null; // act: EventHandler<HandlingEventArgs> handler = delegate(object sender, HandlingEventArgs e) { eventArguments = e; eventSender = sender as ICargo; }; TCargo underTest = new TCargo(identifier, route); underTest.AssignToRoute(itinerary); underTest.Recieve(recLocation, recieveDate); underTest.LoadOn(voyage, recieveDate + TimeSpan.FromDays(1)); underTest.Unload(voyage, recieveDate + TimeSpan.FromDays(10)); underTest.Claimed += handler; underTest.Claimed -= handler; underTest.Claim(clmLocation, recieveDate + TimeSpan.FromDays(11)); // assert: Assert.IsNull(eventArguments); Assert.IsNull(eventSender); foreach(object mock in mocks) mock.VerifyAllExpectations(); }
public void AssignToRoute_withAnotherItinerary_fireItineraryChanged() { // arrange: GList mocks = new GList(); TrackingId identifier = new TrackingId("CARGO01"); DateTime arrivalDate = DateTime.Now + TimeSpan.FromDays(30); IItinerary itinerary = MockRepository.GenerateStrictMock<IItinerary>(); itinerary.Expect(i => i.Equals(null)).Return(false).Repeat.Any(); itinerary.Expect(i => i.FinalArrivalDate).Return(arrivalDate).Repeat.Any(); mocks.Add(itinerary); IItinerary itinerary2 = MockRepository.GenerateStrictMock<IItinerary>(); itinerary2.Expect(i => i.Equals((IItinerary)itinerary)).Return(false).Repeat.Any(); itinerary2.Expect(i => i.FinalArrivalDate).Return(arrivalDate).Repeat.Any(); mocks.Add(itinerary2); itinerary.Expect(i => i.Equals((IItinerary)itinerary2)).Return(false).Repeat.Any(); IRouteSpecification route = MockRepository.GenerateStrictMock<IRouteSpecification>(); route.Expect(r => r.IsSatisfiedBy(itinerary)).Return(true).Repeat.AtLeastOnce(); route.Expect(r => r.IsSatisfiedBy(itinerary2)).Return(true).Repeat.AtLeastOnce(); route.Expect(s => s.Equals(route)).Return(true).Repeat.Any(); mocks.Add(route); ChangeEventArgs<IItinerary> eventArguments = null; ICargo eventSender = null; // act: TCargo underTest = new TCargo(identifier, route); underTest.AssignToRoute(itinerary); Assert.AreSame(itinerary, underTest.Itinerary); underTest.ItineraryChanged += delegate(object sender, ChangeEventArgs<IItinerary> e) { eventArguments = e; eventSender = sender as ICargo; }; underTest.AssignToRoute(itinerary2); // assert: Assert.AreSame(itinerary2, eventArguments.NewValue); Assert.AreSame(itinerary, eventArguments.OldValue); Assert.AreSame(eventSender, underTest); foreach(object mock in mocks) mock.VerifyAllExpectations(); }
public void Claim_atFinalArrivalLocation_setTheTransportStatusToClaimed() { // arrange: GList mocks = new GList(); TrackingId identifier = new TrackingId("CARGO01"); VoyageNumber voyageNumber = new VoyageNumber("VYG001"); DateTime arrivalDate = DateTime.Now + TimeSpan.FromDays(30); DateTime recieveDate = DateTime.Now + TimeSpan.FromDays(1); UnLocode recUnLocode = new UnLocode("RECLC"); UnLocode endUnLocode = new UnLocode("FINAL"); IVoyage voyage = MockRepository.GenerateStrictMock<IVoyage>(); voyage.Expect(v => v.IsMoving).Return(false).Repeat.AtLeastOnce(); voyage.Expect(v => v.Number).Return(voyageNumber).Repeat.AtLeastOnce(); voyage.Expect(v => v.LastKnownLocation).Return(recUnLocode).Repeat.Twice(); voyage.Expect(v => v.LastKnownLocation).Return(endUnLocode).Repeat.Once(); mocks.Add(voyage); ILocation recLocation = MockRepository.GenerateStrictMock<ILocation>(); recLocation.Expect(l => l.UnLocode).Return(recUnLocode).Repeat.AtLeastOnce(); mocks.Add(recLocation); ILocation clmLocation = MockRepository.GenerateStrictMock<ILocation>(); clmLocation.Expect(l => l.UnLocode).Return(endUnLocode).Repeat.AtLeastOnce(); mocks.Add(clmLocation); 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.FinalArrivalLocation).Return(endUnLocode).Repeat.Any(); itinerary.Expect(i => i.InitialDepartureLocation).Return(recUnLocode).Repeat.Any(); mocks.Add(itinerary); IRouteSpecification route = MockRepository.GenerateStrictMock<IRouteSpecification>(); route.Expect(r => r.IsSatisfiedBy(itinerary)).Return(true).Repeat.AtLeastOnce(); mocks.Add(route); // act: TCargo underTest = new TCargo(identifier, route); underTest.AssignToRoute(itinerary); underTest.Recieve(recLocation, recieveDate); underTest.LoadOn(voyage, recieveDate + TimeSpan.FromDays(1)); underTest.Unload(voyage, recieveDate + TimeSpan.FromDays(10)); underTest.Claim(clmLocation, recieveDate + TimeSpan.FromDays(11)); // assert: Assert.AreEqual(TransportStatus.Claimed, underTest.Delivery.TransportStatus); foreach(object mock in mocks) mock.VerifyAllExpectations(); }
public void AssignToRoute_withNullItinerary_throwsArgumentNullException() { // arrange: GList mocks = new GList(); TrackingId identifier = new TrackingId("CARGO01"); IRouteSpecification route = MockRepository.GenerateStrictMock<IRouteSpecification>(); mocks.Add(route); // act: TCargo underTest = new TCargo(identifier, route); Assert.Throws<ArgumentNullException>( delegate { underTest.AssignToRoute(null); }); // assert: foreach(object mock in mocks) mock.VerifyAllExpectations(); }
public void Unload_fromVoyage_resetCurrentVoyage() { // arrange: GList mocks = new GList(); VoyageNumber voyageNumber = new VoyageNumber("VYG001"); TrackingId identifier = new TrackingId("CARGO01"); DateTime arrivalDate = DateTime.Now + TimeSpan.FromDays(30); DateTime recDate = DateTime.Now + TimeSpan.FromHours(1); DateTime loadDate = DateTime.Now + TimeSpan.FromDays(1); UnLocode initialLocation = new UnLocode("INITL"); UnLocode finalLocation = new UnLocode("FINAL"); ILocation recLocation = MockRepository.GenerateStrictMock<ILocation>(); recLocation.Expect(l => l.UnLocode).Return(initialLocation).Repeat.AtLeastOnce(); mocks.Add(recLocation); IVoyage voyage = MockRepository.GenerateStrictMock<IVoyage>(); voyage.Expect(v => v.IsMoving).Return(false).Repeat.AtLeastOnce(); voyage.Expect(v => v.Number).Return(voyageNumber).Repeat.AtLeastOnce(); voyage.Expect(v => v.LastKnownLocation).Return(initialLocation).Repeat.Twice(); voyage.Expect(v => v.LastKnownLocation).Return(finalLocation).Repeat.Once(); mocks.Add(voyage); 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.FinalArrivalLocation).Return(finalLocation).Repeat.Any(); itinerary.Expect(i => i.InitialDepartureLocation).Return(initialLocation).Repeat.Any(); mocks.Add(itinerary); IRouteSpecification route = MockRepository.GenerateStrictMock<IRouteSpecification>(); route.Expect(r => r.IsSatisfiedBy(itinerary)).Return(true).Repeat.AtLeastOnce(); mocks.Add(route); // act: TCargo underTest = new TCargo(identifier, route); underTest.AssignToRoute(itinerary); underTest.Recieve(recLocation, recDate); underTest.LoadOn(voyage, loadDate); underTest.Unload(voyage, loadDate + TimeSpan.FromDays(10)); // assert: Assert.IsNull(underTest.Delivery.CurrentVoyage); foreach(object mock in mocks) mock.VerifyAllExpectations(); }
public void LoadOn_Voyage_fireLoaded() { // arrange: GList mocks = new GList(); VoyageNumber voyageNumber = new VoyageNumber("VYG001"); TrackingId identifier = new TrackingId("CARGO01"); DateTime arrivalDate = DateTime.Now + TimeSpan.FromDays(30); DateTime recDate = DateTime.Now + TimeSpan.FromHours(1); DateTime loadDate = DateTime.Now + TimeSpan.FromDays(1); UnLocode initialLocation = new UnLocode("INITL"); ILocation recLocation = MockRepository.GenerateStrictMock<ILocation>(); recLocation.Expect(l => l.UnLocode).Return(initialLocation).Repeat.AtLeastOnce(); mocks.Add(recLocation); IVoyage voyage = MockRepository.GenerateStrictMock<IVoyage>(); voyage.Expect(v => v.IsMoving).Return(false).Repeat.AtLeastOnce(); voyage.Expect(v => v.Number).Return(voyageNumber).Repeat.AtLeastOnce(); voyage.Expect(v => v.LastKnownLocation).Return(initialLocation).Repeat.AtLeastOnce(); mocks.Add(voyage); 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.FinalArrivalLocation).Return(new UnLocode("FINAL")).Repeat.Any(); itinerary.Expect(i => i.InitialDepartureLocation).Return(initialLocation).Repeat.Any(); mocks.Add(itinerary); IRouteSpecification route = MockRepository.GenerateStrictMock<IRouteSpecification>(); route.Expect(r => r.IsSatisfiedBy(itinerary)).Return(true).Repeat.AtLeastOnce(); mocks.Add(route); HandlingEventArgs eventArguments = null; ICargo eventSender = null; // act: EventHandler<HandlingEventArgs> handler = delegate(object sender, HandlingEventArgs e) { eventArguments = e; eventSender = sender as ICargo; }; TCargo underTest = new TCargo(identifier, route); underTest.AssignToRoute(itinerary); underTest.Recieve(recLocation, recDate); underTest.Loaded += handler; underTest.LoadOn(voyage, loadDate); // assert: Assert.IsNotNull(eventArguments); Assert.AreSame(underTest.Delivery, eventArguments.Delivery); Assert.AreSame(eventSender, underTest); foreach(object mock in mocks) mock.VerifyAllExpectations(); }
public void ClearCustoms_atCurrentLocation_dontCallUnsubscribedHandlersOf_CustomsCleared() { // arrange: GList mocks = new GList(); TrackingId identifier = new TrackingId("CARGO01"); DateTime arrivalDate = DateTime.Now + TimeSpan.FromDays(30); DateTime recieveDate = DateTime.Now + TimeSpan.FromDays(1); UnLocode recUnLocode = new UnLocode("RECLC"); ILocation recLocation = MockRepository.GenerateStrictMock<ILocation>(); recLocation.Expect(l => l.UnLocode).Return(recUnLocode).Repeat.AtLeastOnce(); mocks.Add(recLocation); 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.InitialDepartureLocation).Return(recUnLocode).Repeat.Any(); mocks.Add(itinerary); IRouteSpecification route = MockRepository.GenerateStrictMock<IRouteSpecification>(); route.Expect(r => r.IsSatisfiedBy(itinerary)).Return(true).Repeat.AtLeastOnce(); mocks.Add(route); HandlingEventArgs eventArguments = null; ICargo eventSender = null; // act: EventHandler<HandlingEventArgs> handler = delegate(object sender, HandlingEventArgs e) { eventArguments = e; eventSender = sender as ICargo; }; TCargo underTest = new TCargo(identifier, route); underTest.AssignToRoute(itinerary); underTest.Recieve(recLocation, recieveDate); underTest.CustomsCleared += handler; underTest.CustomsCleared -= handler; underTest.ClearCustoms(recLocation, recieveDate + TimeSpan.FromHours(6)); // assert: Assert.AreEqual(RoutingStatus.Routed, underTest.Delivery.RoutingStatus); Assert.AreEqual(TransportStatus.InPort, underTest.Delivery.TransportStatus); Assert.AreSame(recUnLocode, underTest.Delivery.LastKnownLocation); Assert.IsNull(eventArguments); Assert.IsNull(eventSender); foreach(object mock in mocks) mock.VerifyAllExpectations(); }