/// <summary> /// Apply the given configuration to the resource set. /// </summary> /// <param name="configuration">data service configuration instance.</param> /// <param name="staticConfiguration">Data service static configuration.</param> private void ApplyConfiguration(DataServiceConfiguration configuration, DataServiceStaticConfiguration staticConfiguration) { #if DEBUG Debug.Assert(!this.isReadOnly, "Can only apply the configuration once."); #endif // Set entity set rights this.rights = configuration.GetResourceSetRights(this.resourceSet); // Set page size this.pageSize = configuration.GetResourceSetPageSize(this.resourceSet); if (this.pageSize < 0) { throw new DataServiceException(500, Strings.DataService_SDP_PageSizeMustbeNonNegative(this.pageSize, this.Name)); } // Add QueryInterceptors this.readAuthorizationMethods = staticConfiguration.GetReadAuthorizationMethods(this.resourceSet); // Add ChangeInterceptors this.writeAuthorizationMethods = staticConfiguration.GetWriteAuthorizationMethods(this.resourceSet); #if DEBUG this.isReadOnly = true; #endif }
public void StaticConfigurationCaching() { ReflectionBookStoreDataService service = new ReflectionBookStoreDataService(); service.AttachHost(new DataServiceHostSimulator { AbsoluteServiceUri = new Uri("http://www.temp.org"), AbsoluteRequestUri = new Uri("http://www.temp.org/Authors"), RequestHttpMethod = "GET", ResponseStream = new MemoryStream() }); service.ProcessRequest(); DataServiceCacheItem cacheItem = MetadataCache <DataServiceCacheItem> .TryLookup(service.GetType(), new object()); DataServiceStaticConfiguration oldStaticConfig = cacheItem.StaticConfiguration; service.AttachHost(new DataServiceHostSimulator { AbsoluteServiceUri = new Uri("http://www.temp.org"), AbsoluteRequestUri = new Uri("http://www.temp.org/Books"), RequestHttpMethod = "GET", ResponseStream = new MemoryStream() }); service.ProcessRequest(); cacheItem = MetadataCache <DataServiceCacheItem> .TryLookup(service.GetType(), new object()); DataServiceStaticConfiguration newStaticConfig = cacheItem.StaticConfiguration; Assert.AreEqual(oldStaticConfig, newStaticConfig); ResourceSet rsBooks = cacheItem.ResourceSetWrapperCache["Books"].ResourceSet; var queryInterceptors = newStaticConfig.GetReadAuthorizationMethods(rsBooks); Assert.AreEqual(queryInterceptors.Count(), 1); ResourceSet rsAuthors = cacheItem.ResourceSetWrapperCache["Authors"].ResourceSet; var changeInterceptors = newStaticConfig.GetWriteAuthorizationMethods(rsAuthors); Assert.AreEqual(changeInterceptors.Count(), 1); }