public object Put(SlowResource r) { System.Threading.Thread.Sleep(4000); return(new SlowResource { Time = r.Time }); }
public void WhenGettingAsyncEventTheRequestIsInFactAsync() { // Arrange Request request = Session.Bind(Constants.SlowPath); TimeSpan asyncTime = TimeSpan.MaxValue; TimeSpan syncTime = TimeSpan.MinValue; SlowResource result = null; TestAsyncEvent(wh => { DateTime t1 = DateTime.Now; // Act request.AsyncEvent() .OnComplete(() => wh.Set()) .Get(response => { syncTime = DateTime.Now - t1; result = response.Decode <SlowResource>(); }); asyncTime = DateTime.Now - t1; }); // Assert Assert.IsNotNull(result); Assert.AreEqual(4, result.Time); Assert.Greater(syncTime, TimeSpan.FromSeconds(3), "Request takes at least 4 seconds - 3 should be a safe test"); Assert.Less(asyncTime, TimeSpan.FromSeconds(1), "Async should be instantaneous - 1 second should be safe"); }
public void WhenPostingAsyncTheRequestIsInFactAsync() { // Arrange Request request = Session.Bind(Constants.SlowPath).AsJson(); TimeSpan asyncTime = TimeSpan.MaxValue; TimeSpan syncTime = TimeSpan.MinValue; SlowResource input = new SlowResource { Time = 10 }; SlowResource result = null; TestAsync(wh => { DateTime t1 = DateTime.Now; // Act request.Async() .OnError(error => Assert.Fail()) .OnComplete(() => wh.Set()) .Post<SlowResource>(input, response => { syncTime = DateTime.Now - t1; result = response.Body; }); asyncTime = DateTime.Now - t1; }); // Assert Assert.IsNotNull(result); Assert.AreEqual(input.Time, result.Time); Assert.Greater(syncTime, TimeSpan.FromSeconds(3), "Request takes at least 4 seconds - 3 should be a safe test"); Assert.Less(asyncTime, TimeSpan.FromSeconds(1), "Async should be instantaneous - 1 second should be safe"); }
public object Post(SlowResource r) { System.Threading.Thread.Sleep(4000); return new SlowResource { Time = r.Time }; }