public void Initialize() { this.jsonWriter = new MockJsonWriter { WriteNameVerifier = name => { }, WriteValueVerifier = str => { } }; this.referencedModel = new EdmModel(); model = TestUtils.WrapReferencedModelsToMainModel(referencedModel); // Version will be V3+ in production since it's JSON Light only this.valueWriter = new MockJsonLightValueSerializer(jsonWriter, model) { Settings = new ODataMessageWriterSettings { Version = ODataVersion.V4, ShouldIncludeAnnotation = ODataUtils.CreateAnnotationFilter("*") } }; this.jsonLightInstanceAnnotationWriter = new JsonLightInstanceAnnotationWriter(this.valueWriter, new JsonMinimalMetadataTypeNameOracle()); }
public void TestWriteInstanceAnnotationsForError() { var defaultValueWriter = new MockJsonLightValueSerializer(jsonWriter, model) { Settings = new ODataMessageWriterSettings { Version = ODataVersion.V4 } }; var defaultAnnotationWriter = new JsonLightInstanceAnnotationWriter(defaultValueWriter, new JsonMinimalMetadataTypeNameOracle()); var annotations = new Collection<ODataInstanceAnnotation>(); annotations.Add(new ODataInstanceAnnotation("term.one", new ODataPrimitiveValue(123))); annotations.Add(new ODataInstanceAnnotation("term.two", new ODataPrimitiveValue("456"))); var verifierCalls = 0; this.jsonWriter.WriteNameVerifier = (name) => verifierCalls++; defaultValueWriter.WritePrimitiveVerifier = (value, reference) => verifierCalls++; defaultAnnotationWriter.WriteInstanceAnnotationsForError(annotations); verifierCalls.Should().Be(4); }
private static string WriteInstanceAnnotation(ODataInstanceAnnotation instanceAnnotation, IEdmModel model) { var stringWriter = new StringWriter(); var outputContext = new ODataJsonLightOutputContext( ODataFormat.Json, stringWriter, new ODataMessageWriterSettings { Version = ODataVersion.V4, ShouldIncludeAnnotation = ODataUtils.CreateAnnotationFilter("*") }, model); var valueSerializer = new ODataJsonLightValueSerializer(outputContext); // The JSON Writer will complain if there is no active scope, so start an object scope. valueSerializer.JsonWriter.StartObjectScope(); var instanceAnnotationWriter = new JsonLightInstanceAnnotationWriter(valueSerializer, new JsonMinimalMetadataTypeNameOracle()); // The method under test. instanceAnnotationWriter.WriteInstanceAnnotation(instanceAnnotation); valueSerializer.JsonWriter.EndObjectScope(); return stringWriter.ToString(); }