public void AvailableValues_Number_InDictionary() { var scheme = Load(@" <PListScheme> <Key name = ""keyname"" type = ""Dictionary""> <Value name = ""num"" type = ""Number"" required = ""True""> <Value name = ""1"" /> <Value name = ""2"" /> <Value name = ""3"" /> </Value> </Key> </PListScheme>"); var value = new PDictionary(); var num = new PNumber(1); var root = new PDictionary(); root.Add("keyname", value); value.Add("num", num); var available = PListScheme.AvailableValues(num, PListScheme.Match(root, scheme)); Assert.AreEqual(3, available.Count, "#1"); }
public void WalkScheme_Dictionary_NotPartOfScheme() { var scheme = Load(@" <PListScheme> <Key name = ""key1"" type = ""Array"" arrayType = ""Dictionary"" /> </PListScheme>"); var dict = new PDictionary(); dict.Add("foo", new PNumber(1)); var tree = new PArray(); tree.Add(dict); tree.Add(new PNumber(1)); var root = new PDictionary(); root.Add("foo", tree); var result = PListScheme.Match(root, scheme); var keys = result.Keys.ToArray(); for (int i = 0; i < keys.Length; i++) { Assert.IsNull(result [keys [i]], "#1." + i); } }
public void WalkScheme_PDictionaryKey_RequiredValues() { var scheme = Load(@" <PListScheme> <Key name = ""key1"" type = ""Dictionary""> <Value name = ""val1"" type = ""Number"" required = ""True"" /> <Value name = ""val2"" type = ""Array"" arrayType = ""Number"" required = ""True"" /> </Key> </PListScheme>"); var key = scheme.Keys [0]; var root = new PDictionary(); var tree = (PDictionary)key.Create(); root.Add("key1", tree); var result = PListScheme.Match(root, scheme); Assert.AreEqual(4, result.Count); Assert.AreSame(result [tree], key, "#2"); var val1 = tree ["val1"]; Assert.AreSame(result [val1], key.Values [0], "#3"); var val2 = tree ["val2"]; Assert.AreSame(result [val2], key.Values [1], "#4"); IsInstanceOf <PNumber> (((PArray)val2) [0], "#5"); }
public PListScheme PListSchemeTest() { string value = "<xml></xml>"; using (var reader = System.Xml.XmlReader.Create(new StringReader(value))) return(PListScheme.Load(reader)); /*41eb3a30-3b19-4ea5-a7dc-e4c76871f391*/ }
public static PListScheme Load(System.Xml.XmlReader reader) { /*c9b18785-1348-42e3-a479-9cac1e7c5360*/ var result = new PListScheme(); var doc = new System.Xml.XmlDocument(); doc.Load(reader); return(result); }
public void AvailableKeys_Array_NotInScheme() { var root = new PDictionary(); root.Add("foo", new PArray()); var available = PListScheme.AvailableKeys(root["foo"], PListScheme.Match(root, PListScheme.Empty)); Assert.IsNull(available, "#1"); }
public void AvailableValues_String_NotInScheme() { var root = new PDictionary(); root.Add("foo", new PString("bar")); var available = PListScheme.AvailableValues(root["foo"], PListScheme.Match(root, PListScheme.Empty)); Assert.IsNull(available, "#1"); }
public void AvailableValues_Boolean_NotInScheme() { var value = new PBoolean(true); var root = new PDictionary(); root.Add("foo", value); var available = PListScheme.AvailableValues(value, PListScheme.Match(root, PListScheme.Empty)); Assert.AreEqual(2, available.Count, "#1"); }
public void AvailableValues_Boolean_InArray() { var scheme = Load(@" <PListScheme> <Key name = ""keyname"" type = ""Array"" arrayType = ""Boolean"" /> </PListScheme>"); var value = new PBoolean(true); var root = new PDictionary(); root.Add(scheme.Keys[0].Identifier, value); var available = PListScheme.AvailableValues(value, PListScheme.Match(root, scheme)); Assert.AreEqual(2, available.Count, "#1"); }
public void AvailableValues_Number_InArray() { var scheme = Load(@" <PListScheme> <Key name = ""keyname"" type = ""Array"" arrayType = ""Number"" > <Value name = ""1"" /> <Value name = ""2"" /> <Value name = ""3"" /> </Key> </PListScheme>"); var array = new PArray(); var key = scheme.GetKey("keyname"); var root = new PDictionary(); root.Add(key.Identifier, array); // The array cannot have a different value (it's a container!) var available = PListScheme.AvailableValues(array, PListScheme.Match(root, scheme)); Assert.IsNull(available, "#1"); // The only element in the array can be of value '1', '2' or '3' array.Add(new PNumber(1)); available = PListScheme.AvailableValues(array [0], PListScheme.Match(root, scheme)); Assert.AreEqual(3, available.Count, "#2"); // Now the first element can be either a '1' or a '3' array.Add(new PNumber(2)); available = PListScheme.AvailableValues(array [0], PListScheme.Match(root, scheme)); Assert.AreEqual(2, available.Count, "#3"); Assert.IsTrue(available.Any(f => f.Identifier == "1"), "#4"); Assert.IsTrue(available.Any(f => f.Identifier == "3"), "#5"); // The second element can be a '2' or a '3' available = PListScheme.AvailableValues(array [1], PListScheme.Match(root, scheme)); Assert.AreEqual(2, available.Count, "#6"); Assert.IsTrue(available.Any(f => f.Identifier == "2"), "#7"); Assert.IsTrue(available.Any(f => f.Identifier == "3"), "#8"); // Now it can only be '1' array.Add(new PNumber(3)); available = PListScheme.AvailableValues(array [0], PListScheme.Match(root, scheme)); Assert.AreEqual(1, available.Count, "#9"); Assert.IsTrue(available.Any(f => f.Identifier == "1"), "#10"); }
public void AvailableKeys_Dictionary() { var scheme = Load(@" <PListScheme> <Key name = ""keyname"" type = ""Dictionary"" /> </PListScheme>"); var value = new PDictionary(); var root = new PDictionary(); root.Add("keyname", value); var available = PListScheme.AvailableKeys(value, PListScheme.Match(root, scheme)); Assert.AreEqual(1, available.Count, "#1"); Assert.AreEqual(PString.Type, available [0].Type, "#2"); }
public void AvailableValues_Number_NoValues() { var scheme = Load(@" <PListScheme> <Key name = ""keyname"" type = ""Number"" /> </PListScheme>"); var root = new PDictionary(); var key = scheme.GetKey("keyname"); root.Add(key.Identifier, key.Create()); var tree = PListScheme.Match(root, scheme); var available = PListScheme.AvailableValues(tree.First().Key, tree); Assert.IsNull(available); }
public void AvailableValues_Boolean_InDictionary() { var scheme = Load(@" <PListScheme> <Key name = ""keyname"" type = ""Dictionary""> <Value name = ""key1"" type = ""Boolean"" required = ""True"" /> </Key> </PListScheme>"); var root = new PDictionary(); var key = scheme.GetKey("keyname"); root.Add(key.Identifier, key.Create()); var tree = PListScheme.Match(root, scheme); var key1 = ((PDictionary)root ["keyname"]) ["key1"]; var available = PListScheme.AvailableValues(key1, tree); Assert.AreEqual(2, available.Count, "#1"); }
public void AvailableValues_Boolean() { var scheme = Load(@" <PListScheme> <Key name = ""keyname"" type = ""Boolean"" /> </PListScheme>"); var root = new PDictionary(); var key = scheme.GetKey("keyname"); root.Add(key.Identifier, key.Create()); var tree = PListScheme.Match(root, scheme); var available = PListScheme.AvailableValues(tree.First().Key, tree); Assert.AreEqual(2, available.Count, "#1"); Assert.AreEqual("Yes", available [0].Identifier, "#1"); Assert.AreEqual("Yes", available [0].Description, "#2"); Assert.AreEqual("No", available [1].Identifier, "#3"); Assert.AreEqual("No", available [1].Description, "#4"); }
public void WalkScheme_PNumberKey_WithValues() { var scheme = Load(@" <PListScheme> <Key name = ""key1"" type = ""Number""> <Value name = ""0"" /> <Value name = ""1"" /> <Value name = ""2"" /> </Key> </PListScheme>"); var key = scheme.Keys [0]; var root = new PDictionary(); var tree = key.Create(); root.Add("key1", tree); var result = PListScheme.Match(root, scheme); Assert.AreEqual(1, result.Count); Assert.AreSame(result [tree], key, "#2"); }
public void AvailableKeys_NumberArray() { var scheme = Load(@" <PListScheme> <Key name = ""keyname"" type = ""Array"" arrayType = ""Number"" > <Value name = ""1"" /> <Value name = ""2"" /> <Value name = ""3"" /> </Key> </PListScheme>"); var key = scheme.GetKey("keyname"); var value = new PArray(); var root = new PDictionary(); root.Add(key.Identifier, value); var available = PListScheme.AvailableKeys(value, PListScheme.Match(root, scheme)); Assert.AreEqual(3, available.Count, "#1"); // We can create '2' or '3', but not '1' value.Add(new PNumber(1)); available = PListScheme.AvailableKeys(value, PListScheme.Match(root, scheme)); Assert.AreEqual(2, available.Count, "#2"); Assert.IsFalse(available.Any(v => v.Identifier == "1"), "#3"); // We can only create '3' value.Add(new PNumber(2)); available = PListScheme.AvailableKeys(value, PListScheme.Match(root, scheme)); Assert.AreEqual(1, available.Count, "#4"); Assert.IsTrue(available.Any(v => v.Identifier == "3"), "#5"); value.Add(new PNumber(3)); available = PListScheme.AvailableKeys(value, PListScheme.Match(root, scheme)); Assert.AreEqual(0, available.Count, "#4"); }
public void WalkScheme_Array_NotPartOfScheme() { var scheme = Load(@" <PListScheme> <Key name = ""key1"" type = ""Array"" arrayType = ""Dictionary"" /> </PListScheme>"); var tree = new PArray(); tree.Add(new PNumber(0)); tree.Add(new PNumber(1)); var root = new PDictionary(); root.Add("foo", tree); var result = PListScheme.Match(root, scheme); Assert.AreEqual(3, result.Count, "#1"); Assert.IsNull(result [tree], "#2"); Assert.IsNull(result [tree [0]], "#3"); Assert.IsNull(result [tree [1]], "#4"); }
public void AvailableValues_Number_WithValues() { var scheme = Load(@" <PListScheme> <Key name = ""keyname"" type = ""Number""> <Value name = ""1"" /> <Value name = ""2"" /> <Value name = ""3"" /> </Key> </PListScheme>"); var key = scheme.GetKey("keyname"); var value = (PNumber)key.Create(); var root = new PDictionary(); root.Add(key.Identifier, value); var tree = PListScheme.Match(root, scheme); var available = PListScheme.AvailableValues(value, tree); Assert.AreEqual(3, available.Count, "#1"); Assert.AreEqual(1, value.Value, "#2"); }
PListScheme Load(string value) { using (var reader = XmlReader.Create(new StringReader(value))) return(PListScheme.Load(reader)); }
public static PListScheme Load (System.Xml.XmlReader reader) { /*c9b18785-1348-42e3-a479-9cac1e7c5360*/ var result = new PListScheme (); var doc = new System.Xml.XmlDocument (); doc.Load (reader); return result; }