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 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 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 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");
        }