示例#1
0
        private static void WriteNestedItems(ODataItem[] nestedItemsToWrite, ODataAtomWriter writer)
        {
            foreach (ODataItem itemToWrite in nestedItemsToWrite)
            {
                ODataFeed feedToWrite = itemToWrite as ODataFeed;
                if (feedToWrite != null)
                {
                    writer.WriteStart(feedToWrite);
                }
                else
                {
                    ODataEntry entryToWrite = itemToWrite as ODataEntry;
                    if (entryToWrite != null)
                    {
                        writer.WriteStart(entryToWrite);
                    }
                    else
                    {
                        writer.WriteStart((ODataNavigationLink)itemToWrite);
                    }
                }
            }

            for (int count = 0; count < nestedItemsToWrite.Length; count++)
            {
                writer.WriteEnd();
            }
        }
示例#2
0
        private static void ValidateWrittenPayload(MemoryStream stream, ODataAtomWriter writer, string expectedPayload)
        {
            writer.Flush();
            stream.Seek(0, SeekOrigin.Begin);
            string payload = (new StreamReader(stream)).ReadToEnd();

            payload.Should().Be(expectedPayload);
        }
示例#3
0
        private void VerifyTypeCollectionRoundtrip(ODataCollectionValue value, string propertyName, ODataFeedAndEntrySerializationInfo info)
        {
            var properties = new[] { new ODataProperty {
                                         Name = propertyName, Value = value
                                     } };
            var entry = new ODataEntry()
            {
                TypeName = "NS.Student", Properties = properties, SerializationInfo = info
            };
            MemoryStream stream = new MemoryStream();

            using (ODataAtomOutputContext outputContext = new ODataAtomOutputContext(
                       ODataFormat.Atom,
                       new NonDisposingStream(stream),
                       Encoding.UTF8,
                       new ODataMessageWriterSettings()
            {
                Version = ODataVersion.V4
            },
                       /*writingResponse*/ true,
                       /*synchronous*/ true,
                       model,
                       /*urlResolver*/ null))
            {
                outputContext.MessageWriterSettings.SetServiceDocumentUri(ServiceDocumentUri);
                var atomWriter = new ODataAtomWriter(outputContext, /*entitySet*/ null, /*entityType*/ null, /*writingFeed*/ false);
                atomWriter.WriteStart(entry);
                atomWriter.WriteEnd();
            }

            stream.Position = 0;
            object actualValue = null;

            using (ODataAtomInputContext inputContext = new ODataAtomInputContext(
                       ODataFormat.Atom,
                       stream,
                       Encoding.UTF8,
                       new ODataMessageReaderSettings(),
                       /*readingResponse*/ true,
                       /*synchronous*/ true,
                       model,
                       /*urlResolver*/ null))
            {
                var atomReader = new ODataAtomReader(inputContext, /*entitySet*/ null, /*entityType*/ null, /*writingFeed*/ false);
                while (atomReader.Read())
                {
                    if (atomReader.State == ODataReaderState.EntryEnd)
                    {
                        ODataEntry entryOut = atomReader.Item as ODataEntry;
                        actualValue = entryOut.Properties.Single(p => p.Name == propertyName).ODataValue;
                    }
                }
            }

            TestUtils.AssertODataValueAreEqual(actualValue as ODataValue, value);
        }
示例#4
0
        private void WriteResponseWithoutModelAndValidatePayload(ODataItem[] nestedItemToWrite, string expectedPayload, bool setMetadataDocumentUri = true)
        {
            // without model, write response
            var stream        = new MemoryStream();
            var outputContext = CreateAtomOutputContext(stream, null, true, null);
            var writer        = new ODataAtomWriter(outputContext, null, null, nestedItemToWrite[0] is ODataFeed);

            WriteNestedItems(nestedItemToWrite, writer);
            ValidateWrittenPayload(stream, writer, expectedPayload);
        }
示例#5
0
        private void WriteRequestWithModelAndValidatePayload(ODataItem[] nestedItemToWrite, string expectedPayload, bool setMetadataDocumentUri = true)
        {
            // with model, write request
            var stream        = new MemoryStream();
            var outputContext = CreateAtomOutputContext(stream, null, false, this.userModel);
            var writer        = new ODataAtomWriter(outputContext, this.entitySet, this.entityType, nestedItemToWrite[0] is ODataFeed);

            WriteNestedItems(nestedItemToWrite, writer);
            ValidateWrittenPayload(stream, writer, expectedPayload);
        }
示例#6
0
        private void WriteRequestWithoutModelAndValidatePayload(ODataItem[] nestedItemToWrite, string expectedPayload, bool setMetadataDocumentUri = true)
        {
            // without model, write request
            // 1. CreateEntityContainerElementContextUri(): no entitySetName --> no context uri is output.
            // 2. but odata.type will be output because of no model. JsonMinimalMetadataTypeNameOracle.GetEntryTypeNameForWriting method: // We only write entity type names in Json Light if it's more derived (different) from the expected type name.
            var stream        = new MemoryStream();
            var outputContext = CreateAtomOutputContext(stream, null, false, null);
            var writer        = new ODataAtomWriter(outputContext, null, null, nestedItemToWrite[0] is ODataFeed);

            WriteNestedItems(nestedItemToWrite, writer);
            ValidateWrittenPayload(stream, writer, expectedPayload);
        }