コード例 #1
0
 public object Put(SlowResource r)
 {
     System.Threading.Thread.Sleep(4000);
     return(new SlowResource {
         Time = r.Time
     });
 }
コード例 #2
0
        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");
        }
コード例 #3
0
ファイル: PostTests.cs プロジェクト: JornWildt/Ramone
        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");
        }
コード例 #4
0
ファイル: SlowHandler.cs プロジェクト: miqui/Ramone
 public object Post(SlowResource r)
 {
   System.Threading.Thread.Sleep(4000);
   return new SlowResource { Time = r.Time };
 }