public void GetAborted() { //Arrange StubModule.HaltProcessing = TimeSpan.FromMilliseconds(1000); StubModule.GetPerson = false; StubModule.TestHarness = new List<Person> { new Person { Id = 1, Email = "*****@*****.**" } }; RestRequest target = new RestRequest(HttpMethod.GET, new RestUri(_MyUri, "/Person/{id}").SetParameter("id", "1")); //Act RestResponse response = null; //A completely synchronous GetResponse cannot be aborted. //So, spining off a new thread.. And balancing the times between GetResponse() and Abort() methods. var task = Task.Factory.StartNew(() => { response = target.GetResponse(); }); Thread.Sleep(500); target.Abort(); task.Wait(); //Assert Assert.NotNull(response); Assert.NotNull(response.Error); Assert.Equal("The request was aborted: The request was canceled.", response.Error.InnerException.Message); Assert.Equal(0, (int)response.Error.StatusCode); }
public void GetOfTAborted() { //Arrange StubModule.HaltProcessing = TimeSpan.FromMilliseconds(1000); StubModule.GetPerson = false; StubModule.TestHarness = new List <Person> { new Person { Id = 1, Email = "*****@*****.**" } }; RestRequest target = new RestRequest(HttpMethod.GET, new RestUri(_MyUri, "/Person/{id}").SetParameter("id", "1")); //Act RestResponse <Person> response = null; //A completely synchronous GetResponse cannot be aborted. //So, spining off a new thread.. And balancing the times between GetResponse() and Abort() methods. var task = Task.Factory.StartNew(() => { response = target.GetResponse <Person>(); }); Thread.Sleep(500); target.Abort(); task.Wait(); //Assert Assert.NotNull(response); Assert.NotNull(response.Error); Assert.Equal("The request was aborted: The request was canceled.", response.Error.InnerException.Message); Assert.Equal(0, (int)response.Error.StatusCode); }
public void GetAsyncOfTAborted() { //Arrange StubModule.HaltProcessing = TimeSpan.FromSeconds(0); StubModule.GetPerson = false; StubModule.TestHarness = new List <Person> { new Person { Id = 1, Email = "*****@*****.**" } }; RestRequest target = new RestRequest(HttpMethod.GET, new RestUri(_MyUri, "/Person/{id}").SetParameter("id", "1")); //Act var response = target.GetResponseAsync <Person>(); target.Abort(); //Assert Assert.NotNull(response.Result); Assert.NotNull(response.Result.Error); Assert.Equal("The request was aborted: The request was canceled.", response.Result.Error.InnerException.Message); Assert.Equal(0, (int)response.Result.Error.StatusCode); }
public void GetAsyncOfTAborted() { //Arrange StubModule.HaltProcessing = TimeSpan.FromSeconds(0); StubModule.GetPerson = false; StubModule.TestHarness = new List<Person> { new Person { Id = 1, Email = "*****@*****.**" } }; RestRequest target = new RestRequest(HttpMethod.GET, new RestUri(_MyUri, "/Person/{id}").SetParameter("id", "1")); //Act var response = target.GetResponseAsync<Person>(); target.Abort(); //Assert Assert.NotNull(response.Result); Assert.NotNull(response.Result.Error); Assert.Equal("The request was aborted: The request was canceled.", response.Result.Error.InnerException.Message); Assert.Equal(0, (int)response.Result.Error.StatusCode); }