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> /// Advances the enumerator to the next element of the collection. /// </summary> /// <returns> /// true if the enumerator was successfully advanced to the next element; /// false if the enumerator has passed the end of the collection. /// </returns> /// <exception cref="T:System.InvalidOperationException"> /// The collection was modified after the enumerator was created. /// </exception> public bool MoveNext() { _iCurrentRecord++; if (_iCurrentRecord <= _header.NumRecords) _arrayList = this.Read(); bool more = true; if (_iCurrentRecord > _header.NumRecords) { //this._dbfStream.Close(); more = false; } return more; }
public DeserializerSession([NotNull] Serializer serializer) { Serializer = serializer; _buffer = new byte[MinBufferSize]; if (serializer.Options.PreserveObjectReferences) { _objectById = new IntToObjectLookup(capacity:1); } if (serializer.Options.VersionTolerance) { _versionInfoByType = new TypeToVersionInfoLookup(); } _offset = serializer.Options.KnownTypes.Length; }
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 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 SpecifyNewRoute_withAnotherSpecification_keepTheRoutingStatusUnchanged() { // arrange: GList mocks = new GList(); TrackingId identifier = new TrackingId("CARGO01"); IRouteSpecification route = MockRepository.GenerateStrictMock<IRouteSpecification>(); IRouteSpecification route2 = MockRepository.GenerateStrictMock<IRouteSpecification>(); route.Expect(r => r.Equals(route2)).Return(false).Repeat.AtLeastOnce(); mocks.Add(route); mocks.Add(route2); // act: TCargo underTest = new TCargo(identifier, route); underTest.SpecifyNewRoute(route2); // assert: Assert.AreEqual(RoutingStatus.NotRouted, underTest.Delivery.RoutingStatus); foreach(object mock in mocks) mock.VerifyAllExpectations(); }
public void SpecifyNewRoute_withNullSpecification_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.SpecifyNewRoute(null); }); // assert: Assert.AreEqual(RoutingStatus.NotRouted, underTest.Delivery.RoutingStatus); 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 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_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 object Call(Interpreter interpreter, Token token, List arguments) { return(arguments[0] is DictionaryInstance); }
public object Call(Interpreter interpreter, Token token, List arguments) { return(self.container.Count); }
public object Call(Interpreter interpreter, Token token, List arguments) { self.container.Remove(arguments[0]); return(null); }
public void Unload_05() { // 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.NextExpectedLocation).Return(new UnLocode("NEXTL")).Repeat.Any(); 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); // assert: Assert.Throws<ArgumentException>(delegate {state.Unload(voyage, arrival - TimeSpan.FromDays(2));}); foreach (object mock in mocks) mock.VerifyAllExpectations(); }
/// ---------------------------------------------------------------------------------------- /// <summary> /// Decrypt, parse and use new SEB settings /// </summary> /// ---------------------------------------------------------------------------------------- public static bool StoreDecryptedSEBSettings(byte[] sebData) { DictObj sebPreferencesDict; string sebFilePassword = null; bool passwordIsHash = false; X509Certificate2 sebFileCertificateRef = null; sebPreferencesDict = DecryptSEBSettings(sebData, false, ref sebFilePassword, ref passwordIsHash, ref sebFileCertificateRef); if (sebPreferencesDict == null) return false; //Decryption didn't work, we abort Logger.AddInformation("Reconfiguring"); // Reset SEB, close third party applications SEBClientInfo.SebWindowsClientForm.closeSebClient = false; Logger.AddInformation("Attempting to CloseSEBForm for reconfiguration"); SEBClientInfo.SebWindowsClientForm.CloseSEBForm(); Logger.AddInformation("Successfully CloseSEBForm for reconfiguration"); SEBClientInfo.SebWindowsClientForm.closeSebClient = true; //SEBClientInfo.SebWindowsClientForm.Close(); //SEBClientInfo.SebWindowsClientForm.Dispose(); // We need to check if setting for createNewDesktop changed // Check this SEBClientInfo.CreateNewDesktopOldValue = false; if ((int)sebPreferencesDict[SEBSettings.KeySebConfigPurpose] == (int)SEBSettings.sebConfigPurposes.sebConfigPurposeStartingExam) { /// /// If these SEB settings are ment to start an exam /// Logger.AddInformation("Reconfiguring to start an exam"); /// If these SEB settings are ment to start an exam // Store decrypted settings Logger.AddInformation("Attempting to StoreSebClientSettings"); SEBSettings.StoreSebClientSettings(sebPreferencesDict); Logger.AddInformation("Successfully StoreSebClientSettings"); // Set the flag that SEB is running in exam mode now SEBClientInfo.examMode = true; //Re-initialize logger SEBClientInfo.InitializeLogger(); // Check if SEB is running on the standard desktop and the new settings demand to run in new desktop (createNewDesktop = true) // or the other way around! if (false) { // If it did, SEB needs to quit and be restarted manually for the new setting to take effekt if (SEBClientInfo.CreateNewDesktopOldValue == false) { SEBMessageBox.Show(SEBUIStrings.settingsRequireNewDesktop, SEBUIStrings.settingsRequireNewDesktopReason, MessageBoxIcon.Error, MessageBoxButtons.OK); } else { SEBMessageBox.Show(SEBUIStrings.settingsRequireNotNewDesktop, SEBUIStrings.settingsRequireNotNewDesktopReason, MessageBoxIcon.Error, MessageBoxButtons.OK); } //SEBClientInfo.SebWindowsClientForm.closeSebClient = true; SEBClientInfo.SebWindowsClientForm.ExitApplication(); } // Re-Initialize SEB according to the new settings Logger.AddInformation("Attempting to InitSEBDesktop for reconfiguration"); if (!SebWindowsClientMain.InitSEBDesktop()) return false; Logger.AddInformation("Sucessfully InitSEBDesktop for reconfiguration"); // Re-open the main form //SEBClientInfo.SebWindowsClientForm = new SebWindowsClientForm(); //SebWindowsClientMain.singleInstanceController.SetMainForm(SEBClientInfo.SebWindowsClientForm); //return if initializing SEB with openend preferences was successful Logger.AddInformation("Attempting to OpenSEBForm for reconfiguration"); var ret = SEBClientInfo.SebWindowsClientForm.OpenSEBForm(); Logger.AddInformation("Successfully OpenSEBForm for reconfiguration"); return ret; } else { /// /// If these SEB settings are ment to configure a client /// Logger.AddInformation("Reconfiguring to configure a client"); /// If these SEB settings are ment to configure a client // Check if we have embedded identities and import them into the Windows Certifcate Store ListObj embeddedCertificates = (ListObj)sebPreferencesDict[SEBSettings.KeyEmbeddedCertificates]; for (int i = embeddedCertificates.Count - 1; i >= 0; i--) { // Get the Embedded Certificate DictObj embeddedCertificate = (DictObj)embeddedCertificates[i]; // Is it an identity? if ((int)embeddedCertificate[SEBSettings.KeyType] == 1) { // Store the identity into the Windows Certificate Store SEBProtectionController.StoreCertificateIntoStore((byte[])embeddedCertificate[SEBSettings.KeyCertificateData]); } // Remove the identity from settings, as it should be only stored in the Certificate Store and not in the locally stored settings file embeddedCertificates.RemoveAt(i); } // Store decrypted settings SEBSettings.StoreSebClientSettings(sebPreferencesDict); //Re-initialize logger SEBClientInfo.InitializeLogger(); // Write new settings to the localapp directory SEBSettings.WriteSebConfigurationFile(SEBClientInfo.SebClientSettingsAppDataFile, "", false, null, SEBSettings.sebConfigPurposes.sebConfigPurposeConfiguringClient); // Re-Initialize SEB desktop according to the new settings if (!SebWindowsClientMain.InitSEBDesktop()) return false; if (SEBClientInfo.SebWindowsClientForm.OpenSEBForm()) { // Activate SebWindowsClient so the message box gets focus //SEBClientInfo.SebWindowsClientForm.Activate(); // Check if setting for createNewDesktop changed if (false) { // If it did, SEB needs to quit and be restarted manually for the new setting to take effekt SEBMessageBox.Show(SEBUIStrings.sebReconfiguredRestartNeeded, SEBUIStrings.sebReconfiguredRestartNeededReason, MessageBoxIcon.Warning, MessageBoxButtons.OK); //SEBClientInfo.SebWindowsClientForm.closeSebClient = true; SEBClientInfo.SebWindowsClientForm.ExitApplication(); } if (SEBMessageBox.Show(SEBUIStrings.sebReconfigured, SEBUIStrings.sebReconfiguredQuestion, MessageBoxIcon.Question, MessageBoxButtons.YesNo) == DialogResult.No) { //SEBClientInfo.SebWindowsClientForm.closeSebClient = true; SEBClientInfo.SebWindowsClientForm.ExitApplication(); } return true; //reading preferences was successful } else { return false; } } }
public object Call(Interpreter interpreter, Token token, List arguments) { return(self.ToString()); }
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 object Call(Interpreter interpreter, Token token, List arguments) { return(self.container.ContainsValue(arguments[0])); }
/// <summary> /// Read a single dbase record /// </summary> /// <returns> /// The read shapefile record, /// or null if there are no more records. /// </returns> private ArrayList Read() { ArrayList attrs = null; bool foundRecord = false; while (!foundRecord) { // retrieve the record length int tempNumFields = _header.NumFields; // storage for the actual values attrs = new ArrayList(tempNumFields); // read the deleted flag char tempDeleted = (char)_dbfStream.ReadChar(); // read the record length int tempRecordLength = 1; // for the deleted character just read. // read the Fields for (int j = 0; j < tempNumFields; j++) { // find the length of the field. int tempFieldLength = _header.Fields[j].Length; tempRecordLength = tempRecordLength + tempFieldLength; // find the field type char tempFieldType = _header.Fields[j].DbaseType; // read the data. object tempObject = null; switch (tempFieldType) { case 'L': // logical data type, one character (T,t,F,f,Y,y,N,n) char tempChar = (char)_dbfStream.ReadByte(); if ((tempChar == 'T') || (tempChar == 't') || (tempChar == 'Y') || (tempChar == 'y')) tempObject = true; else tempObject = false; break; case 'C': // character record. if (_header.Encoding == null) { char[] sbuffer = _dbfStream.ReadChars(tempFieldLength); tempObject = new string(sbuffer).Trim().Replace("\0", String.Empty); //.ToCharArray(); } else { var buf = _dbfStream.ReadBytes(tempFieldLength); tempObject = _header.Encoding.GetString(buf, 0, buf.Length).Trim(); } break; case 'D': // date data type. char[] ebuffer = new char[8]; ebuffer = _dbfStream.ReadChars(8); string tempString = new string(ebuffer, 0, 4); int year; if (!Int32.TryParse(tempString, NumberStyles.Integer, CultureInfo.InvariantCulture, out year)) break; tempString = new string(ebuffer, 4, 2); int month; if (!Int32.TryParse(tempString, NumberStyles.Integer, CultureInfo.InvariantCulture, out month)) break; tempString = new string(ebuffer, 6, 2); int day; if (!Int32.TryParse(tempString, NumberStyles.Integer, CultureInfo.InvariantCulture, out day)) break; try { if (day>0 && year>0 && month>0 && month<=12) // don't try to parse date when day is invalid - it will be useless and slow for large files tempObject = new DateTime(year, month, day); } catch (Exception) { } break; case 'N': // number case 'F': // floating point number char[] fbuffer = new char[tempFieldLength]; fbuffer = _dbfStream.ReadChars(tempFieldLength); tempString = new string(fbuffer); double val; if (Double.TryParse(tempString.Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out val)) { tempObject = val; } else { // if we can't format the number, just save it as a string tempObject = tempString; } break; default: throw new NotSupportedException("Do not know how to parse Field type " + tempFieldType); } attrs.Add(tempObject); } // ensure that the full record has been read. if (tempRecordLength < _header.RecordLength) { byte[] tempbuff = new byte[_header.RecordLength - tempRecordLength]; tempbuff = _dbfStream.ReadBytes(_header.RecordLength - tempRecordLength); } // add the row if it is not deleted. if (tempDeleted != '*') { foundRecord = true; } } return attrs; }
public object Call(Interpreter interpreter, Token token, List arguments) { return(new DictionaryInstance(new Dict())); }
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(); }
/// <summary> /// Advances the IDataReader to the next record. /// </summary> /// <returns>true if there are more rows; otherwise, false.</returns> public bool Read() { bool moreDbfRecords = _dbfEnumerator.MoveNext(); bool moreShpRecords = _shpEnumerator.MoveNext(); if (!moreDbfRecords) { int a = 0; a++; } if (!moreShpRecords) { int b = 0; b++; } _moreRecords = moreDbfRecords && moreShpRecords; // get current shape geometry = (IGeometry)_shpEnumerator.Current; // get current dbase record _columnValues = (ArrayList)_dbfEnumerator.Current; return _moreRecords; // moreDbfRecords && moreShpRecords; }
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 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(); }
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 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 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 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(); }
public void SpecifyNewRoute_withAnotherSpecification_fireNewRouteSpecified() { // arrange: GList mocks = new GList(); TrackingId identifier = new TrackingId("CARGO01"); IRouteSpecification route = MockRepository.GenerateStrictMock<IRouteSpecification>(); IRouteSpecification route2 = MockRepository.GenerateStrictMock<IRouteSpecification>(); route.Expect(r => r.Equals(route2)).Return(false).Repeat.AtLeastOnce(); mocks.Add(route); mocks.Add(route2); ChangeEventArgs<IRouteSpecification> eventArguments = null; ICargo eventSender = null; // act: TCargo underTest = new TCargo(identifier, route); underTest.NewRouteSpecified += delegate(object sender, ChangeEventArgs<IRouteSpecification> e) { eventArguments = e; eventSender = sender as ICargo; }; underTest.SpecifyNewRoute(route2); // assert: Assert.AreSame(route2, eventArguments.NewValue); Assert.AreSame(route, eventArguments.OldValue); Assert.AreSame(eventSender, underTest); 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 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 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 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(); }
/// <summary> /// /// </summary> /// <param name="dbaseFields"></param> /// <param name="columnValues"></param> public RowStructure(DbaseFieldDescriptor[] dbaseFields, ArrayList columnValues) { _dbaseFields = dbaseFields; _columnValues = columnValues; }
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(); }
/// <summary> /// Read a single dbase record /// </summary> /// <returns> /// The read shapefile record, /// or null if there are no more records. /// </returns> private ArrayList Read() { ArrayList attrs = null; bool foundRecord = false; while (!foundRecord) { // retrieve the record length int tempNumFields = _header.NumFields; // storage for the actual values attrs = new ArrayList(tempNumFields); // read the deleted flag char tempDeleted = (char)_dbfStream.ReadChar(); // read the record length int tempRecordLength = 1; // for the deleted character just read. // read the Fields for (int j = 0; j < tempNumFields; j++) { // find the length of the field. int tempFieldLength = _header.Fields[j].Length; tempRecordLength = tempRecordLength + tempFieldLength; // find the field type char tempFieldType = _header.Fields[j].DbaseType; // read the data. object tempObject = null; switch (tempFieldType) { case 'L': // logical data type, one character (T,t,F,f,Y,y,N,n) char tempChar = (char)_dbfStream.ReadByte(); if ((tempChar == 'T') || (tempChar == 't') || (tempChar == 'Y') || (tempChar == 'y')) { tempObject = true; } else { tempObject = false; } break; case 'C': // character record. char[] sbuffer = new char[tempFieldLength]; sbuffer = _dbfStream.ReadChars(tempFieldLength); // use an encoding to ensure all 8 bits are loaded // tempObject = new string(sbuffer, "ISO-8859-1").Trim(); //HACK: this can be made more efficient tempObject = new string(sbuffer).Trim().Replace("\0", String.Empty); //.ToCharArray(); break; case 'D': // date data type. char[] ebuffer = new char[8]; ebuffer = _dbfStream.ReadChars(8); string tempString = new string(ebuffer, 0, 4); int year; if (!Int32.TryParse(tempString, NumberStyles.Integer, CultureInfo.InvariantCulture, out year)) { break; } tempString = new string(ebuffer, 4, 2); int month; if (!Int32.TryParse(tempString, NumberStyles.Integer, CultureInfo.InvariantCulture, out month)) { break; } tempString = new string(ebuffer, 6, 2); int day; if (!Int32.TryParse(tempString, NumberStyles.Integer, CultureInfo.InvariantCulture, out day)) { break; } tempObject = new DateTime(year, month, day); break; case 'N': // number case 'F': // floating point number char[] fbuffer = new char[tempFieldLength]; fbuffer = _dbfStream.ReadChars(tempFieldLength); tempString = new string(fbuffer); try { tempObject = Double.Parse(tempString.Trim(), CultureInfo.InvariantCulture); } catch (FormatException) { // if we can't format the number, just save it as a string tempObject = tempString; } break; default: throw new NotSupportedException("Do not know how to parse Field type " + tempFieldType); } attrs.Add(tempObject); } // ensure that the full record has been read. if (tempRecordLength < _header.RecordLength) { byte[] tempbuff = new byte[_header.RecordLength - tempRecordLength]; tempbuff = _dbfStream.ReadBytes(_header.RecordLength - tempRecordLength); } // add the row if it is not deleted. if (tempDeleted != '*') { foundRecord = true; } } return(attrs); }
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 object Call(Interpreter interpreter, Token token, List arguments) { self.container.Clear(); return(null); }
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(); }