コード例 #1
0
ファイル: ChannelTests.cs プロジェクト: nuxleus/WCFWeb
        private static void SubmitRequests(object data)
        {
            ManualResetEvent done = data as ManualResetEvent;

            Assert.IsNotNull(done);
            try
            {
                // Wait for channel to start receiving requests. The HttpListener should have started accepting
                // requests at this point but on a few occasions there seems to be a delay causing the HttpClient
                // requests that we start below to fail. By inserting this sleep we should be able to rule out
                // some lower level race condition.
                Thread.Sleep(BasicChannelTests.waitTimeout);

                using (var client = TestServiceClient.CreateClient())
                {
                    var result = TestServiceClient.RunClient(client, TestHeaderOptions.InsertRequest | TestHeaderOptions.ValidateResponse);
                    int cnt    = 0;
                    foreach (var response in result)
                    {
                        cnt++;
                        Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, string.Format("Check failed in response {0}", cnt));
                        Assert.AreEqual(BasicChannelTests.ChannelHttpReasonPhrase, response.ReasonPhrase, string.Format("Check failed in response {0}", cnt));
                    }
                }
            }
            finally
            {
                done.Set();
            }
        }
コード例 #2
0
 private void MissingPropertyServiceTest(bool asynchronousSendEnabled, bool faultDetail, bool streamed)
 {
     using (var host = TestServiceHost.CreateWebHost <TestService>(asynchronousSendEnabled, faultDetail, streamed, new HttpMessageHandlerFactory(typeof(TestHandler))))
     {
         using (var client = TestServiceClient.CreateClient(false, TestServiceCommon.ServiceAddress))
         {
             var result = TestServiceClient.RunClient(client, TestHeaderOptions.InsertRequest | TestHeaderOptions.ValidateResponse);
             foreach (var httpResponse in result)
             {
                 TestServiceCommon.ValidateInternalServerErrorResponse(httpResponse, faultDetail);
             }
         }
     }
 }
コード例 #3
0
 private void MethodNotAllowedServiceTest(bool asynchronousSendEnabled, bool streamed)
 {
     using (var host = TestServiceHost.CreateWebHost <TestService>(asynchronousSendEnabled, false, streamed, new HttpMessageHandlerFactory(typeof(TestHandler))))
     {
         using (var client = TestServiceClient.CreateClient(false, TestServiceCommon.ServiceAddress))
         {
             var result = TestServiceClient.RunClient(client, TestHeaderOptions.InsertRequest | TestHeaderOptions.ValidateResponse, HttpMethod.Options);
             foreach (var httpResponse in result)
             {
                 TestServiceCommon.ValidateMethodNotAllowedResponse(httpResponse);
             }
         }
     }
 }
コード例 #4
0
 private void NoDataServiceTest(bool asynchronousSendEnabled, bool streamed, bool copyHeaderInHandler)
 {
     NoDataServiceTests.CopyHeaderInHandler = copyHeaderInHandler;
     using (var host = TestServiceHost.CreateWebHost <TestService>(asynchronousSendEnabled, false, streamed, new HttpMessageHandlerFactory(typeof(TestHandler))))
     {
         using (var client = TestServiceClient.CreateClient())
         {
             var result = TestServiceClient.RunClient(client, TestHeaderOptions.InsertRequest | TestHeaderOptions.ValidateResponse);
             foreach (var httpResponse in result)
             {
                 Assert.AreEqual(HttpStatusCode.OK, httpResponse.StatusCode);
                 Assert.AreEqual(TestWebServiceBase.HttpReasonPhrase, httpResponse.ReasonPhrase);
                 Assert.AreEqual(0, httpResponse.Content.Headers.ContentLength);
                 Assert.IsNull(httpResponse.Content.Headers.ContentType);
             }
         }
     }
 }
コード例 #5
0
 private void PersistenceTest(bool asynchronousSendEnabled, bool streamed)
 {
     using (var host = TestServiceHost.CreateWebHost <TestService>(asynchronousSendEnabled, false, streamed, new HttpMessageHandlerFactory(typeof(TestHandler))))
     {
         using (var client = TestServiceClient.CreateClient())
         {
             var result = TestServiceClient.RunClient(client, TestHeaderOptions.ValidateResponse);
             foreach (var httpResponse in result)
             {
                 Assert.AreEqual(HttpStatusCode.OK, httpResponse.StatusCode);
                 Assert.AreEqual(TestWebServiceBase.HttpReasonPhrase, httpResponse.ReasonPhrase);
                 Assert.AreEqual("text/plain", httpResponse.Content.Headers.ContentType.MediaType);
                 Assert.AreEqual("utf-8", httpResponse.Content.Headers.ContentType.CharSet);
                 var body = httpResponse.Content.ReadAsString();
                 Assert.AreEqual(body, TestWebServiceBase.HttpResponseContent);
             }
         }
     }
 }
コード例 #6
0
        private void DisposeHandlerTest(bool asynchronousSendEnabled, bool streamed)
        {
            DisposeHandlerTests.handlerList = new List <TestHandler>();
            using (var host = TestServiceHost.CreateWebHost <TestService>(asynchronousSendEnabled, false, streamed, new HttpMessageHandlerFactory(typeof(TestHandler))))
            {
                using (var client = TestServiceClient.CreateClient())
                {
                    var result = TestServiceClient.RunClient(client, TestHeaderOptions.InsertRequest | TestHeaderOptions.ValidateResponse);
                    foreach (var httpResponse in result)
                    {
                        Assert.AreEqual(HttpStatusCode.OK, httpResponse.StatusCode);
                        Assert.AreEqual(TestWebServiceBase.HttpReasonPhrase, httpResponse.ReasonPhrase);
                    }

                    Assert.AreEqual(1, DisposeHandlerTests.handlerList.Count);
                    Assert.IsFalse(DisposeHandlerTests.handlerList[0].IsDisposed);
                }
            }

            Assert.AreEqual(1, DisposeHandlerTests.handlerList.Count);
            Assert.IsTrue(DisposeHandlerTests.handlerList[0].IsDisposed);
        }