public void TryGetKey_preconditions() { var data = new IniDataParser().Parse(""); var separator = data.SectionKeySeparator; string result; // ensure that various good keys aren't rejected var goodKey = ""; Assert.DoesNotThrow(() => data.TryGetKey(goodKey, out result)); goodKey = "key"; Assert.DoesNotThrow(() => data.TryGetKey(goodKey, out result)); goodKey = string.Format("section{0}key", separator); Assert.DoesNotThrow(() => data.TryGetKey(goodKey, out result)); // should be rejected var badKey = string.Format("section{0}subsection{0}key", separator); Assert.Throws <ArgumentException>(() => data.TryGetKey(badKey, out result)); }
public void TryGetKey_data_retrieval() { var input = @" global = 1 [section1] key1 = 2 [section1\subsection] key2 = 3 "; var data = new IniDataParser().Parse(input); var separator = data.SectionKeySeparator; string key; string result; // keys should all be retrieved Assert.IsTrue(data.TryGetKey("global", out result)); Assert.AreEqual(result, "1"); key = string.Format("section1{0}key1", separator); Assert.IsTrue(data.TryGetKey(key, out result)); Assert.AreEqual(result, "2"); key = string.Format(@"section1\subsection{0}key2", separator); Assert.IsTrue(data.TryGetKey(key, out result)); Assert.AreEqual(result, "3"); // invalid keys should fail... Assert.IsFalse(data.TryGetKey(null, out result)); Assert.That(result, Is.Empty); Assert.IsFalse(data.TryGetKey("", out result)); Assert.That(result, Is.Empty); Assert.IsFalse(data.TryGetKey("badglobal", out result)); Assert.That(result, Is.Empty); key = string.Format("badsection{0}badkey", separator); Assert.IsFalse(data.TryGetKey(key, out result)); Assert.That(result, Is.Empty); }