Example #1
0
        public void FindEntry_should_return_null_when_the_requested_entry_does_not_exist()
        {
            TnsParser parser     = new TnsParser(AddTnsNameTest.SAMPLE_FILE);
            TnsEntry  foundEntry = parser.FindEntry("eastwind.world");

            Assert.IsNull(foundEntry);
        }
Example #2
0
        public void FindEntry_should_only_ecognize_entry_names_that_start_in_the_first_column_of_a_new_line()
        {
            string textThatIsInTheFileButNotAnEntryName = "CONNECT_DATA";

            StringAssert.Contains(textThatIsInTheFileButNotAnEntryName, AddTnsNameTest.SAMPLE_FILE);

            TnsParser parser     = new TnsParser(AddTnsNameTest.SAMPLE_FILE);
            TnsEntry  foundEntry = parser.FindEntry(textThatIsInTheFileButNotAnEntryName);

            Assert.IsNull(foundEntry);
        }
Example #3
0
        public void FindEntry_should_return_position_of_the_requested_entry_when_it_does_exist()
        {
            string entryName     = "SOUTHWIND.WORLD";
            int    startPosition = AddTnsNameTest.SAMPLE_FILE.IndexOf(entryName);

            Assert.IsTrue(startPosition >= 0, "Entry should exist in sample file.");

            TnsParser parser     = new TnsParser(AddTnsNameTest.SAMPLE_FILE);
            TnsEntry  foundEntry = parser.FindEntry(entryName);

            Assert.AreEqual(startPosition, foundEntry.StartPosition);
        }
Example #4
0
        public void FindEntry_should_return_length_of_the_found_entry_definition()
        {
            string    entryName = "SOUTHWIND.WORLD";
            const int LENGTH_OF_SOUTHWIND_DEFINITION = 189; // this corresponds to the text of SAMPLE_FILE

            int startPosition = AddTnsNameTest.SAMPLE_FILE.IndexOf(entryName);

            Assert.IsTrue(startPosition >= 0, "Entry should exist in sample file.");

            TnsParser parser     = new TnsParser(AddTnsNameTest.SAMPLE_FILE);
            TnsEntry  foundEntry = parser.FindEntry(entryName);

            Assert.AreEqual(LENGTH_OF_SOUTHWIND_DEFINITION, foundEntry.Length);
        }
Example #5
0
    public List <TnsEntry> Parse(string TNSNamesContents)
    {
        string          TNSPattern      = @"([\w -] +)\s *= (?:\s |.) +?\)\s *\)\s *\)\s * ((?=[\w\-])|(?=$))";
        Regex           reTns           = new Regex(TNSPattern, RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace);
        MatchCollection matchCollection = reTns.Matches(TNSNamesContents);
        var             TnsEntries      = new List <TnsEntry>();

        foreach (Match match in matchCollection)
        {
            var    tnsEntry     = new TnsEntry();
            string matchedValue = match.Value.Trim();
            tnsEntry.Name        = Regex.Match(matchedValue, @"^([^\s]+)", RegexOptions.IgnoreCase)?.Value.Trim();
            tnsEntry.Host        = Regex.Match(matchedValue, "(?<=HOST.+=) ([^)]*)", RegexOptions.IgnoreCase)?.Value.Trim();
            tnsEntry.Port        = Regex.Match(matchedValue, "(?<=PORT.+=) ([^)]*)", RegexOptions.IgnoreCase)?.Value.Trim();
            tnsEntry.ServiceName = Regex.Match(matchedValue, "(?<=SERVICE_NAME.+=) ([^)]*)", RegexOptions.IgnoreCase)?.Value;
            TnsEntries.Add(tnsEntry);
        }
        return(TnsEntries);
    }