public void InsertAndGetFromFreshDB()
        {
            //Given
            connection = DBHelper.GetDbConnection(dbLocation);
            connection.InitializeDB();
            IMatchProvider provider = new MatchProvider(connection);

            //When
            provider.SaveMatchLevel1("near", "actual");
            var matches = provider.GetMatches("near").ToList();

            //Then
            Assert.AreEqual(1, matches.Count());
            Assert.IsTrue(matches.All(x => x.AltLevel1 == "near"));
        }
        public void InsertAndGetLevel2FromFreshDB()
        {
            //Given
            connection = DBHelper.GetDbConnection(dbLocation);
            connection.InitializeDB();
            IMatchProvider provider = new MatchProvider(connection);

            //When
            provider.SaveMatchLevel2("near", "level1", "level2");
            var matches = provider.GetMatches("near", "level1");

            //Then
            Assert.AreEqual(1, matches.Count());
            var match = matches.Single();
            Assert.AreEqual("level2", match.Level2);
        }
        public void GetMatches_InputWithDifferentCase_RecordRetrieved()
        {
            // Arrange
            connection = DBHelper.GetDbConnection(dbLocation);
            connection.InitializeDB();
            IMatchProvider provider = new MatchProvider(connection);
            provider.SaveMatchLevel1("Near", "actual");

            // Act
            List<Level1Match> matchesLowerCase =
                provider.GetMatches("near").ToList();

            // Assert
            Assert.AreEqual(1, matchesLowerCase.Count());
            Assert.AreEqual("Near", matchesLowerCase.Single().AltLevel1);
            Assert.AreEqual("actual", matchesLowerCase.Single().Level1);
        }
        public void SaveMatchLevel1_InsertDuplicateMatch_RecordOverwritten()
        {
            // Arrange
            connection = DBHelper.GetDbConnection(dbLocation);
            connection.InitializeDB();
            IMatchProvider provider = new MatchProvider(connection);

            // Act
            provider.SaveMatchLevel1("input", "match_x");
            provider.SaveMatchLevel1("input", "match_y");
            IEnumerable<Level1Match> matches = provider.GetMatches("input").ToList();

            // Asset
            Assert.AreEqual(1, matches.Count());
            var match = matches.Single();
            Assert.AreEqual("input", match.AltLevel1);
            Assert.AreEqual("match_y", match.Level1);
        }
        public void SaveMatchLevel1_InsertWithDifferentCase_RecordOverwritten()
        {
            // Arrange
            connection = DBHelper.GetDbConnection(dbLocation);
            connection.InitializeDB();
            IMatchProvider provider = new MatchProvider(connection);

            // Act
            provider.SaveMatchLevel1("near", "actual");
            provider.SaveMatchLevel1("Near", "actual");
            List<Level1Match> matchesUpperCase =
                provider.GetMatches("NEAR").ToList();
            List<Level1Match> matchesLowerCase =
                provider.GetMatches("near").ToList();

            // Assert
            Assert.AreEqual(1, matchesUpperCase.Count());
            Assert.AreEqual(1, matchesLowerCase.Count());
            Assert.AreEqual(
                matchesUpperCase.First().MatchId,
                matchesLowerCase.First().MatchId);
        }
        public void InsertTooLongMatch()
        {
            //Given
            connection = DBHelper.GetDbConnection(dbLocation);
            connection.InitializeDB();
            IMatchProvider provider = new MatchProvider(connection);
            string tooLong = new String('a', maxLength + 1);

            //When
            provider.SaveMatchLevel1(tooLong, tooLong);

            var matches = provider.GetMatches(tooLong);

            //Then exception
        }
        public void InsertToFreshDBAndGetFromDeletedDB()
        {
            //Given
            connection = DBHelper.GetDbConnection(dbLocation);
            connection.InitializeDB();
            IMatchProvider provider = new MatchProvider(connection);

            //When
            provider.SaveMatchLevel1("near", "actual");
            provider.SaveMatchLevel1("near", "actual3");
            connection.Close();
            File.Delete(dbLocation);

            connection = DBHelper.GetDbConnection(dbLocation);
            connection.InitializeDB();
            provider = new MatchProvider(connection);
            var matches = provider.GetMatches("near");
            connection.Close();

            //Then
            Assert.AreEqual(0, matches.Count());
        }
        public void InsertSpecialCharactersMatch()
        {
            //Given
            connection = DBHelper.GetDbConnection(dbLocation);
            connection.InitializeDB();
            IMatchProvider provider = new MatchProvider(connection);
            string specialCharacters =
                "%ùéèôçà六书/六書形声字/形聲字абвгдеёжзийклмнопрстуфхцчшщъыьэюя";
            int length = specialCharacters.Length;

            //When
            provider.SaveMatchLevel1(specialCharacters, specialCharacters);
            var matches = provider.GetMatches(specialCharacters);

            //Then
            Assert.AreEqual(1, matches.Count());
            var match = matches.Single();
            Assert.AreEqual(specialCharacters.Length, match.AltLevel1.Length);
            Assert.AreEqual(specialCharacters, match.AltLevel1);
            Assert.AreEqual(specialCharacters, match.Level1);
        }
        public void InsertMaxLengthMatch()
        {
            //Given
            connection = DBHelper.GetDbConnection(dbLocation);
            connection.InitializeDB();
            IMatchProvider provider = new MatchProvider(connection);
            string veryLong = new String('a', maxLength);

            //When
            provider.SaveMatchLevel1(veryLong, veryLong);
            var matches = provider.GetMatches(veryLong);

            //Then
            Assert.AreEqual(1, matches.Count());
            var match = matches.Single();
            Assert.AreEqual(veryLong, match.AltLevel1);
            Assert.AreEqual(veryLong, match.Level1);
        }
Exemplo n.º 10
0
        public void GeoCoder_PerfsTestsUsingDictionaries()
        {
            connection = DBHelper.GetDbConnection(dbLocation);
            connection.InitializeDB();
            GeoCoder geoCoder = new GeoCoder(connection);
            geoCoder.LoadGazetteerFile(@"PHL_adm3.csv");
                //You need to copy this file manually
            Stopwatch watch = new Stopwatch();
            watch.Start();
            geoCoder.SetGazetteerColumns(
                new GazetteerColumnHeaders
                {
                    Level1Code = "ID_1",
                    Level2Code = "ID_2",
                    Level3Code = "ID_3",
                    Level1Name = "NAME_1",
                    Level2Name = "NAME_2",
                    Level3Name = "NAME_3"
                },
                false);

            Debug.WriteLine("Time to create dictionaries: " + watch.Elapsed.TotalSeconds);

            foreach (int linesCount in new[] {500, 1000, 2000})
            {
                geoCoder.LoadInputFileCsv(GenerateInputFile(linesCount));
                geoCoder.SetInputColumns(geoCoder.DefaultInputColumnHeaders());
                watch.Restart();
                geoCoder.AddAllLocationCodes();
                var elapsed = watch.Elapsed.TotalSeconds;
                //LocationCodes.useDictionaries = !LocationCodes.useDictionaries;
                geoCoder.LoadInputFileCsv(GenerateInputFile(linesCount));
                geoCoder.SetInputColumns(geoCoder.DefaultInputColumnHeaders());
                watch.Restart();
                geoCoder.AddAllLocationCodes();
                Debug.WriteLine(
                    linesCount + " input lines: " + elapsed + " vs " +
                    watch.Elapsed.TotalSeconds);
                // LocationCodes.useDictionaries = !LocationCodes.useDictionaries;

                foreach (var row in geoCoder.InputData.AsEnumerable())
                {
                    var elems = row.ItemArray;
                    Assert.IsFalse(elems[5] is DBNull);
                    Assert.IsFalse(elems[6] is DBNull);
                    Assert.IsFalse(elems[7] is DBNull);
                }
            }
        }