Exemplo n.º 1
0
        public void TestPropertiesCase()
        {
            JsonDictionary dict = new JsonDictionary();
            string name = "TestName";
            dict.Add("location", "path");
            dict.Add("required", true);
            dict.Add("description", "A string description");
            dict.Add("default", "A default value");
            dict.Add("type", "string");
            dict.Add("repeated", true);
            dict.Add("enum", new List<string> { "atom", "json" });
            dict.Add("enumDescriptions", new List<string> { "atom are small particals", "json is my friend" });
            dict.Add("minimum", "43");
            dict.Add("maximum", "53");
            dict.Add("pattern", "[1-9][0-9]*");
            var impl = new ParameterFactory.BaseParameter(new KeyValuePair<string, object>(name, dict));

            Assert.AreEqual("TestName", impl.Name);
            Assert.AreEqual("path", impl.ParameterType);
            Assert.AreEqual("A string description", impl.Description);
            Assert.AreEqual("string", impl.ValueType);
            Assert.AreEqual(true, impl.IsRequired);
            Assert.AreEqual(true, impl.IsRepeatable);
            Assert.AreEqual("A default value", impl.DefaultValue);
            MoreAsserts.ContentsEqualAndInOrder(new List<string> { "atom", "json" }, impl.EnumValues);
            MoreAsserts.ContentsEqualAndInOrder(
                new List<string> { "atom are small particals", "json is my friend" }, impl.EnumValueDescriptions);
            Assert.AreEqual("53", impl.Maximum);
            Assert.AreEqual("43", impl.Minimum);
            Assert.AreEqual("[1-9][0-9]*", impl.Pattern);
        }
Exemplo n.º 2
0
        public void ValidateRegexTest()
        {
            IMethod m = new MockMethod();
            var dict = new JsonDictionary { { "name", "test" }, { "pattern", ".+" } };

            var jsonObj = new KeyValuePair<string, object>("test", dict);

            var p = new ParameterFactory.BaseParameter(jsonObj);
            var inputData = new ParameterCollection();
            var validator = new MethodValidator(m, inputData);
            Assert.IsTrue(validator.ValidateRegex(p, "Test"));
        }
Exemplo n.º 3
0
        public void ValidateEnumNullTest()
        {
            IMethod m = new MockMethod();
            var dict = new JsonDictionary { { "name", "test" } };

            // Create the parameter.
            var jsonObj = new KeyValuePair<string, object>("test", dict);
            var p = new ParameterFactory.BaseParameter(jsonObj);
            var inputData = new ParameterCollection();
            var validator = new MethodValidator(m, inputData);

            // Confirm that the method validates enumerations correctly.
            Assert.IsTrue(validator.ValidateEnum(p, "one"));
            Assert.IsTrue(validator.ValidateEnum(p, "two"));
            Assert.IsTrue(validator.ValidateEnum(p, "three"));
            Assert.IsTrue(validator.ValidateEnum(p, "One"));
            Assert.IsTrue(validator.ValidateEnum(p, ""));
        }
Exemplo n.º 4
0
        public void GetParameterNameTest()
        {
            var paramArgs = new KeyValuePair<string, object>("safeName", new JsonDictionary());
            IParameter param = new ParameterFactory.BaseParameter(paramArgs);
            Assert.AreEqual("safeName", GeneratorUtils.GetParameterName(param, Enumerable.Empty<string>()));

            paramArgs = new KeyValuePair<string, object>("string", new JsonDictionary());
            param = new ParameterFactory.BaseParameter(paramArgs);
            Assert.AreEqual("stringValue", GeneratorUtils.GetParameterName(param, Enumerable.Empty<string>()));

            paramArgs = new KeyValuePair<string, object>("String", new JsonDictionary());
            param = new ParameterFactory.BaseParameter(paramArgs);
            Assert.AreEqual("stringValue", GeneratorUtils.GetParameterName(param, Enumerable.Empty<string>()));

            paramArgs = new KeyValuePair<string, object>("SafeName", new JsonDictionary());
            param = new ParameterFactory.BaseParameter(paramArgs);
            Assert.AreEqual("safeName", GeneratorUtils.GetParameterName(param, Enumerable.Empty<string>()));
        }