public void Can_Serialize_NestedJsonValueDto()
        {
            var scaffold = new List <JsonValue> {
                new JsonValue(text.ToJson()), new JsonValue(text.ToJson())
            };

            var container = new NestedJsonValueDto
            {
                ElementId   = "container_1",
                ElementType = "container",
                // Raw nesting - won't be escaped
                Content = new ElementContentDto {
                    ElementId = "container_1", Content = "container goes here"
                },
                Action = new ElementActionDto {
                    ElementId = "container_1", Action = "action goes here"
                },
                Scaffolding = scaffold
            };

            var json = container.ToJson();

            var fromJson = json.FromJson <NestedJsonValueDto>();

            foreach (var jsonValue in fromJson.Scaffolding)
            {
                var fromJsonValue = jsonValue.As <TextElementDto>();
                Assert.That(fromJsonValue.ElementId, Is.EqualTo(text.ElementId));
                Assert.That(fromJsonValue.Action.ElementId, Is.EqualTo(text.Action.ElementId));
                Assert.That(fromJsonValue.Content.ElementId, Is.EqualTo(text.Content.ElementId));
            }
        }
Ejemplo n.º 2
0
        public void Can_Serialize_NestedJsonValueDto()
        {
            var scaffold = new List<JsonValue> { new JsonValue(text.ToJson()), new JsonValue(text.ToJson()) };

            var container = new NestedJsonValueDto
            {
                ElementId = "container_1",
                ElementType = "container",
                // Raw nesting - won't be escaped
                Content = new ElementContentDto { ElementId = "container_1", Content = "container goes here" },
                Action = new ElementActionDto { ElementId = "container_1", Action = "action goes here" },
                Scaffolding = scaffold
            };

            var json = container.ToJson();

            var fromJson = json.FromJson<NestedJsonValueDto>();

            foreach (var jsonValue in fromJson.Scaffolding)
            {
                var fromJsonValue = jsonValue.As<TextElementDto>();
                Assert.That(fromJsonValue.ElementId, Is.EqualTo(text.ElementId));
                Assert.That(fromJsonValue.Action.ElementId, Is.EqualTo(text.Action.ElementId));
                Assert.That(fromJsonValue.Content.ElementId, Is.EqualTo(text.Content.ElementId));
            }
        }