Beispiel #1
0
 public void GetUriFragmentFromMetadataReferencePropertyNameShouldReturnTheSubstringAfterHash()
 {
     ODataJsonLightUtils.GetUriFragmentFromMetadataReferencePropertyName(this.MetadataDocumentUri, "#name").Should().Be("name");
     ODataJsonLightUtils.GetUriFragmentFromMetadataReferencePropertyName(this.MetadataDocumentUri, "http://example.com/foo#name").Should().Be("name");
     ODataJsonLightUtils.GetUriFragmentFromMetadataReferencePropertyName(this.MetadataDocumentUri, "##").Should().Be("#");
     ODataJsonLightUtils.GetUriFragmentFromMetadataReferencePropertyName(this.MetadataDocumentUri, "#function(Edm.Duration,Edm.Guid)").Should().Be("function(Edm.Duration,Edm.Guid)");
 }
Beispiel #2
0
        /// <summary>
        /// Computes the operations that are missing from the payload but should be added by conventions onto the entry.
        /// </summary>
        private void ComputeMissingOperationsToEntry()
        {
            Debug.Assert(this.entryMetadataContext != null, "this.entryMetadataContext != null");
            Debug.Assert(this.metadataContext != null, "this.metadataContext != null");

            if (this.computedActions == null)
            {
                Debug.Assert(this.computedFunctions == null, "this.computedFunctions == null");

                this.computedActions   = new List <ODataAction>();
                this.computedFunctions = new List <ODataFunction>();
                HashSet <IEdmOperation> edmOperations = GetOperationsInEntry(this.entryMetadataContext.Entry, this.metadataContext.Model, this.metadataContext.MetadataDocumentUri);
                foreach (IEdmOperation bindableOperation in this.entryMetadataContext.SelectedBindableOperations)
                {
                    // if this operation appears in the payload, skip it.
                    if (edmOperations.Contains(bindableOperation))
                    {
                        continue;
                    }

                    string         metadataReferencePropertyName = ODataConstants.ContextUriFragmentIndicator + ODataJsonLightUtils.GetMetadataReferenceName(this.metadataContext.Model, bindableOperation);
                    bool           isAction;
                    ODataOperation operation = ODataJsonLightUtils.CreateODataOperation(this.metadataContext.MetadataDocumentUri, metadataReferencePropertyName, bindableOperation, out isAction);
                    operation.SetMetadataBuilder(this.entryMetadataContext.Entry.MetadataBuilder, this.metadataContext.MetadataDocumentUri);
                    if (isAction)
                    {
                        this.computedActions.Add((ODataAction)operation);
                    }
                    else
                    {
                        this.computedFunctions.Add((ODataFunction)operation);
                    }
                }
            }
        }
Beispiel #3
0
 public void GetAbsoluteUriFromMetadataReferencePropertyNameShouldReturnAnAbsoluteUri()
 {
     ODataJsonLightUtils.GetAbsoluteUriFromMetadataReferencePropertyName(this.MetadataDocumentUri, "#name").Should().Be(new Uri(this.MetadataDocumentUri, "#name"));
     ODataJsonLightUtils.GetAbsoluteUriFromMetadataReferencePropertyName(this.MetadataDocumentUri, "http://example.com/foo#name").Should().Be(new Uri("http://example.com/foo#name", UriKind.Absolute));
     ODataJsonLightUtils.GetAbsoluteUriFromMetadataReferencePropertyName(this.MetadataDocumentUri, "#").Should().Be(new Uri(this.MetadataDocumentUri, "#"));
     ODataJsonLightUtils.GetAbsoluteUriFromMetadataReferencePropertyName(this.MetadataDocumentUri, "http://example.com/foo#").Should().Be(new Uri("http://example.com/foo#", UriKind.Absolute));
     ODataJsonLightUtils.GetAbsoluteUriFromMetadataReferencePropertyName(this.MetadataDocumentUri, "##").Should().Be(new Uri(this.MetadataDocumentUri, "##"));
 }
Beispiel #4
0
        private void TestGetFunctionName(string metadataPropertyName, Action <string> validateName, Action <string> validateParameters)
        {
            string firstParameterName;
            string name = ODataJsonLightUtils.GetFullyQualifiedOperationName(this.MetadataDocumentUri, metadataPropertyName, out firstParameterName);

            validateName(name);
            validateParameters(firstParameterName);
        }
Beispiel #5
0
        /// <summary>
        /// Sets the metadata builder for this operation.
        /// </summary>
        /// <param name="builder">The metadata builder used to compute values from model annotations.</param>
        /// <param name="metadataDocumentUri">The metadata document Uri.</param>
        internal void SetMetadataBuilder(ODataEntityMetadataBuilder builder, Uri metadataDocumentUri)
        {
            Debug.Assert(metadataDocumentUri != null, "metadataDocumentUri != null");
            Debug.Assert(metadataDocumentUri.IsAbsoluteUri, "metadataDocumentUri.IsAbsoluteUri");

            ODataJsonLightValidationUtils.ValidateOperation(metadataDocumentUri, this);
            this.metadataBuilder   = builder;
            this.operationFullName = ODataJsonLightUtils.GetFullyQualifiedOperationName(metadataDocumentUri, UriUtils.UriToString(this.Metadata), out this.parameterNames);
            this.computedTitle     = null;
            this.computedTarget    = null;
        }
Beispiel #6
0
        /// <summary>
        /// Throw if property is processed already.
        /// </summary>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="duplicationRecord">DuplicationRecord of the property.</param>
        private static void ThrowIfPropertyIsProcessed(string propertyName, DuplicationRecord duplicationRecord)
        {
            if (object.ReferenceEquals(duplicationRecord.PropertyODataAnnotations, propertyAnnotationsProcessedToken))
            {
                if (ODataJsonLightReaderUtils.IsAnnotationProperty(propertyName) && !ODataJsonLightUtils.IsMetadataReferenceProperty(propertyName))
                {
                    throw new ODataException(Strings.DuplicatePropertyNamesChecker_DuplicateAnnotationNotAllowed(propertyName));
                }

                throw new ODataException(Strings.DuplicatePropertyNamesChecker_DuplicatePropertyNamesNotAllowed(propertyName));
            }
        }
Beispiel #7
0
        /// <summary>
        /// Sets the metadata builder for this operation.
        /// </summary>
        /// <param name="builder">The metadata builder used to compute values from model annotations.</param>
        /// <param name="metadataDocumentUri">The metadata document Uri.</param>
        internal void SetMetadataBuilder(ODataEntityMetadataBuilder builder, Uri metadataDocumentUri)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(metadataDocumentUri != null, "metadataDocumentUri != null");
            Debug.Assert(metadataDocumentUri.IsAbsoluteUri, "metadataDocumentUri.IsAbsoluteUri");

            ODataJsonLightValidationUtils.ValidateOperation(metadataDocumentUri, this);
            this.metadataBuilder   = builder;
            this.operationFullName = ODataJsonLightUtils.GetFullyQualifiedFunctionImportName(metadataDocumentUri, UriUtilsCommon.UriToString(this.Metadata), out this.bindingParameterTypeName);
            this.computedTitle     = null;
            this.computedTarget    = null;
        }
Beispiel #8
0
        /// <summary>
        /// Marks a property to note that all its annotations should have been processed by now.
        /// </summary>
        /// <param name="propertyName">Name of the property.</param>
        /// <remarks>
        /// It's an error if more annotations for a marked property are found later in the payload.
        /// </remarks>
        internal void MarkPropertyAsProcessed(string propertyName)
        {
            Debug.Assert(propertyName != null);

            PropertyData data;

            if (!propertyData.TryGetValue(propertyName, out data))
            {
                propertyData[propertyName] = data = new PropertyData(PropertyState.AnnotationSeen);
            }

            if (data.Processed)
            {
                throw new ODataException(
                          ODataJsonLightReaderUtils.IsAnnotationProperty(propertyName) &&
                          !ODataJsonLightUtils.IsMetadataReferenceProperty(propertyName)
                    ? Strings.DuplicateAnnotationNotAllowed(propertyName)
                    : Strings.DuplicatePropertyNamesNotAllowed(propertyName));
            }

            data.Processed = true;
        }
Beispiel #9
0
        /// <summary>
        /// Returns a hash set of operation imports (actions and functions) in the given entry.
        /// </summary>
        /// <param name="entry">The entry in question.</param>
        /// <param name="model">The edm model to resolve operation imports.</param>
        /// <param name="metadataDocumentUri">The metadata document uri.</param>
        /// <returns>The hash set of operation imports (actions and functions) in the given entry.</returns>
        private static HashSet <IEdmOperation> GetOperationsInEntry(ODataEntry entry, IEdmModel model, Uri metadataDocumentUri)
        {
            Debug.Assert(entry != null, "entry != null");
            Debug.Assert(model != null, "model != null");
            Debug.Assert(metadataDocumentUri != null && metadataDocumentUri.IsAbsoluteUri, "metadataDocumentUri != null && metadataDocumentUri.IsAbsoluteUri");

            HashSet <IEdmOperation>      edmOperationImportsInEntry = new HashSet <IEdmOperation>(EqualityComparer <IEdmOperation> .Default);
            IEnumerable <ODataOperation> operations = ODataUtilsInternal.ConcatEnumerables((IEnumerable <ODataOperation>)entry.NonComputedActions, (IEnumerable <ODataOperation>)entry.NonComputedFunctions);

            if (operations != null)
            {
                foreach (ODataOperation operation in operations)
                {
                    Debug.Assert(operation.Metadata != null, "operation.Metadata != null");
                    string operationMetadataString = UriUtils.UriToString(operation.Metadata);
                    Debug.Assert(
                        ODataJsonLightUtils.IsMetadataReferenceProperty(operationMetadataString),
                        "ODataJsonLightUtils.IsMetadataReferenceProperty(operationMetadataString)");
                    Debug.Assert(
                        operationMetadataString[0] == ODataConstants.ContextUriFragmentIndicator || metadataDocumentUri.IsBaseOf(operation.Metadata),
                        "operationMetadataString[0] == JsonLightConstants.ContextUriFragmentIndicator || metadataDocumentUri.IsBaseOf(operation.Metadata)");

                    string fullyQualifiedOperationName        = ODataJsonLightUtils.GetUriFragmentFromMetadataReferencePropertyName(metadataDocumentUri, operationMetadataString);
                    IEnumerable <IEdmOperation> edmOperations = model.ResolveOperations(fullyQualifiedOperationName);
                    if (edmOperations != null)
                    {
                        foreach (IEdmOperation edmOperation in edmOperations)
                        {
                            edmOperationImportsInEntry.Add(edmOperation);
                        }
                    }
                }
            }

            return(edmOperationImportsInEntry);
        }
Beispiel #10
0
 public void GetMetadataReferenceNameFromFunctionImportShouldReturnCorrectNameForFunctionImportWithNoOverload()
 {
     ODataJsonLightUtils.GetMetadataReferenceName(this.model, this.operationWithNoOverload).Should().Be("TestModel.FunctionImportWithNoOverload");
 }
 public void IsMetadataReferencePropertyShouldReturnFalse()
 {
     Assert.False(ODataJsonLightUtils.IsMetadataReferenceProperty("name"));
     Assert.False(ODataJsonLightUtils.IsMetadataReferenceProperty("http://www.example.com/foo"));
 }
 public void GetMetadataReferenceNameFromFunctionImportShouldReturnCorrectNameForFunctionImportWithOverloadAnd2Params()
 {
     Assert.Equal("TestModel.FunctionImportWithOverload(p1,p2)", ODataJsonLightUtils.GetMetadataReferenceName(this.model, this.operationWithOverloadAnd2Params));
 }