Exemple #1
0
        public void TestSerializationConsistency()
        {
            var config = new UsernameAuthenticatedServerConfiguration();

            config.Username = "******";
            config.Password = "******";

            var newConfig = new UsernameAuthenticatedServerConfiguration();

            newConfig.DeserializeJSON(config.SerializeJSON());

            Assert.AreEqual(config.Username, newConfig.Username);
            Assert.AreEqual(config.Password, newConfig.Password);
        }
Exemple #2
0
        public void TestSchemaValidation()
        {
            var config = new UsernameAuthenticatedServerConfiguration();

            config.Host     = "192.168.5.1";
            config.Port     = 32755;
            config.SSL      = true;
            config.TLS      = true;
            config.Username = "******";
            config.Password = "******";

            var json = config.SerializeJSON();

            var    resolver = new JsonSchemaResolver();
            string textSchema;

            using (var client = new WebClient())
            {
                textSchema = client.DownloadString("https://cdn.rawgit.com/xcitestudios/json-schemas/cdn-tag-3/com/xcitestudios/schemas/Network/Server/Configuration/UsernameAuthenticatedServerConfiguration.json");
            }

            var schema = JSchema.Parse(textSchema, new JSchemaReaderSettings {
                Resolver = new JSchemaUrlResolver(),
                BaseUri  = new Uri("https://cdn.rawgit.com/xcitestudios/json-schemas/cdn-tag-3/com/xcitestudios/schemas/Network/Server/Configuration/")
            });

            var jsonObject = JObject.Parse(json);

            IList <string> errorMessages = new List <string>();
            var            isValid       = jsonObject.IsValid(schema, out errorMessages);

            string errorMessage = "";

            if (!isValid)
            {
                for (var i = 0; i < errorMessages.Count; i++)
                {
                    errorMessage += errorMessages[i] + "\n";
                }
            }

            Assert.IsTrue(isValid, errorMessage);
        }