Ejemplo n.º 1
0
        /// <summary>
        /// Create ODataContextUrlInfo from ODataCollectionStartSerializationInfo
        /// </summary>
        /// <param name="info">The ODataCollectionStartSerializationInfo to be used.</param>
        /// <param name="itemTypeReference">ItemTypeReference specifying element type.</param>
        /// <returns>The generated ODataContextUrlInfo.</returns>
        internal static ODataContextUrlInfo Create(ODataCollectionStartSerializationInfo info, IEdmTypeReference itemTypeReference)
        {
            string collectionTypeName = null;

            if (info != null)
            {
                collectionTypeName = info.CollectionTypeName;
            }
            else if (itemTypeReference != null)
            {
                collectionTypeName = EdmLibraryExtensions.GetCollectionTypeName(itemTypeReference.ODataFullName());
            }

            return(new ODataContextUrlInfo()
            {
                TypeName = collectionTypeName,
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create ODataContextUrlInfo from ODataCollectionStartSerializationInfo
        /// </summary>
        /// <param name="info">The ODataCollectionStartSerializationInfo to be used.</param>
        /// <param name="itemTypeReference">ItemTypeReference specifying element type.</param>
        /// <returns>The generated ODataContextUrlInfo.</returns>
        internal static ODataContextUrlInfo Create(ODataCollectionStartSerializationInfo info, IEdmTypeReference itemTypeReference)
        {
            string collectionTypeName = null;
            if (info != null)
            {
                collectionTypeName = info.CollectionTypeName;
            }
            else if (itemTypeReference != null)
            {
                collectionTypeName = EdmLibraryExtensions.GetCollectionTypeName(itemTypeReference.FullName());
            }

            return new ODataContextUrlInfo()
            {
                TypeName = collectionTypeName,
            };
        }
 public void ShouldBeAbleToClearTheCollectionStartSerializationInfo()
 {
     ODataCollectionStart collectionStart = new ODataCollectionStart();
     ODataCollectionStartSerializationInfo serializationInfo = new ODataCollectionStartSerializationInfo { CollectionTypeName = "Collection(Edm.String)" };
     collectionStart.SerializationInfo = serializationInfo;
     collectionStart.SetSerializationInfo(null);
     collectionStart.SerializationInfo.Should().BeNull();
 }
 /// <summary>
 /// Provide additional serialization information to the <see cref="ODataCollectionWriter"/> for <paramref name="collectionStart"/>.
 /// </summary>
 /// <param name="collectionStart">The instance to set the serialization info.</param>
 /// <param name="serializationInfo">The serialization info to set.</param>
 public static void SetSerializationInfo(this ODataCollectionStart collectionStart, ODataCollectionStartSerializationInfo serializationInfo)
 {
     ExceptionUtils.CheckArgumentNotNull(collectionStart, "collectionStart");
     collectionStart.SerializationInfo = serializationInfo;
 }
 public void ShouldBeAbleToSetTheCollectionStartSerializationInfo()
 {
     ODataCollectionStart collectionStart = new ODataCollectionStart();
     ODataCollectionStartSerializationInfo serializationInfo = new ODataCollectionStartSerializationInfo { CollectionTypeName = "Collection(Edm.String)" };
     collectionStart.SetSerializationInfo(serializationInfo);
     collectionStart.SerializationInfo.Should().BeSameAs(serializationInfo);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Writes the collection payload as specified in the <paramref name="testDescriptor"/>.
        /// </summary>
        /// <param name="messageWriter">The message writer.</param>
        /// <param name="writer">The writer to write to.</param>
        /// <param name="flush">True if the stream should be flush before returning; otherwise false.</param>
        /// <param name="testDescriptor">The test descriptor specifying the collection to write.</param>
        internal static void WriteCollectionPayload(ODataMessageWriterTestWrapper messageWriter, ODataCollectionWriter writer, bool flush, CollectionWriterTestDescriptor testDescriptor)
        {
            Debug.Assert(writer != null, "writer != null");
            Debug.Assert(testDescriptor != null, "testDescriptor != null");

            object[] payloadItems = testDescriptor.PayloadItems;
            int payloadItemIndex = 0;
            foreach (CollectionWriterTestDescriptor.WriterInvocations invocation in testDescriptor.Invocations)
            {
                switch (invocation)
                {
                    case CollectionWriterTestDescriptor.WriterInvocations.StartCollection:
                        ODataCollectionStartSerializationInfo serInfo = null;
                        if (!string.IsNullOrEmpty(testDescriptor.CollectionTypeName))
                        {
                            serInfo = new ODataCollectionStartSerializationInfo();
                            serInfo.CollectionTypeName = testDescriptor.CollectionTypeName;
                        }

                        writer.WriteStart(new ODataCollectionStart { Name = testDescriptor.CollectionName, SerializationInfo = serInfo });
                        break;
                    
                    case CollectionWriterTestDescriptor.WriterInvocations.Item:
                        object payloadItem = payloadItems[payloadItemIndex];

                        ODataError error = payloadItem as ODataError;
                        if (error != null)
                        {
                            throw new InvalidOperationException("Expected payload item but found an error.");
                        }

                        writer.WriteItem(payloadItem);
                        payloadItemIndex++;
                        break;
                    
                    case CollectionWriterTestDescriptor.WriterInvocations.Error:
                        ODataAnnotatedError error2 = testDescriptor.PayloadItems[payloadItemIndex] as ODataAnnotatedError;
                        if (error2 == null)
                        {
                            throw new InvalidOperationException("Expected an error but found a payload item.");
                        }

                        messageWriter.WriteError(error2.Error, error2.IncludeDebugInformation);
                        payloadItemIndex++;
                        break;
                    
                    case CollectionWriterTestDescriptor.WriterInvocations.EndCollection:
                        writer.WriteEnd();
                        break;
                    
                    case CollectionWriterTestDescriptor.WriterInvocations.UserException:
                        throw new Exception("User code triggered an exception.");

                    default:
                        break;
                }
            }

            if (flush)
            {
                writer.Flush();
            }
        }
 private Uri CreateCollectionContextUri(ODataCollectionStartSerializationInfo serializationInfo, IEdmTypeReference itemTypeReference)
 {
     ODataContextUrlInfo info = ODataContextUrlInfo.Create(serializationInfo, itemTypeReference);
     Uri contextUrl = this.responseContextUriBuilder.BuildContextUri(ODataPayloadKind.Collection, info);
     contextUrl.Should().NotBeNull();
     return contextUrl;
 }
 public void CollectionSerializationInfoShouldOverrideEdmMetadata()
 {
     var collectionStartSerializationInfo1 = new ODataCollectionStartSerializationInfo { CollectionTypeName = "Collection(Edm.Guid)" };
     this.CreateCollectionContextUri(collectionStartSerializationInfo1, EdmCoreModel.Instance.GetString(isNullable: false)).OriginalString.Should().Be(BuildExpectedContextUri("#Collection(Edm.Guid)"));
 }
 /// <summary>
 /// Provide additional serialization information to the <see cref="ODataCollectionWriter"/> for <paramref name="collectionStart"/>.
 /// </summary>
 /// <param name="collectionStart">The instance to set the serialization info.</param>
 /// <param name="serializationInfo">The serialization info to set.</param>
 public static void SetSerializationInfo(this ODataCollectionStart collectionStart, ODataCollectionStartSerializationInfo serializationInfo)
 {
     ExceptionUtils.CheckArgumentNotNull(collectionStart, "collectionStart");
     collectionStart.SerializationInfo = serializationInfo;
 }
 public void TestInit()
 {
     this.testSubject = new ODataCollectionStartSerializationInfo();
 }