public void Test() { var requestFactory = new TestRequestFactory(); requestFactory.RequestTimeout = TimeSpan.FromSeconds(30); requestFactory.PrepareResponse = r => { byte[] responseBytes = Encoding.UTF8.GetBytes("{\"Id\":1}"); r.ResponseStream.Write(responseBytes, 0, responseBytes.Length); r.ResponseStream.Seek(0, SeekOrigin.Begin); }; var client = new SampleClient("http://foo.com", requestFactory); var gate = new AutoResetEvent(false); TestClass response = null; client.BeginGetTestClass(ar => { response = client.EndGetTestClass(ar); gate.Set(); }, null); if (!gate.WaitOne(40000)) { throw new Exception("timed out"); } Assert.AreEqual(1, response.Id); }
public void aTestServer() { var server = new CassiniDevServer(); server.StartServer(ContentLocation); var gate = new AutoResetEvent(false); Exception exception = null; var client = new SampleClient(server.RootUrl); client.BeginGetTestClass(ar => { try { var result = client.EndGetTestClass(ar); } catch (Exception ex) { exception = ex; } finally { server.Dispose(); } gate.Set(); }, null); if (!gate.WaitOne(10000)) { throw new Exception("timed out"); } if (exception != null) { throw exception; } }
public void TestServer() { var gate = new AutoResetEvent(false); Exception exception = null; TestClass result = null; var client = new SampleClient(RootUrl); client.Serializer = Serializer; client.BeginGetTestClass(ar => { try { result = client.EndGetTestClass(ar); } catch (Exception ex) { exception = ex; } gate.Set(); }, null); if (!gate.WaitOne(60000)) { throw new Exception("timed out"); } if (exception != null) { throw exception; } Assert.AreEqual(1, result.Id); }
public void TestServer() { var gate = new AutoResetEvent(false); Exception exception = null; var client = new SampleClient(RootUrl.TrimEnd('/')); client.BeginGetTestClass(ar => { try { var result = client.EndGetTestClass(ar); } catch (Exception ex) { exception = ex; } gate.Set(); }, null); if (!gate.WaitOne(10000)) { throw new Exception("timed out"); } if (exception != null) { throw exception; } }