public void TestParseBoolean1() { BooleanParser parser = new BooleanParser(); bool actual = parser.ParseBoolean("true"); bool expected = true; Assert.AreEqual(expected, actual); }
private static void RunBooleanParserDemo() { // Use the default boolean parser BooleanParser parser = new BooleanParser(); bool result = parser.ParseBoolean("truE"); // converts to true bool result2 = parser.ParseBoolean("FAlse"); // converts to false // Alternatively, we can set custom strings for conversion of boolean values Dictionary<string, bool> mapping = new Dictionary<string, bool> { { "Yes", true }, { "No", false }, { "Y", true }, { "N", false } }; BooleanParser parser2 = new BooleanParser(mapping); bool result3 = parser2.ParseBoolean("true"); // converts to true bool result4 = parser2.ParseBoolean("Yes"); // converts to true bool result5 = parser2.ParseBoolean("N"); // converts to false }
public void TestParseBoolean2() { Dictionary<string, bool> mapping = new Dictionary<string, bool> { { "Yes", true }, { "No", false }, { "Y", true }, { "N", false } }; BooleanParser parser = new BooleanParser(mapping); bool actual = parser.ParseBoolean("No"); bool expected = false; Assert.AreEqual(expected, actual); }