Ejemplo n.º 1
0
        public void CapitalCities_must_call_BulkAsync_method()
        {
            var mockFileSystem = new MockFileSystem();
            var mockInputFile  = new MockFileData("city,city_ascii,lat,lng,country,iso2,iso3,admin_name,capital,population,id\nPristina,Pristina,42.6666,21.1724,Kosovo,XK,XKS,Prishtinë,primary,,1901760068");

            mockFileSystem.AddFile(@"capital_cities.csv", mockInputFile);
            CapitalCityRecord record = new CapitalCityRecord()
            {
                City       = "Pristina",
                Country    = "Kosovo",
                Id         = "1901760068",
                CityAscii  = "Pristina",
                Population = null,
                Latitude   = new decimal(42.6666),
                Longitude  = new decimal(21.1724)
            };
            CapitalSearchDocument        capitalSearch = new CapitalSearchDocument(record);
            List <CapitalSearchDocument> cp            = new List <CapitalSearchDocument>()
            {
                capitalSearch
            };



            var parameter = CsvProcessor.ProcessCsvFiles(mockFileSystem);

            Assert.AreEqual(capitalSearch, parameter[0]);
        }
Ejemplo n.º 2
0
        public async Task RunAsync()
        {
            // if the index exists, let's delete it
            // you probably don't want to do this kind of
            // index management in a production environment
            var index = await client.Indices.ExistsAsync(IndexName);

            if (index.Exists)
            {
                await client.Indices.DeleteAsync(IndexName);
            }

            // let's create the index
            var createResult =
                await client.Indices.CreateAsync(IndexName, c => c
                                                 .Settings(s => s
                                                           .Analysis(a => a
                                                                     // our custom search analyzer
                                                                     .AddSearchAnalyzer()
                                                                     )
                                                           )
                                                 .Map <CapitalSearchDocument>(m => m.AutoMap())
                                                 );



            // let's load the data

            var records = CsvProcessor.ProcessCsvFiles(fileSystem);

            // we are pushing all the data in at once
            var bullkResult =
                await client
                .BulkAsync(b => b
                           .Index(IndexName)
                           .CreateMany(records)
                           );
        }