public void Claim_05() { // arrange: List<object> mocks = new List<object>(); UnLocode code = new UnLocode("FINAL"); TrackingId id = new TrackingId("CRG01"); DateTime arrival = DateTime.UtcNow; ILocation location2 = MockRepository.GenerateStrictMock<ILocation>(); location2.Expect(l => l.UnLocode).Return(code).Repeat.AtLeastOnce(); mocks.Add(location2); 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.AtLeastOnce(); mocks.Add(itinerary); IRouteSpecification specification = MockRepository.GenerateStrictMock<IRouteSpecification>(); specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.AtLeastOnce(); mocks.Add(specification); CargoState previousState = MockRepository.GenerateStrictMock<CargoState>(id, specification); previousState.Expect(s => s.LastKnownLocation).Return(code).Repeat.Any(); mocks.Add(previousState); previousState = MockRepository.GenerateStrictMock<CargoState>(previousState, itinerary); mocks.Add(previousState); InPortCargo state = new InPortCargo(previousState, code, arrival); // act: Assert.Throws<ArgumentException>(delegate { state.Claim(location2, DateTime.UtcNow - TimeSpan.FromDays(1)); }); // assert: foreach (object mock in mocks) mock.VerifyAllExpectations(); }
public void Claim_01() { // arrange: UnLocode code = new UnLocode("FINAL"); TrackingId id = new TrackingId("CRG01"); DateTime arrival = DateTime.UtcNow; IRouteSpecification specification = MockRepository.GenerateStrictMock<IRouteSpecification>(); ILocation location = MockRepository.GenerateStrictMock<ILocation>(); location.Expect(l => l.UnLocode).Return(code).Repeat.AtLeastOnce(); 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.AtLeastOnce(); specification.Expect(s => s.IsSatisfiedBy(itinerary)).Return(true).Repeat.AtLeastOnce(); CargoState previousState = MockRepository.GenerateStrictMock<CargoState>(id, specification); previousState.Expect(s => s.LastKnownLocation).Return(code).Repeat.Any(); previousState = MockRepository.GenerateStrictMock<CargoState>(previousState, itinerary); InPortCargo state = new InPortCargo(previousState, code, arrival); // act: CargoState newState = state.Claim(location, DateTime.UtcNow + TimeSpan.FromDays(2)); // assert: Assert.IsNotNull(newState); Assert.IsInstanceOf<ClaimedCargo>(newState); location.VerifyAllExpectations(); itinerary.VerifyAllExpectations(); specification.VerifyAllExpectations(); }