Пример #1
0
        public void JsonInstanceModelWithWrongPathInput()
        {
            var schemaText = File.ReadAllText("Common/jsd/schema-w-recursion.schema.json");
            var schemaJson = JsonValue.Parse(schemaText);
            var schema     = new JsonSerializer().Deserialize <JsonSchema>(schemaJson);

            // test recursive schema
            JsonSchemaToInstanceModelGenerator converter = new JsonSchemaToInstanceModelGenerator("TestOrg", "edag", schema);
            JsonObject instanceModel = converter.GetInstanceModel();

            Assert.NotNull(instanceModel);
            JsonObject actualElements = instanceModel.TryGetObject("Elements");

            Assert.Equal(6, actualElements.Count);

            // test expand path with wrong path
            string path = "melding.ansatte.foresatt.wronginput";

            try
            {
                JsonObject instanceModelAfterExpand = converter.ExpandPath(path);
            }
            catch (Exception e)
            {
                Assert.Equal("Path does not exist in instance model", e.Message);
            }

            // test expand path which cannot be expanded
            path = "melding.ansatte.navn";
            try
            {
                JsonObject instanceModelAfterExpand = converter.ExpandPath(path);
            }
            catch (Exception e)
            {
                Assert.StartsWith("Path cannot be expanded", e.Message);
            }

            // test expand path of already expanded path
            path = "melding.ansatte";
            try
            {
                JsonObject instanceModelAfterExpand = converter.ExpandPath(path);
            }
            catch (Exception e)
            {
                Assert.StartsWith("Path already expanded", e.Message);
            }
        }
Пример #2
0
        public void JsonInstanceModelOfRecursiveSchema()
        {
            var schemaText = File.ReadAllText("Common/jsd/schema-w-recursion.schema.json");
            var schemaJson = JsonValue.Parse(schemaText);
            var schema     = new JsonSerializer().Deserialize <JsonSchema>(schemaJson);

            // test recursive schema
            JsonSchemaToInstanceModelGenerator converter = new JsonSchemaToInstanceModelGenerator("TestOrg", "edag", schema);
            JsonObject instanceModel = converter.GetInstanceModel();

            Assert.NotNull(instanceModel);
            JsonObject actualElements = instanceModel.TryGetObject("Elements");

            Assert.Equal(6, actualElements.Count);

            // test expand path
            string     path = "melding.ansatte.foresatt";
            JsonObject instanceModelAfterExpand  = converter.ExpandPath(path);
            JsonObject actualElementsAfterExpand = instanceModelAfterExpand.TryGetObject("Elements");
            JsonObject nameElement = actualElementsAfterExpand.TryGetObject(path + ".navn");

            Assert.NotNull(nameElement);
            Assert.Equal(18, actualElementsAfterExpand.Count);

            // test remove path
            JsonObject modelAfterRemovePath      = converter.RemovePath(path);
            JsonObject actualElementsAfterRemove = modelAfterRemovePath.TryGetObject("Elements");
            JsonObject missingNameElement        = actualElementsAfterRemove.TryGetObject(path + ".navn");

            Assert.Null(missingNameElement);
            Assert.Equal(6, actualElementsAfterRemove.Count);

            /* File.WriteAllText("schema-w-recursion-remove-path.instance-model.json", modelAfterRemovePath.ToString());*/
        }