Beispiel #1
0
        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)"));
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        /// <summary>
        /// Validates the <paramref name="serializationInfo"/> instance.
        /// </summary>
        /// <param name="serializationInfo">The serialization info instance to validate.</param>
        /// <returns>The <paramref name="serializationInfo"/> instance.</returns>
        internal static ODataCollectionStartSerializationInfo Validate(ODataCollectionStartSerializationInfo serializationInfo)
        {
            if (serializationInfo != null)
            {
                ExceptionUtils.CheckArgumentNotNull(serializationInfo.CollectionTypeName, "serializationInfo.CollectionTypeName");
            }

            return(serializationInfo);
        }
        /// <summary>
        /// Validates the <paramref name="serializationInfo"/> instance.
        /// </summary>
        /// <param name="serializationInfo">The serialization info instance to validate.</param>
        /// <returns>The <paramref name="serializationInfo"/> instance.</returns>
        internal static ODataCollectionStartSerializationInfo Validate(ODataCollectionStartSerializationInfo serializationInfo)
        {
            if (serializationInfo != null)
            {
                ExceptionUtils.CheckArgumentNotNull(serializationInfo.CollectionTypeName, "serializationInfo.CollectionTypeName");
            }

            return serializationInfo;
        }
        public void ShouldBeAbleToSetTheCollectionStartSerializationInfo()
        {
            ODataCollectionStart collectionStart = new ODataCollectionStart();
            ODataCollectionStartSerializationInfo serializationInfo = new ODataCollectionStartSerializationInfo {
                CollectionTypeName = "Collection(Edm.String)"
            };

            collectionStart.SetSerializationInfo(serializationInfo);
            Assert.Same(serializationInfo, collectionStart.SerializationInfo);
        }
        public void ShouldBeAbleToClearTheCollectionStartSerializationInfo()
        {
            ODataCollectionStart collectionStart = new ODataCollectionStart();
            ODataCollectionStartSerializationInfo serializationInfo = new ODataCollectionStartSerializationInfo {
                CollectionTypeName = "Collection(Edm.String)"
            };

            collectionStart.SerializationInfo = serializationInfo;
            collectionStart.SetSerializationInfo(null);
            Assert.Null(collectionStart.SerializationInfo);
        }
Beispiel #7
0
            /// <summary>
            /// Creates the metadata URI for an operation (function, action, service op) based on its function import.
            /// </summary>
            /// <param name="serializationInfo">Serialization information to generate the metadata uri.</param>
            /// <param name="itemTypeReference">The item type of the collection.</param>
            /// <param name="metadataUri">Returns the metadata URI for an operation (function, action, service op) based on its function import.</param>
            /// <returns>true if we have successfully built the metadata URI; false otherwise.</returns>
            internal override bool TryBuildCollectionMetadataUri(ODataCollectionStartSerializationInfo serializationInfo, IEdmTypeReference itemTypeReference, out Uri metadataUri)
            {
                DebugUtils.CheckNoExternalCallers();
                string collectionTypeName = null;

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

                metadataUri = CreateTypeMetadataUri(this.metadataDocumentUri, collectionTypeName);
                if (this.writingResponse && metadataUri == null)
                {
                    throw new ODataException(OData.Strings.ODataJsonLightMetadataUriBuilder_TypeNameMissingForTopLevelCollectionWhenWritingResponsePayload);
                }

                return(metadataUri != null);
            }
 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;
 }
Beispiel #9
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();
            }
        }
Beispiel #10
0
 public void ValidateNullSerializationInfoShouldReturnNull()
 {
     Assert.Null(ODataCollectionStartSerializationInfo.Validate(null));
 }
 /// <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 ODataCollectionStartSerializationInfoTests()
 {
     this.testSubject = new ODataCollectionStartSerializationInfo();
 }
        public void ValidatingSerializationInfoShouldThrowIfCollectionTypeNameNotSet()
        {
            Action action = () => ODataCollectionStartSerializationInfo.Validate(new ODataCollectionStartSerializationInfo());

            action.ShouldThrow <ArgumentNullException>().Where(e => e.Message.Contains("serializationInfo.CollectionTypeName"));
        }
 public void ValidateNullSerializationInfoShouldReturnNull()
 {
     ODataCollectionStartSerializationInfo.Validate(null).Should().BeNull();
 }
 public ODataCollectionStartSerializationInfoTests()
 {
     this.testSubject = new ODataCollectionStartSerializationInfo();
 }
 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();
 }
        public void ValidatingSerializationInfoShouldThrowIfCollectionTypeNameNotSet()
        {
            Action action = () => ODataCollectionStartSerializationInfo.Validate(new ODataCollectionStartSerializationInfo());

            action.ShouldThrow <ArgumentNullException>().WithMessage("serializationInfo.CollectionTypeName", ComparisonMode.Substring);
        }
Beispiel #18
0
        public void ValidatingSerializationInfoShouldThrowIfCollectionTypeNameNotSet()
        {
            Action action = () => ODataCollectionStartSerializationInfo.Validate(new ODataCollectionStartSerializationInfo());

            Assert.Throws <ArgumentNullException>("serializationInfo.CollectionTypeName", action);
        }
 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)"));
 }
Beispiel #20
0
 /// <summary>
 /// Creates the metadata URI for an operation (function, action, service op) based on its function import.
 /// </summary>
 /// <param name="serializationInfo">Serialization information to generate the metadata uri.</param>
 /// <param name="itemTypeReference">The item type of the collection.</param>
 /// <param name="metadataUri">Returns the metadata URI for an operation (function, action, service op) based on its function import.</param>
 /// <returns>true if we have successfully built the metadata URI; false otherwise.</returns>
 internal abstract bool TryBuildCollectionMetadataUri(ODataCollectionStartSerializationInfo serializationInfo, IEdmTypeReference itemTypeReference, out Uri metadataUri);
Beispiel #21
0
 /// <summary>
 /// Creates the metadata URI for an operation (function, action, service op) based on its function import.
 /// </summary>
 /// <param name="serializationInfo">Serialization information to generate the metadata uri.</param>
 /// <param name="itemTypeReference">The item type of the collection.</param>
 /// <param name="metadataUri">Returns the metadata URI for an operation (function, action, service op) based on its function import.</param>
 /// <returns>true if we have successfully built the metadata URI; false otherwise.</returns>
 internal override bool TryBuildCollectionMetadataUri(ODataCollectionStartSerializationInfo serializationInfo, IEdmTypeReference itemTypeReference, out Uri metadataUri)
 {
     DebugUtils.CheckNoExternalCallers();
     metadataUri = null;
     return(false);
 }
 public void ShouldBeAbleToSetTheCollectionStartSerializationInfo()
 {
     ODataCollectionStart collectionStart = new ODataCollectionStart();
     ODataCollectionStartSerializationInfo serializationInfo = new ODataCollectionStartSerializationInfo { CollectionTypeName = "Collection(Edm.String)" };
     collectionStart.SetSerializationInfo(serializationInfo);
     collectionStart.SerializationInfo.Should().BeSameAs(serializationInfo);
 }
 public void TestInit()
 {
     this.testSubject = new ODataCollectionStartSerializationInfo();
 }