public async Task DeleteShouldIssueADeleteHttpRequest() { using (var httpTest = new HttpTest()) { var validationClient = new EmailValidationsRestClient(new DummyRestClientFactory()); var validationId = Guid.Parse("a3706a81-87da-4762-a135-dabaac6e6971"); await validationClient.DeleteAsync(validationId); httpTest.ShouldHaveCalled($"{DummyRestClientFactory.SoleUri}/email-validations/{validationId:D}"); } }
public async Task RetrieveShouldReturnNullForHttp404() { using (var httpTest = new HttpTest()) { httpTest.RespondWithJson(new { }, 404); var validationClient = new EmailValidationsRestClient(new DummyRestClientFactory()); var validationId = Guid.Parse("a3706a81-87da-4762-a135-dabaac6e6971"); var response = await validationClient.GetAsync(validationId); Assert.Null(response); } }
public async Task ShouldWaitForCompletionOnInProgress() { var noOfInProgressReplies = 5; using (var httpTest = new HttpTest()) { var fakeValidationId = Guid.Parse("a3706a81-87da-4762-a135-dabaac6e6971"); // Reply for a few times with an in-progress status codes for (var i = 0; i < noOfInProgressReplies; i++) { httpTest.RespondWithJson(new { overview = new { id = fakeValidationId, status = "in-progress" } }, 202); } // Then report the completion of the job httpTest.RespondWithJson(new { overview = new { id = fakeValidationId, status = "completed" } }, 200); // Fetch the job and poll until it's done var validationRestClient = new EmailValidationsRestClient(new DummyRestClientFactory()); var validation = await validationRestClient.GetAsync(fakeValidationId, new WaitingStrategy(true)); // Did we make the expected number of requests? Assert.Equal(noOfInProgressReplies + 1, httpTest.CallLog.Count); Assert.Equal(ValidationStatus.Completed, validation.Overview.Status); } }
public async Task ShouldHandleQueryOfInProgressJobs() { using (var httpTest = new HttpTest()) { var validationId = Guid.Parse("a3706a81-87da-4762-a135-dabaac6e6971"); httpTest.RespondWithJson(new { overview = new { id = validationId, status = "InProgress" } }, 202); var validationClient = new EmailValidationsRestClient(new DummyRestClientFactory()); var response = await validationClient.GetAsync(validationId); Assert.Equal(ValidationStatus.InProgress, response.Overview.Status); } }