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();
        }
Ejemplo n.º 2
0
        // Enable or disable replace function in web.config
        public virtual void SetReplaceFunctionFeature(string filePath, bool includeWcfDataServicesGroupInWebConfig, bool replaceFunctionEnabled)
        {
#if !ClientSKUFramework

            this.configFile = new ExeConfigurationFileMap { ExeConfigFilename = Path.Combine(filePath, "Web.Config") };
            this.config = ConfigurationManager.OpenMappedExeConfiguration(this.configFile, ConfigurationUserLevel.None);

            this.config.SectionGroups.Remove("wcfDataServices");

            if (includeWcfDataServicesGroupInWebConfig)
            {
                DataServicesSectionGroup dataServicesSectionGroup = new DataServicesSectionGroup();
                this.config.SectionGroups.Add("wcfDataServices", dataServicesSectionGroup);

                DataServicesFeaturesSection dataServicesFeaturesSection = new DataServicesFeaturesSection();
                dataServicesSectionGroup.Sections.Add("features", dataServicesFeaturesSection);

                dataServicesFeaturesSection.ReplaceFunction.Enable = replaceFunctionEnabled;
            }

            config.Save();
#endif
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Applies the settings from the configuration file.
 /// </summary>
 /// <param name="featuresSection">The features section from the configuration file.</param>
 internal void ApplySettingsFromConfiguration(DataServicesFeaturesSection featuresSection)
 {
     if (featuresSection != null)
     {
         // If the element is specified in the config section, then value in the config
         // wins over the api one. Hence overriding the api value if the value is specified
         // in the config file.
         if (featuresSection.ReplaceFunction.IsPresent)
         {
             this.AcceptReplaceFunctionInQuery = featuresSection.ReplaceFunction.Enable;
         }
     }
 }
 /// <summary>
 /// Loads settings defined in the configuration file.
 /// </summary>
 private void LoadConfigurationSettings()
 {
     this.DataServicesFeaturesSection = (DataServicesFeaturesSection)ConfigurationManager.GetSection("wcfDataServices/features");
 }