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(); }
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 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 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_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 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 Recieve_05() { // arrange: TrackingId id = new TrackingId("CRG01"); IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>(); CargoState state = new NewCargo(id, specification); // assert: Assert.Throws <ArgumentNullException>(delegate { state.Recieve(null, DateTime.UtcNow); }); specification.VerifyAllExpectations(); }
public void AssignToRoute_04() { // arrange: TrackingId id = new TrackingId("CRG01"); IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>(); NewCargo state = new NewCargo(id, specification); // assert: Assert.Throws <ArgumentNullException>(delegate { state.AssignToRoute(null); }); specification.VerifyAllExpectations(); }
public void Ctor_03() { // arrange: TrackingId id = new TrackingId("CLAIM"); IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>(); CargoState previousState = MockRepository.GenerateStrictMock <CargoState>(id, specification); DateTime claimDate = DateTime.UtcNow; // act: Assert.Throws <ArgumentException>(delegate { new ClaimedCargo(previousState, claimDate); }); // assert: specification.VerifyAllExpectations(); }
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 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 SpecifyNewRoute_02() { // arrange: TrackingId id = new TrackingId("CRG01"); IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>(); IRouteSpecification specification2 = MockRepository.GenerateStrictMock <IRouteSpecification>(); specification.Expect(s => s.Equals(specification2)).Return(true).Repeat.Any(); specification2.Expect(s => s.Equals(specification)).Return(true).Repeat.Any(); NewCargo state = new NewCargo(id, specification); // act: CargoState newState = state.SpecifyNewRoute(specification2); // assert: Assert.IsNotNull(newState); Assert.AreSame(state, newState); specification.VerifyAllExpectations(); specification2.VerifyAllExpectations(); }
public void Ctor_01() { // arrange: TrackingId id = new TrackingId("CRG01"); IRouteSpecification specification = MockRepository.GenerateStrictMock <IRouteSpecification>(); // act: NewCargo state = new NewCargo(id, specification); // assert: Assert.IsTrue(state.Equals(state)); Assert.IsFalse(state.Equals(null)); Assert.AreSame(id, state.Identifier); Assert.AreSame(specification, state.RouteSpecification); Assert.IsNull(state.LastKnownLocation); Assert.IsNull(state.Itinerary); Assert.IsNull(state.CurrentVoyage); Assert.IsNull(state.EstimatedTimeOfArrival); Assert.AreEqual(RoutingStatus.NotRouted, state.RoutingStatus); Assert.AreEqual(TransportStatus.NotReceived, state.TransportStatus); Assert.IsFalse(state.IsUnloadedAtDestination); specification.VerifyAllExpectations(); }