예제 #1
0
        public JsonLightInstanceAnnotationWriterTests()
        {
            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
            var stream = new MemoryStream();

            this.valueWriter = new MockJsonLightValueSerializer(CreateJsonLightOutputContext(stream, model, this.jsonWriter));
            this.jsonLightInstanceAnnotationWriter = new JsonLightInstanceAnnotationWriter(this.valueWriter, new JsonMinimalMetadataTypeNameOracle());
        }
예제 #2
0
        public void TestWriteInstanceAnnotationsForError()
        {
            var stream             = new MemoryStream();
            var defaultValueWriter = new MockJsonLightValueSerializer(CreateJsonLightOutputContext(stream, model, this.jsonWriter, 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);
            Assert.Equal(4, verifierCalls);
        }
        public void ShouldWriteAnyAnnotationByDefaultWithIgnoreFilterSetToTrue()
        {
            var stream             = new MemoryStream();
            var defaultValueWriter = new MockJsonLightValueSerializer(CreateJsonLightOutputContext(stream, model, this.jsonWriter, 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.WriteInstanceAnnotations(annotations, new InstanceAnnotationWriteTracker(), true);
            verifierCalls.Should().Be(4);
        }