public void DefaultIndex()
            {
                ApplicationDataPath path = new ApplicationDataPath("Foo[1].Bar");

                Assert.AreEqual(2, path.Count);
                Assert.AreEqual("Bar", path.Last().Name);
                Assert.IsNull(path.Last().Index);
            }
            public void MatchesOriginal()
            {
                ApplicationDataPath original = new ApplicationDataPath();
                original.Prepend("Bar", 42);
                original.Prepend("Foo", 10);

                ApplicationDataPath copy = new ApplicationDataPath(original);

                Assert.AreEqual(original.Count, copy.Count);
                Assert.AreEqual(original.Last().Name, copy.Last().Name);
                Assert.AreEqual(original.Last().Index, copy.Last().Index);
            }
 public void AppendsToEnd()
 {
     ApplicationDataPath path = new ApplicationDataPath();
     path.Append("Foo", 42);
     path.Append("Bar", 16);
     Assert.AreEqual(16, path.Last().Index);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Implements the validation logic for the receiver.
        /// </summary>
        /// <param name="objectToValidate">The object to validate.</param>
        /// <param name="currentTarget">The object on the behalf of which the validation is performed.</param>
        /// <param name="key">The key that identifies the source of objectToValidate.</param>
        /// <param name="validationResults">The validation results to which the outcome of the validation should be stored.</param>
        public override void DoValidate(object objectToValidate, object currentTarget, string key, ValidationResults validationResults)
        {
            if (objectToValidate == null)
            {
                return;
            }

            object[] arr = (object[])objectToValidate;
            Dictionary<string, object>[] items = arr.Length > 0 ? objectToValidate as Dictionary<string, object>[] : new Dictionary<string, object>[0];
            for (int i = 0; i < items.Length; i++)
            {
                Dictionary<string, object> item = items[i];
                ApplicationDataPath path = new ApplicationDataPath(key);
                path.Last().Index = i;
                this.WrappedValidator.DoValidate(item, currentTarget, path.ToString(), validationResults);
            }
        }
 public void PrependsToStart()
 {
     ApplicationDataPath path = new ApplicationDataPath();
     path.Prepend("Foo", 42);
     path.Prepend("Bar", 16);
     Assert.AreEqual(42, path.Last().Index);
 }
            public void TwoLevels()
            {
                ApplicationDataPath path = new ApplicationDataPath("Foo[1].Bar[3]");

                Assert.AreEqual(2, path.Count);
                Assert.AreEqual("Bar", path.Last().Name);
                Assert.AreEqual(3, path.Last().Index);
            }
            public void OneLevelIntegerAsName()
            {
                ApplicationDataPath path = new ApplicationDataPath("10");

                Assert.AreEqual(1, path.Count);
                Assert.AreEqual("10", path.Last().Name);
                Assert.IsNull(path.Last().Index);
            }