public void SaveToShouldCheckForNullArguments() { Mainfile mainfile = this.mainfileBuilder.Create(); Assert.That(() => mainfile.SaveTo(null, MainfileType.Address), Throws.InstanceOf <ArgumentNullException>()); }
public void ShouldBeAbleToReadAddressFiles() { this.mainfileBuilder.AddFile(string.Empty, ExamplePafFileData.MainAddress); Mainfile mainfile = this.mainfileBuilder.Create(); using (IDataReader reader = mainfile.CreateReader(MainfileType.Address)) { Assert.That(reader.Read(), Is.True); Assert.That(reader["Key"], Is.EqualTo(2572775)); Assert.That(reader["Postcode"], Is.EqualTo("CF30AA")); Assert.That(reader["LocalityKey"], Is.EqualTo(24904)); Assert.That(reader["ThoroughfareKey"], Is.EqualTo(21479)); Assert.That(reader["ThoroughfareDescriptorKey"], Is.EqualTo(6)); Assert.That(reader["DependentThoroughfareKey"], Is.EqualTo(DBNull.Value)); Assert.That(reader["DependentThoroughfareDescriptorKey"], Is.EqualTo(DBNull.Value)); Assert.That(reader["BuildingNumber"], Is.EqualTo(1)); Assert.That(reader["BuildingNameKey"], Is.EqualTo(DBNull.Value)); Assert.That(reader["SubBuildingNameKey"], Is.EqualTo(DBNull.Value)); Assert.That(reader["NumberOfHouseholds"], Is.EqualTo(1)); Assert.That(reader["OrganisationKey"], Is.EqualTo(DBNull.Value)); Assert.That(reader["PostcodeType"], Is.EqualTo((int)DeliveryPointType.SmallUser)); Assert.That(reader["IsBuildingNumberConcatenated"], Is.False); Assert.That(reader["DeliveryPointSuffix"], Is.EqualTo("1A")); Assert.That(reader["IsSmallUserOrganisation"], Is.False); Assert.That(reader.IsDBNull(reader.GetOrdinal("POBoxNumber")), Is.True); Assert.That(reader.Read(), Is.False); } }
private Task SaveThoroughfares(Mainfile data) { TableInformation info = new TableInformation { ColumnMappings = DefaultMappings, ColumnsToConvert = new[] { 1 }, Name = "Thoroughfares" }; return(this.BulkCopy(data.CreateReader(MainfileType.Thoroughfares), info)); }
private Task SaveOrganisations(Mainfile data) { TableInformation info = new TableInformation { ColumnMappings = DefaultMappings, ColumnsToConvert = new[] { 1, 2 }, Name = "Organisations" }; return(this.BulkCopy(data.CreateReader(MainfileType.Organisations), info)); }
public string SaveToShouldSaveTheSpecifiedType(string content, MainfileType type) { PafRepository repository = Substitute.For <PafRepository>(); this.mainfileBuilder.AddFile(type.ToString(), content); Mainfile mainfile = this.mainfileBuilder.Create(); mainfile.SaveTo(repository, type); return(repository.ReceivedCalls().Single().GetMethodInfo().Name); }
public void ShouldBeAbleToReadSubBuildingNameFiles() { this.mainfileBuilder.AddFile(string.Empty, ExamplePafFileData.SubBuildingName); Mainfile mainfile = this.mainfileBuilder.Create(); using (IDataReader reader = mainfile.CreateReader(MainfileType.SubBuildingNames)) { Assert.That(reader.Read(), Is.True); Assert.That(reader["Key"], Is.EqualTo(2)); Assert.That(reader["Name"], Is.EqualTo("1")); Assert.That(reader.Read(), Is.False); } }
public void ShouldBeAbleToReadThoroughfareDescriptorFiles() { this.mainfileBuilder.AddFile(string.Empty, ExamplePafFileData.ThoroughfareDescriptors); Mainfile mainfile = this.mainfileBuilder.Create(); using (IDataReader reader = mainfile.CreateReader(MainfileType.ThoroughfareDescriptors)) { Assert.That(reader.Read(), Is.True); Assert.That(reader["Key"], Is.EqualTo(1)); Assert.That(reader["Descriptor"], Is.EqualTo("ROAD")); Assert.That(reader.Read(), Is.False); } }
public static void Main(string[] args) { const string PathToExampleData = @"D:\PAF\Fixed PAF"; var mainfile = new Mainfile(PathToExampleData); var bulkInserter = new BulkInserter(); Console.Write("Inserting records"); var stopwatch = Stopwatch.StartNew(); bulkInserter.Insert(mainfile).Wait(); stopwatch.Stop(); Console.WriteLine("finished ({0:f1} secs.)", stopwatch.Elapsed.TotalSeconds); Console.ReadKey(); }
public void SaveToShouldReadFromMultipleFilesOfTheSameType() { this.mainfileBuilder.AddFile("Locality1", ExamplePafFileData.Localities); this.mainfileBuilder.AddFile("Locality2", ExamplePafFileData.Localities); this.mainfileBuilder.AddFile("MainAddress1", ExamplePafFileData.MainAddress); Mainfile mainfile = this.mainfileBuilder.Create(); PafRepository repository = Substitute.For <PafRepository>(); mainfile.SaveTo(repository, MainfileType.Localities); repository.ReceivedWithAnyArgs(2).AddLocality(null); }
public static void Main(string[] args) { const string PathToExampleData = @"D:\PAF\Fixed PAF"; var mainfile = new Mainfile(PathToExampleData); var repository = new MemoryRepository(); // Load the PAF data (this could be changed to use the view in the // SqlServerExample). Console.Write("Creating repository..."); var stopwatch = Stopwatch.StartNew(); mainfile.SaveAll(repository); stopwatch.Stop(); Console.WriteLine("finished ({0} inserted in {1:f1} secs.)", repository.Addresses.Count, stopwatch.Elapsed.TotalSeconds); // Create the Lucene.NET index Console.Write("Creating index..."); DeleteExistingIndex(); stopwatch.Restart(); using (var indexer = new Indexer()) { foreach (KeyValuePair <int, string> address in repository.Addresses) { indexer.Add(address.Key, address.Value); } indexer.Optimize(); } stopwatch.Stop(); Console.WriteLine("finished ({0:f1} secs.)", stopwatch.Elapsed.TotalSeconds); // An example search using (var finder = new AddressFinder()) { stopwatch.Restart(); int[] addresses = finder.FindAddresses("2 Chuch St"); // Notice we've misspelled 'Church' and used an abbreviation for Street stopwatch.Stop(); Console.WriteLine("{0} matches found in {1}ms.", addresses.Length, stopwatch.ElapsedMilliseconds); // This could be replaced with a call to SQL to get all the // addresses + postcodes. foreach (int addressKey in addresses) { Console.WriteLine("{0}: '{1}'", addressKey, repository.FindAddress(addressKey)); } } Console.ReadKey(); }
public void ShouldBeAbleToReadOrganisationFiles() { this.mainfileBuilder.AddFile(string.Empty, ExamplePafFileData.Organisations); Mainfile mainfile = this.mainfileBuilder.Create(); using (IDataReader reader = mainfile.CreateReader(MainfileType.Organisations)) { Assert.That(reader.Read(), Is.True); Assert.That(reader["Key"], Is.EqualTo(122173)); Assert.That(reader["PostcodeType"], Is.EqualTo((int)DeliveryPointType.SmallUser)); Assert.That(reader["Name"], Is.EqualTo("H M COASTGUARD")); Assert.That(reader["Department"], Is.EqualTo("M R S C HUMBER")); Assert.That(reader.Read(), Is.False); } }
public void ShouldBeAbleToReadLocalityFiles() { this.mainfileBuilder.AddFile(string.Empty, ExamplePafFileData.Localities); Mainfile mainfile = this.mainfileBuilder.Create(); using (IDataReader reader = mainfile.CreateReader(MainfileType.Localities)) { Assert.That(reader.Read(), Is.True); Assert.That(reader["Key"], Is.EqualTo(3658)); Assert.That(reader["PostTown"], Is.EqualTo("BODMIN")); Assert.That(reader["DependentLocality"], Is.EqualTo("CARDINHAM")); Assert.That(reader["DoubleDependentLocality"], Is.EqualTo("LITTLE DOWNS")); Assert.That(reader.Read(), Is.False); } }
public void SaveAllShouldSaveAddressFilesLast() { foreach (FieldInfo field in typeof(ExamplePafFileData).GetFields()) { this.mainfileBuilder.AddFile(field.Name, (string)field.GetValue(null)); } Mainfile mainfile = this.mainfileBuilder.Create(); var repository = Substitute.For <PafRepository>(); mainfile.SaveAll(repository); MethodInfo lastCalled = repository.ReceivedCalls().Select(c => c.GetMethodInfo()).Last(); Assert.That(lastCalled.Name, Is.EqualTo("AddAddress")); }
public async Task Insert(Mainfile data) { // We can prepare this table in memory in parallel with the others // but have to save it on its own due to foreign keys var addresses = new DataTable(); await Task.WhenAll( this.SaveAddressesToTable(data, MainfileType.Address, addresses), this.SaveBuildingNames(data), this.SaveLocalities(data), this.SaveOrganisations(data), this.SaveSubBuildingNames(data), this.SaveThoroughfareDescriptors(data), this.SaveThoroughfares(data)); // Now we can save the address table await this.SaveAddresses(addresses); }
public static void Main(string[] args) { const string PathToExampleData = @"D:\PAF\Fixed PAF"; var addressFormatter = new AddressFormatter(); var mainfile = new Mainfile(PathToExampleData); var repository = new MemoryRepository(FormatOptions.Postcode | FormatOptions.TitleCase); var sw = System.Diagnostics.Stopwatch.StartNew(); mainfile.SaveAll(repository); sw.Stop(); Console.WriteLine("Converted {0} addresses in {1}ms", repository.Addresses.Count, sw.ElapsedMilliseconds); Console.WriteLine( string.Join( "\n", addressFormatter.Format(repository.Addresses[1]))); Console.ReadKey(); }
private Task SaveAddressesToTable(Mainfile data, MainfileType type, DataTable table) { return(Task.Run(() => { using (IDataReader reader = data.CreateReader(type)) { CopyColumns(reader, table); CopyRows( reader, table, values => { string postcode = values[11] as string; if ((postcode != null) && (postcode.Length > 3)) { values[11] = postcode.Insert(postcode.Length - 3, " "); } }); } })); }