예제 #1
0
        public void Online(JsonSchema schema)
        {
            try
            {
                var localSchemaJson = schema.ToJson(_serializer);

                var onlineSchemaText = JsonSchemaOptions.Download(schema.Id);
                var onlineSchemaJson = JsonValue.Parse(onlineSchemaText);
                var onlineSchema     = new JsonSchema();
                onlineSchema.FromJson(onlineSchemaJson, _serializer);

                var localValidation  = schema.Validate(onlineSchemaJson);
                var onlineValidation = onlineSchema.Validate(localSchemaJson);

                Assert.AreEqual(onlineSchema, schema);

                onlineValidation.AssertValid();
                localValidation.AssertValid();

                Assert.AreEqual(onlineSchemaJson, localSchemaJson);
            }
            catch (WebException)
            {
                Assert.Inconclusive();
            }
            catch (AggregateException e)
            {
                if (e.InnerExceptions.OfType <WebException>().Any())
                {
                    Assert.Inconclusive();
                }
                throw;
            }
        }
예제 #2
0
        public void Online(IJsonSchema schema)
        {
            try
            {
                // TODO: Catch web exceptions and assert inconclusive.
                var localSchemaJson = schema.ToJson(null);

                var onlineSchemaText = JsonSchemaOptions.Download(schema.Id);
                var onlineSchemaJson = JsonValue.Parse(onlineSchemaText);
                var onlineSchema     = JsonSchemaFactory.FromJson(onlineSchemaJson);

                var localValidation  = schema.Validate(onlineSchemaJson);
                var onlineValidation = onlineSchema.Validate(localSchemaJson);

                Assert.AreEqual(onlineSchema, schema);

                onlineValidation.AssertValid();
                localValidation.AssertValid();

                Assert.AreEqual(onlineSchemaJson, localSchemaJson);
            }
            catch (WebException)
            {
                Assert.Inconclusive();
            }
            catch (AggregateException e)
            {
                if (e.InnerExceptions.OfType <WebException>().Any())
                {
                    Assert.Inconclusive();
                }
                throw;
            }
        }
예제 #3
0
        public void Online(string testName, JsonSchema schema)
        {
            try
            {
                var localSchemaJson = schema.ToJson(_serializer);

                var onlineSchemaText = JsonSchemaOptions.Download(schema.Id);
                var onlineSchemaJson = JsonValue.Parse(onlineSchemaText);
                var onlineSchema     = new JsonSchema();
                onlineSchema.FromJson(onlineSchemaJson, _serializer);

                var localValidation  = schema.Validate(onlineSchemaJson);
                var onlineValidation = onlineSchema.Validate(localSchemaJson);

                try
                {
                    Console.WriteLine("Asserting schema equality");
                    Assert.AreEqual(onlineSchema, schema);

                    Console.WriteLine("Validating local against online");
                    onlineValidation.AssertValid();
                    Console.WriteLine("Validating online against local");
                    localValidation.AssertValid();

                    Console.WriteLine("Asserting json equality");
                    Assert.AreEqual(onlineSchemaJson, localSchemaJson);
                }
                catch (Exception)
                {
                    Console.WriteLine("Online {0}", onlineSchemaJson);
                    Console.WriteLine("Local {0}", localSchemaJson);
                    throw;
                }
            }
            catch (WebException)
            {
                Assert.Inconclusive();
            }
            catch (HttpRequestException)
            {
                Assert.Inconclusive();
            }
            catch (SocketException)
            {
                Assert.Inconclusive();
            }
            catch (AggregateException e)
            {
                if (e.InnerExceptions.OfType <WebException>().Any() || e.InnerExceptions.OfType <HttpRequestException>().Any())
                {
                    Assert.Inconclusive();
                }
                throw;
            }
        }