Exemple #1
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 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);
        }