Пример #1
0
        private NodeToExpressionTranslator CreateTestSubject(
            DataServiceBehavior dataServiceBehavior             = null,
            FunctionExpressionBinder expressionBinder           = null,
            Action <ODataProtocolVersion> verifyProtocolVersion = null,
            Action <ODataProtocolVersion> verifyRequestVersion  = null)
        {
            if (dataServiceBehavior == null)
            {
                dataServiceBehavior = new DataServiceBehavior();
            }

            if (expressionBinder == null)
            {
                expressionBinder = this.functionExpressionBinder;
            }

            if (verifyProtocolVersion == null)
            {
                verifyProtocolVersion = v => { };
            }

            if (verifyRequestVersion == null)
            {
                verifyRequestVersion = v => { };
            }

            return(NodeToExpressionTranslator.CreateForTests(
                       expressionBinder,
                       dataServiceBehavior,
                       new object(),
                       false,
                       this.implicitParameterExpression,
                       verifyProtocolVersion,
                       verifyRequestVersion));
        }
Пример #2
0
        private static IEnumerable <IEdmVocabularyAnnotation> GetMetadataAnnotations(DataServiceBehavior dataServiceBehavior, out EdmEntityContainer container)
        {
            container = new EdmEntityContainer("Fake", "Container");
            var primaryModel = new EdmModel();

            primaryModel.AddElement(container);

            return(UrlConvention.BuildMetadataAnnotations(dataServiceBehavior, primaryModel));
        }
Пример #3
0
        /// <summary>
        /// Builds the annotations needed to indicate the supported url conventions based on the service's configuration.
        /// </summary>
        /// <param name="dataServiceBehavior">The data service behavior.</param>
        /// <param name="model">The service's model.</param>
        /// <returns>The annotations to add to the model.</returns>
        internal static IEnumerable <IEdmValueAnnotation> BuildMetadataAnnotations(DataServiceBehavior dataServiceBehavior, IEdmModel model)
        {
            Debug.Assert(dataServiceBehavior != null, "dataServiceBehavior != null");
            Debug.Assert(model != null, "model != null");

            if (dataServiceBehavior.GenerateKeyAsSegment)
            {
                yield return(new EdmAnnotation(model.EntityContainer, ConventionTerm, KeyAsSegmentAnnotationValue));
            }
        }
Пример #4
0
        public void ConfigurationFileShouldForReplaceShouldOnlyBeAppliedIfPresent()
        {
            var testSubject = new DataServiceBehavior {
                AcceptReplaceFunctionInQuery = true
            };

            testSubject.ApplySettingsFromConfiguration(new DataServicesFeaturesSection {
                ReplaceFunction = new TestReplaceFeature(false)
                {
                    Enable = false
                }
            });
            testSubject.AcceptReplaceFunctionInQuery.Should().BeTrue();
        }
Пример #5
0
        public ServiceSimulatorFactory()
        {
            this.baseUri = new Uri("http://localhost");
            this.host    = new DataServiceHostSimulator()
            {
                AbsoluteServiceUri = this.baseUri,
                RequestHttpMethod  = "GET",
                RequestAccept      = "application/atom+xml,application/xml",
                RequestVersion     = "4.0",
                RequestMaxVersion  = "4.0",
            };

            this.provider = new DataServiceProviderSimulator();
            this.behavior = new DataServiceBehavior()
            {
                MaxProtocolVersion = Microsoft.OData.Client.ODataProtocolVersion.V4
            };
        }
Пример #6
0
        public void ConfigurationFileShouldSupercedeApiForReplace()
        {
            var testSubject = new DataServiceBehavior {
                AcceptReplaceFunctionInQuery = false
            };
            DataServicesReplaceFunctionFeature replaceFeature = new TestReplaceFeature(true)
            {
                Enable = true
            };
            DataServicesFeaturesSection dataServicesFeaturesSection = new DataServicesFeaturesSection {
                ReplaceFunction = replaceFeature
            };

            testSubject.ApplySettingsFromConfiguration(dataServicesFeaturesSection);
            testSubject.AcceptReplaceFunctionInQuery.Should().BeTrue();

            replaceFeature.Enable = false;
            testSubject.ApplySettingsFromConfiguration(dataServicesFeaturesSection);
            testSubject.AcceptReplaceFunctionInQuery.Should().BeFalse();
        }
Пример #7
0
 /// <summary>
 /// Helper for creating an instance directly from the relevant user input. Should only be called from unit tests.
 /// </summary>
 /// <param name="dataServiceBehavior">The data service behavior from configuration.</param>
 /// <param name="getCustomHeaderValue">The callback for getting custom header values.</param>
 /// <returns>A new UrlConvention instance based on the user input.</returns>
 internal static UrlConvention CreateFromUserInput(DataServiceBehavior dataServiceBehavior, Func <string, string> getCustomHeaderValue)
 {
     Debug.Assert(dataServiceBehavior != null, "dataServiceBehavior != null");
     Debug.Assert(getCustomHeaderValue != null, "getCustomHeaderValue != null");
     return(new UrlConvention(dataServiceBehavior.GenerateKeyAsSegment && IsKeyAsSegment(getCustomHeaderValue(UrlConventionHeaderName))));
 }
Пример #8
0
        /// <summary>
        /// Builds the annotations needed to indicate the supported url conventions based on the service's configuration.
        /// </summary>
        /// <param name="dataServiceBehavior">The data service behavior.</param>
        /// <param name="model">The service's model.</param>
        /// <returns>The annotations to add to the model.</returns>
        internal static IEnumerable<IEdmValueAnnotation> BuildMetadataAnnotations(DataServiceBehavior dataServiceBehavior, IEdmModel model)
        {
            Debug.Assert(dataServiceBehavior != null, "dataServiceBehavior != null");
            Debug.Assert(model != null, "model != null");

            if (dataServiceBehavior.GenerateKeyAsSegment)
            {
                yield return new EdmAnnotation(model.EntityContainer, ConventionTerm, KeyAsSegmentAnnotationValue);
            }
        }
Пример #9
0
 /// <summary>
 /// Helper for creating an instance directly from the relevant user input. Should only be called from unit tests.
 /// </summary>
 /// <param name="dataServiceBehavior">The data service behavior from configuration.</param>
 /// <param name="getCustomHeaderValue">The callback for getting custom header values.</param>
 /// <returns>A new UrlConvention instance based on the user input.</returns>
 internal static UrlConvention CreateFromUserInput(DataServiceBehavior dataServiceBehavior, Func<string, string> getCustomHeaderValue)
 {
     Debug.Assert(dataServiceBehavior != null, "dataServiceBehavior != null");
     Debug.Assert(getCustomHeaderValue != null, "getCustomHeaderValue != null");
     return new UrlConvention(dataServiceBehavior.GenerateKeyAsSegment && IsKeyAsSegment(getCustomHeaderValue(UrlConventionHeaderName)));
 }