Esempio n. 1
0
        public void InitTest()
        {
            this.host = new DataServiceHost2Simulator();
            this.host.AbsoluteServiceUri = new Uri("http://service/");
            this.host.AbsoluteServiceUri = new Uri("http://service/set1");

            var providerSimulator = new DataServiceProviderSimulator();
            this.service = new DataServiceSimulator
            {
                OperationContext = new DataServiceOperationContext(false, this.host),
                Configuration = new DataServiceConfiguration(providerSimulator)
            };

            DataServiceStaticConfiguration staticConfiguration = new DataServiceStaticConfiguration(this.service.Instance.GetType(), providerSimulator);
            IDataServiceProviderBehavior providerBehavior = DataServiceProviderBehavior.CustomDataServiceProviderBehavior;

            this.service.ProcessingPipeline = new DataServiceProcessingPipeline();
            this.service.Provider = new DataServiceProviderWrapper(
                new DataServiceCacheItem(
                    this.service.Configuration, 
                    staticConfiguration), 
                providerSimulator, 
                providerSimulator, 
                this.service,
                false);
            this.service.Provider.ProviderBehavior = providerBehavior;
            this.service.OperationContext.InitializeAndCacheHeaders(this.service);
        }
 public void GetQueryStringItemAsksHost()
 {
     var host = new DataServiceHost2Simulator();
     host.SetQueryStringItem("some-key", "test-value");
     DataServiceOperationContext context = new DataServiceOperationContext(host);
     context.GetQueryStringValue("some-key").Should().Be("test-value");
 }
        public void UrlConventionIntegrationTest()
        {
            var host = new DataServiceHost2Simulator
                       {
                           RequestHeaders = new WebHeaderCollection { { UrlConventionsConstants.UrlConventionHeaderName, "KeyAsSegment" } },
                       };
            var service = new DataServiceSimulator
            {
                Configuration = new DataServiceConfiguration(new DataServiceProviderSimulator()), 
                OperationContext = new DataServiceOperationContext(host)
            };

            service.OperationContext.InitializeAndCacheHeaders(service);

            service.Configuration.DataServiceBehavior.UrlConventions = DataServiceUrlConventions.KeyAsSegment;
            UrlConvention.Create(service).GenerateKeyAsSegment.Should().BeTrue();
        }
        public void Initialize()
        {
            this.host = new DataServiceHost2Simulator();

            var context = new DataServiceOperationContext(this.host);
            this.dataServiceSimulator = new DataServiceSimulator { OperationContext = context };

            var providerSimulator = new DataServiceProviderSimulator();

            DataServiceStaticConfiguration staticConfiguration = new DataServiceStaticConfiguration(this.dataServiceSimulator.Instance.GetType(), providerSimulator);
            IDataServiceProviderBehavior providerBehavior = DataServiceProviderBehavior.CustomDataServiceProviderBehavior;

            var resourceType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "SelectTestNamespace", "Fake", false) { CanReflectOnInstanceType = false, IsOpenType = true };
            resourceType.AddProperty(new ResourceProperty("Id", ResourcePropertyKind.Key | ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(int))) { CanReflectOnInstanceTypeProperty = false });
            var resourceSet = new ResourceSet("FakeSet", resourceType);
            resourceSet.SetReadOnly();

            providerSimulator.AddResourceSet(resourceSet);

            var configuration = new DataServiceConfiguration(providerSimulator);
            configuration.SetEntitySetAccessRule("*", EntitySetRights.All);

            var provider = new DataServiceProviderWrapper(
                new DataServiceCacheItem(
                    configuration,
                    staticConfiguration), 
                providerSimulator, 
                providerSimulator, 
                this.dataServiceSimulator,
                false);

            this.dataServiceSimulator.ProcessingPipeline = new DataServiceProcessingPipeline();
            this.dataServiceSimulator.Provider = provider;
            provider.ProviderBehavior = providerBehavior;
            this.dataServiceSimulator.Configuration = new DataServiceConfiguration(providerSimulator);
            this.dataServiceSimulator.Configuration.DataServiceBehavior.MaxProtocolVersion = ODataProtocolVersion.V4;

            this.responseMessageSimulator = new ODataResponseMessageSimulator();
        }
 public void GetMissingQueryStringItemReturnsNullIfHostReturnsNull()
 {
     var host = new DataServiceHost2Simulator();
     DataServiceOperationContext context = new DataServiceOperationContext(host);
     context.GetQueryStringValue("some-key").Should().Be(null);
 }
        public void RequestHeadersIsFromHost()
        {
            var value = new WebHeaderCollection { { "RequestVersion", "2.0" }, { "Accept", "json" }, { "Custom", "customValue" } };
            var host = new DataServiceHost2Simulator { RequestHeaders = value };
            var requestMessage = new AstoriaRequestMessage(host);

            requestMessage.RequestHeaders.Should().BeEquivalentTo(value);
            requestMessage.RequestHeaders["RequestVersion"] = "2.0";
            requestMessage.RequestHeaders["Accept"] = "json";
            requestMessage.RequestHeaders["Custom"] = "customValue";
        }