Пример #1
0
        public void ProcessRequestCalledTwiceWithSameHostShouldWork()
        {
            var host = new DataServiceHostSimulator {
                AbsoluteRequestUri = new Uri("http://example.com/Customers(1)"), AbsoluteServiceUri = new Uri("http://example.com/"), RequestHttpMethod = "GET", ResponseStream = new MemoryStream(), ProcessExceptionCallBack = (args) => { }
            };
            var svc = new TestService();

            svc.AttachHost(host);
            svc.ProcessRequest();
            host.ResponseStatusCode.Should().Be(200);
            host.ResponseStream.Position = 0;
            var customerResponse = new StreamReader(host.ResponseStream).ReadToEnd();

            customerResponse.Should().Contain("Customer");
            customerResponse.Should().Contain("Redmond Way");
            customerResponse.Should().Contain("*****@*****.**");

            host.ResponseStream     = new MemoryStream();
            host.AbsoluteRequestUri = new Uri("http://example.com/Customers(1)/Address");
            // re-attach the host before calling ProcessRequest
            svc.AttachHost(host);
            svc.ProcessRequest();
            host.ResponseStatusCode.Should().Be(200);
            host.ResponseStream.Position = 0;
            var addressResponse = new StreamReader(host.ResponseStream).ReadToEnd();

            addressResponse.Should().Contain("Redmond Way");
            addressResponse.Should().NotContain("*****@*****.**");
            addressResponse.Should().NotMatch(customerResponse);
        }
Пример #2
0
        public void ProcessRequestCalledTwiceWithSameHostShouldWork()
        {
            var host = new DataServiceHostSimulator {AbsoluteRequestUri = new Uri("http://example.com/Customers(1)"), AbsoluteServiceUri = new Uri("http://example.com/"), RequestHttpMethod = "GET", ResponseStream = new MemoryStream(), ProcessExceptionCallBack = (args) => { }};
            var svc = new TestService();
            svc.AttachHost(host);
            svc.ProcessRequest();
            host.ResponseStatusCode.Should().Be(200);
            host.ResponseStream.Position = 0;
            var customerResponse = new StreamReader(host.ResponseStream).ReadToEnd();
            customerResponse.Should().Contain("Customer");
            customerResponse.Should().Contain("Redmond Way");
            customerResponse.Should().Contain("*****@*****.**");

            host.ResponseStream = new MemoryStream();
            host.AbsoluteRequestUri = new Uri("http://example.com/Customers(1)/Address");
            // re-attach the host before calling ProcessRequest
            svc.AttachHost(host);
            svc.ProcessRequest();
            host.ResponseStatusCode.Should().Be(200);
            host.ResponseStream.Position = 0;
            var addressResponse = new StreamReader(host.ResponseStream).ReadToEnd();
            addressResponse.Should().Contain("Redmond Way");
            addressResponse.Should().NotContain("*****@*****.**");
            addressResponse.Should().NotMatch(customerResponse);
        }
Пример #3
0
 public void ResponseStatusCodeIsNotSetOnHostAfterProcessRequestWith404Error()
 {
     HandleExceptionArgs exceptionArgs = null;
     var host = new DataServiceHostSimulator { AbsoluteRequestUri = new Uri("http://example.com/invalid"), AbsoluteServiceUri = new Uri("http://example.com/"), RequestHttpMethod = "GET", ResponseStream = new MemoryStream(), ProcessExceptionCallBack = (args) => { exceptionArgs = args; } };
     var svc = new TestService();
     svc.AttachHost(host);
     svc.ProcessRequest();
     //// Astoria Server fails to set IDSH.ResponseStatusCode for custom hosts in an error scenario
     //// The behavior has been this way from V2 of WCF Data Services and on, when this is changed
     //// it will be a breaking change
     host.ResponseStatusCode.Should().Be(0);
     host.ResponseStream.Position = 0;
     var customerResponse = new StreamReader(host.ResponseStream).ReadToEnd();
     customerResponse.Should().Contain("Resource not found for the segment 'invalid'.");
     exceptionArgs.ResponseStatusCode.Should().Be(404);
 }
Пример #4
0
        public void ProcessRequestCalledSecondTimeWithoutAttachHostShouldThrow()
        {
            var host = new DataServiceHostSimulator {AbsoluteRequestUri = new Uri("http://example.com/Customers(1)"), AbsoluteServiceUri = new Uri("http://example.com/"), RequestHttpMethod = "GET", ResponseStream = new MemoryStream(), ProcessExceptionCallBack = (args) => { }};
            var svc = new TestService();
            svc.AttachHost(host);
            svc.ProcessRequest();
            host.ResponseStatusCode.Should().Be(200);
            host.ResponseStream.Position = 0;
            var customerResponse = new StreamReader(host.ResponseStream).ReadToEnd();
            customerResponse.Should().Contain("Customer");
            customerResponse.Should().Contain("Redmond Way");
            customerResponse.Should().Contain("*****@*****.**");

            host.ResponseStream = new MemoryStream();
            host.AbsoluteRequestUri = new Uri("http://example.com/Customers(1)/Address");
            Action secondRequest = () => svc.ProcessRequest();
            secondRequest.ShouldThrow<InvalidOperationException>();
        }
Пример #5
0
        public void ResponseStatusCodeIsNotSetOnHostAfterProcessRequestWith404Error()
        {
            HandleExceptionArgs exceptionArgs = null;
            var host = new DataServiceHostSimulator {
                AbsoluteRequestUri = new Uri("http://example.com/invalid"), AbsoluteServiceUri = new Uri("http://example.com/"), RequestHttpMethod = "GET", ResponseStream = new MemoryStream(), ProcessExceptionCallBack = (args) => { exceptionArgs = args; }
            };
            var svc = new TestService();

            svc.AttachHost(host);
            svc.ProcessRequest();
            //// Astoria Server fails to set IDSH.ResponseStatusCode for custom hosts in an error scenario
            //// The behavior has been this way from V2 of WCF Data Services and on, when this is changed
            //// it will be a breaking change
            host.ResponseStatusCode.Should().Be(0);
            host.ResponseStream.Position = 0;
            var customerResponse = new StreamReader(host.ResponseStream).ReadToEnd();

            customerResponse.Should().Contain("Resource not found for the segment 'invalid'.");
            exceptionArgs.ResponseStatusCode.Should().Be(404);
        }
Пример #6
0
        public void ProcessRequestCalledSecondTimeWithoutAttachHostShouldThrow()
        {
            var host = new DataServiceHostSimulator {
                AbsoluteRequestUri = new Uri("http://example.com/Customers(1)"), AbsoluteServiceUri = new Uri("http://example.com/"), RequestHttpMethod = "GET", ResponseStream = new MemoryStream(), ProcessExceptionCallBack = (args) => { }
            };
            var svc = new TestService();

            svc.AttachHost(host);
            svc.ProcessRequest();
            host.ResponseStatusCode.Should().Be(200);
            host.ResponseStream.Position = 0;
            var customerResponse = new StreamReader(host.ResponseStream).ReadToEnd();

            customerResponse.Should().Contain("Customer");
            customerResponse.Should().Contain("Redmond Way");
            customerResponse.Should().Contain("*****@*****.**");

            host.ResponseStream     = new MemoryStream();
            host.AbsoluteRequestUri = new Uri("http://example.com/Customers(1)/Address");
            Action secondRequest = () => svc.ProcessRequest();

            secondRequest.ShouldThrow <InvalidOperationException>();
        }