Exemplo n.º 1
0
 public static void BasicTestWrongCase(string data)
 {
     // Default is Ordinal comparison. Keys with different case should not be found.
     RowConfigReader rcr = new RowConfigReader(data);
     string unused;
     Assert.False(rcr.TryGetNextValue("stringkey", out unused));
     Assert.False(rcr.TryGetNextValue("intkey", out unused));
 }
Exemplo n.º 2
0
        public static void BasicTestWrongCase(string data)
        {
            // Default is Ordinal comparison. Keys with different case should not be found.
            RowConfigReader rcr = new RowConfigReader(data);
            string          unused;

            Assert.False(rcr.TryGetNextValue("stringkey", out unused));
            Assert.False(rcr.TryGetNextValue("intkey", out unused));
        }
Exemplo n.º 3
0
        public static void MalformedLine(string data)
        {
            RowConfigReader rcr = new RowConfigReader(data);
            string          unused;

            Assert.False(rcr.TryGetNextValue("key", out unused));
        }
        internal static string ParseDnsSuffixFromResolvConfFile(string filePath)
        {
            string data = File.ReadAllText(filePath);
            RowConfigReader rcr = new RowConfigReader(data);
            string dnsSuffix;

            return rcr.TryGetNextValue("search", out dnsSuffix) ? dnsSuffix : string.Empty;
        }
Exemplo n.º 5
0
        public static void KeyDoesNotStartLine()
        {
            string data = $"key value{Environment.NewLine} key2 value2";
            RowConfigReader rcr = new RowConfigReader(data);

            string unused;
            Assert.False(rcr.TryGetNextValue("key2", out unused));

            // Can retrieve value if key includes the preceding space.
            Assert.Equal("value2", rcr.GetNextValue(" key2"));
        }
Exemplo n.º 6
0
        public static void KeyDoesNotStartLine()
        {
            string          data = $"key value{Environment.NewLine} key2 value2";
            RowConfigReader rcr  = new RowConfigReader(data);

            string unused;

            Assert.False(rcr.TryGetNextValue("key2", out unused));

            // Can retrieve value if key includes the preceding space.
            Assert.Equal("value2", rcr.GetNextValue(" key2"));
        }
Exemplo n.º 7
0
        public static void NewlineTests(string data)
        {
            // Test strings which have newlines mixed in between data pairs.

            RowConfigReader rcr = new RowConfigReader(data);

            Assert.Equal("00", rcr.GetNextValue("value0"));
            Assert.Equal(0, rcr.GetNextValueAsInt32("value0"));
            Assert.Equal(1, rcr.GetNextValueAsInt32("value1"));
            Assert.Equal("2", rcr.GetNextValue("value2"));
            Assert.Equal("3", rcr.GetNextValue("value3"));

            string unused;

            Assert.False(rcr.TryGetNextValue("Any", out unused));
        }
        internal static List<IPAddress> ParseDnsAddressesFromResolvConfFile(string filePath)
        {
            // Parse /etc/resolv.conf for all of the "nameserver" entries.
            // These are the DNS servers the machine is configured to use.
            // On OSX, this file is not directly used by most processes for DNS
            // queries/routing, but it is automatically generated instead, with
            // the machine's DNS servers listed in it.
            string data = File.ReadAllText(filePath);
            RowConfigReader rcr = new RowConfigReader(data);
            List<IPAddress> addresses = new List<IPAddress>();

            string addressString = null;
            while (rcr.TryGetNextValue("nameserver", out addressString))
            {
                IPAddress parsedAddress;
                if (IPAddress.TryParse(addressString, out parsedAddress))
                {
                    addresses.Add(parsedAddress);
                }
            }

            return addresses;
        }
Exemplo n.º 9
0
        private static IPAddressCollection GetDnsAddresses()
        {
            // Parse /etc/resolv.conf for all of the "nameserver" entries.
            // These are the DNS servers the machine is configured to use.
            // On OSX, this file is not directly used by most processes for DNS
            // queries/routing, but it is automatically generated instead, with
            // the machine's DNS servers listed in it.
            string data = File.ReadAllText(NetworkFiles.EtcResolvConfFile);
            RowConfigReader rcr = new RowConfigReader(data);
            InternalIPAddressCollection addresses = new InternalIPAddressCollection();

            string addressString = null;
            while (rcr.TryGetNextValue("nameserver", out addressString))
            {
                IPAddress parsedAddress;
                if (IPAddress.TryParse(addressString, out parsedAddress))
                {
                    addresses.InternalAdd(parsedAddress);
                }
            }

            return addresses;
        }
Exemplo n.º 10
0
        private static string GetDnsSuffix()
        {
            string data = File.ReadAllText(NetworkFiles.EtcResolvConfFile);
            RowConfigReader rcr = new RowConfigReader(data);
            string dnsSuffix;

            return rcr.TryGetNextValue("search", out dnsSuffix) ? dnsSuffix : string.Empty;
        }
Exemplo n.º 11
0
        public static void NewlineTests(string data)
        {
            // Test strings which have newlines mixed in between data pairs.

            RowConfigReader rcr = new RowConfigReader(data);
            Assert.Equal("00", rcr.GetNextValue("value0"));
            Assert.Equal(0, rcr.GetNextValueAsInt32("value0"));
            Assert.Equal(1, rcr.GetNextValueAsInt32("value1"));
            Assert.Equal("2", rcr.GetNextValue("value2"));
            Assert.Equal("3", rcr.GetNextValue("value3"));

            string unused;
            Assert.False(rcr.TryGetNextValue("Any", out unused));
        }
Exemplo n.º 12
0
 public static void MalformedLine(string data)
 {
     RowConfigReader rcr = new RowConfigReader(data);
     string unused;
     Assert.False(rcr.TryGetNextValue("key", out unused));
 }