public void SpecifyNewRoute_withASpecification_dontCallUnsubscribedHandlersOf_NewRouteSpecified() { // arrange: GList mocks = new GList(); TrackingId identifier = new TrackingId("CARGO01"); IRouteSpecification route = MockRepository.GenerateStrictMock<IRouteSpecification>(); mocks.Add(route); IRouteSpecification route2 = MockRepository.GenerateStrictMock<IRouteSpecification>(); mocks.Add(route2); CargoState mockState1 = MockRepository.GeneratePartialMock<CargoState>(identifier, route); CargoState mockState2 = MockRepository.GeneratePartialMock<CargoState>(mockState1, route2); mockState1.Expect(s => s.SpecifyNewRoute(route2)).Return(mockState2).Repeat.Once(); mockState1.Expect(s => s.Equals(mockState2)).Return(false).Repeat.Any(); mocks.Add(mockState1); mocks.Add(mockState2); ChangeEventArgs<IRouteSpecification> eventArguments = null; ICargo eventSender = null; // act: EventHandler<ChangeEventArgs<IRouteSpecification>> handler = delegate(object sender, ChangeEventArgs<IRouteSpecification> e) { eventArguments = e; eventSender = sender as ICargo; }; TCargo underTest = new FakeCargo(mockState1); underTest.NewRouteSpecified += handler; underTest.NewRouteSpecified -= handler; underTest.SpecifyNewRoute(route2); // assert: Assert.AreSame(route2, underTest.RouteSpecification); Assert.IsNull(eventArguments); Assert.IsNull(eventSender); foreach(object mock in mocks) mock.VerifyAllExpectations(); }
public void AssignToRoute_withAnItinerary_dontCallUnsubscribedHandlersOf_ItineraryChanged() { // 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>(); route.Expect(r => r.IsSatisfiedBy(itinerary)).Return(true).Repeat.AtLeastOnce(); mocks.Add(route); CargoState mockState1 = MockRepository.GeneratePartialMock<CargoState>(identifier, route); CargoState mockState2 = MockRepository.GeneratePartialMock<CargoState>(mockState1, itinerary); mockState1.Expect(s => s.AssignToRoute(itinerary)).Return(mockState2).Repeat.Once(); mockState1.Expect(s => s.Equals(mockState2)).Return(false).Repeat.Any(); mocks.Add(mockState1); mocks.Add(mockState2); ChangeEventArgs<IItinerary> eventArguments = null; ICargo eventSender = null; // act: EventHandler<ChangeEventArgs<IItinerary>> handler = delegate(object sender, ChangeEventArgs<IItinerary> e) { eventArguments = e; eventSender = sender as ICargo; }; TCargo underTest = new FakeCargo(mockState1); underTest.ItineraryChanged += handler; underTest.ItineraryChanged -= handler; underTest.AssignToRoute(itinerary); // assert: Assert.AreSame(itinerary, underTest.Itinerary); Assert.IsNull(eventArguments); Assert.IsNull(eventSender); foreach(object mock in mocks) mock.VerifyAllExpectations(); }
public void SpecifyNewRoute_withASpecification_dontBlockExceptionsFromCurrentState() { // arrange: GList mocks = new GList(); Exception eThrown = new Exception("Catch me."); TrackingId identifier = new TrackingId("CARGO01"); IRouteSpecification route = MockRepository.GenerateStrictMock<IRouteSpecification>(); mocks.Add(route); IRouteSpecification route2 = MockRepository.GenerateStrictMock<IRouteSpecification>(); mocks.Add(route2); CargoState mockState1 = MockRepository.GeneratePartialMock<CargoState>(identifier, route); mockState1.Expect(s => s.SpecifyNewRoute(route2)).Throw(eThrown); mocks.Add(mockState1); ChangeEventArgs<IRouteSpecification> eventArguments = null; ICargo eventSender = null; // act: TCargo underTest = new FakeCargo(mockState1); underTest.NewRouteSpecified += delegate(object sender, ChangeEventArgs<IRouteSpecification> e) { eventArguments = e; eventSender = sender as ICargo; }; Assert.Throws<Exception>(delegate { underTest.SpecifyNewRoute(route2); }, "Catch me."); // assert: Assert.AreSame(route, underTest.RouteSpecification); Assert.IsNull(eventArguments); Assert.IsNull(eventSender); foreach(object mock in mocks) mock.VerifyAllExpectations(); }
public void AssignToRoute_withAnItinerary_dontBlockExceptionsFromCurrentState() { // arrange: GList mocks = new GList(); TrackingId identifier = new TrackingId("CARGO01"); Exception eThrown = new Exception("Catch me."); 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>(); mocks.Add(route); CargoState mockState1 = MockRepository.GeneratePartialMock<CargoState>(identifier, route); mockState1.Expect(s => s.AssignToRoute(itinerary)).Throw(eThrown).Repeat.Any(); mocks.Add(mockState1); ChangeEventArgs<IItinerary> eventArguments = null; ICargo eventSender = null; // act: TCargo underTest = new FakeCargo(mockState1); underTest.ItineraryChanged += delegate(object sender, ChangeEventArgs<IItinerary> e) { eventArguments = e; eventSender = sender as ICargo; }; Assert.Throws<Exception>(delegate{ underTest.AssignToRoute(itinerary);},"Catch me."); // assert: Assert.IsNull(underTest.Itinerary); Assert.IsNull(eventArguments); Assert.IsNull(eventSender); foreach(object mock in mocks) mock.VerifyAllExpectations(); }
public void Claim_atFinalArrivalLocation_dontBlockExceptionsFromCurrentState() { // arrange: GList mocks = new GList(); DateTime date = DateTime.Now + TimeSpan.FromDays(1); Exception eThrown = new Exception("Catch me."); TrackingId identifier = new TrackingId("CARGO01"); ILocation location = MockRepository.GenerateStrictMock<ILocation>(); mocks.Add(location); IRouteSpecification route = MockRepository.GenerateStrictMock<IRouteSpecification>(); mocks.Add(route); CargoState mockState1 = MockRepository.GeneratePartialMock<CargoState>(identifier, route); mockState1.Expect(s => s.Claim(location, date)).Throw(eThrown); mocks.Add(mockState1); HandlingEventArgs eventArguments = null; ICargo eventSender = null; // act: TCargo underTest = new FakeCargo(mockState1); underTest.Claimed += delegate(object sender, HandlingEventArgs e) { eventArguments = e; eventSender = sender as ICargo; }; Assert.Throws<Exception>(delegate { underTest.Claim(location, date); }, "Catch me."); // assert: Assert.IsNull(eventArguments); Assert.IsNull(eventSender); foreach(object mock in mocks) mock.VerifyAllExpectations(); }
public void Claim_atFinalArrivalLocation_delegateLogicToCurrentState() { // arrange: GList mocks = new GList(); TrackingId identifier = new TrackingId("CARGO01"); DateTime date = DateTime.Now + TimeSpan.FromDays(1); UnLocode unlocode = new UnLocode("FINAL"); ILocation location = MockRepository.GenerateStrictMock<ILocation>(); mocks.Add(location); IRouteSpecification route = MockRepository.GenerateStrictMock<IRouteSpecification>(); mocks.Add(route); IRouteSpecification route2 = MockRepository.GenerateStrictMock<IRouteSpecification>(); mocks.Add(route2); CargoState mockState1 = MockRepository.GeneratePartialMock<CargoState>(identifier, route); CargoState mockState2 = MockRepository.GeneratePartialMock<CargoState>(mockState1, route2); mockState1.Expect(s => s.Claim(location, date)).Return(mockState2).Repeat.Once(); mockState1.Expect(s => s.Equals(mockState2)).Return(false).Repeat.Any(); mockState2.Expect(s => s.LastKnownLocation).Return(unlocode).Repeat.AtLeastOnce(); mockState2.Expect(s => s.TransportStatus).Return(TransportStatus.Claimed).Repeat.AtLeastOnce(); mocks.Add(mockState1); mocks.Add(mockState2); HandlingEventArgs eventArguments = null; ICargo eventSender = null; // act: TCargo underTest = new FakeCargo(mockState1); underTest.Claimed += delegate(object sender, HandlingEventArgs e) { eventArguments = e; eventSender = sender as ICargo; }; underTest.Claim(location, date); // assert: Assert.AreEqual(TransportStatus.Claimed, underTest.Delivery.TransportStatus); Assert.AreSame(unlocode, underTest.Delivery.LastKnownLocation); Assert.IsNotNull(eventArguments); Assert.AreSame(unlocode, eventArguments.Delivery.LastKnownLocation); Assert.AreSame(underTest, eventSender); foreach(object mock in mocks) mock.VerifyAllExpectations(); }
public void Unload_fromVoyage_dontBlockExceptionsFromCurrentState() { // arrange: GList mocks = new GList(); DateTime date = DateTime.Now + TimeSpan.FromDays(1); VoyageNumber voyageNumber = new VoyageNumber("VYG001"); Exception eThrown = new Exception("Catch me."); TrackingId identifier = new TrackingId("CARGO01"); IVoyage voyage = MockRepository.GenerateStrictMock<IVoyage>(); mocks.Add(voyage); IRouteSpecification route = MockRepository.GenerateStrictMock<IRouteSpecification>(); mocks.Add(route); IRouteSpecification route2 = MockRepository.GenerateStrictMock<IRouteSpecification>(); mocks.Add(route2); CargoState mockState1 = MockRepository.GeneratePartialMock<CargoState>(identifier, route); mockState1.Expect(s => s.Unload(voyage, date)).Throw(eThrown); mockState1.Expect(s => s.CurrentVoyage).Return(voyageNumber).Repeat.AtLeastOnce(); mocks.Add(mockState1); HandlingEventArgs eventArguments = null; ICargo eventSender = null; // act: TCargo underTest = new FakeCargo(mockState1); underTest.Loaded += delegate(object sender, HandlingEventArgs e) { eventArguments = e; eventSender = sender as ICargo; }; Assert.Throws<Exception>(delegate { underTest.Unload(voyage, date); }, "Catch me."); // assert: Assert.AreSame(voyageNumber, underTest.Delivery.CurrentVoyage); Assert.IsNull(eventArguments); Assert.IsNull(eventSender); foreach(object mock in mocks) mock.VerifyAllExpectations(); }
public void LoadOn_Voyage_delegateLogicToCurrentState() { // arrange: GList mocks = new GList(); TrackingId identifier = new TrackingId("CARGO01"); DateTime date = DateTime.Now + TimeSpan.FromDays(1); VoyageNumber voyageNumber = new VoyageNumber("VYG001"); IVoyage voyage = MockRepository.GenerateStrictMock<IVoyage>(); mocks.Add(voyage); IRouteSpecification route = MockRepository.GenerateStrictMock<IRouteSpecification>(); mocks.Add(route); IRouteSpecification route2 = MockRepository.GenerateStrictMock<IRouteSpecification>(); mocks.Add(route2); CargoState mockState1 = MockRepository.GeneratePartialMock<CargoState>(identifier, route); CargoState mockState2 = MockRepository.GeneratePartialMock<CargoState>(mockState1, route2); mockState1.Expect(s => s.LoadOn(voyage, date)).Return(mockState2).Repeat.Once(); mockState1.Expect(s => s.Equals(mockState2)).Return(false).Repeat.Any(); mockState2.Expect(s => s.CurrentVoyage).Return(voyageNumber).Repeat.AtLeastOnce(); mocks.Add(mockState1); mocks.Add(mockState2); HandlingEventArgs eventArguments = null; ICargo eventSender = null; // act: TCargo underTest = new FakeCargo(mockState1); underTest.Loaded += delegate(object sender, HandlingEventArgs e) { eventArguments = e; eventSender = sender as ICargo; }; underTest.LoadOn(voyage, date); // assert: Assert.AreSame(voyageNumber, underTest.Delivery.CurrentVoyage); Assert.IsNotNull(eventArguments); Assert.AreSame(underTest.Delivery, eventArguments.Delivery); Assert.AreSame(underTest, eventSender); foreach(object mock in mocks) mock.VerifyAllExpectations(); }