public void OnSendMessage404() { var wrongPort = 8083; var request = Requests.Create(new RequestConfig($"http://localhost:{wrongPort}/resource", "GET")); var response = request.Send().Result; Assert.AreEqual(404, response.Status); }
public async Task <String> Publish(Stream fileStream, IProgress <GfycatProgress> reporter) { // Using noMd5 here to skip gfycat's dupe check. // In the case of a dupe being detected, the status request will return back // the details about the dupe which is not currently handled. // // In real code, you can extend this to include things like titles and descriptions. // See api docs for more details. var createRequest = new GfycatCreateRequest() { noMd5 = true, }; // Create the gfycat reporter.Report(new GfycatProgress("Creating gfycat")); var createResponse = await Requests.Create(createRequest); if (!createResponse.IsOk) { throw new InvalidOperationException("Something went wrong, send help."); } // Upload the file reporter.Report(new GfycatProgress("Uploading file")); Requests.Upload(createResponse.GfyName, fileStream); while (true) { var statusResponse = await Requests.Status(createResponse.GfyName); switch (statusResponse.Task) { case "NotFoundo": // This happening once is expected because there is a gap between // when the file is uploaded, and when gfycat detects it. // // In real code, publish should fail if this happens too many times. await Task.Delay(1000); break; case "encoding": reporter.Report(new GfycatProgress("Encoding", statusResponse.Progress)); await Task.Delay(1000); break; case "complete": reporter.Report(new GfycatProgress("Complete")); return(statusResponse.GfyName); case "error": default: throw new InvalidOperationException("Something went wrong, send help."); } } }
public void TestCreateInfoCancel() { var create = r.Create("812-174-9528", 0.01, altToken: "raopmI6N9UIq87uWqhXB5v7xIgi49EH3K3qSFwtoZ/CzcBCN+l"); Assert.IsInstanceOfType(create, typeof(int)); var info = r.Info(create.ToString(), altToken: "raopmI6N9UIq87uWqhXB5v7xIgi49EH3K3qSFwtoZ/CzcBCN+l"); Assert.IsInstanceOfType(info, typeof(Request)); var cancel = r.Cancel(create.ToString(), altToken: "raopmI6N9UIq87uWqhXB5v7xIgi49EH3K3qSFwtoZ/CzcBCN+l"); Assert.IsInstanceOfType(cancel, typeof(string)); }
private async Task <TestResult> StartTest(SequenceDependencyLocator sequenceDependency, UniqueConfiguration item) { RequestConfig requestConfig = item.ToRequestConfig(); await sequenceDependency.ReplaceDependency(requestConfig); await sequenceDependency.ReplaceDependency(item.Validation); await sequenceDependency.Wait(item); var request = Requests.Create(requestConfig); OnTestStart?.Invoke(item.Name); var response = request.Send(); var testResult = new TestResult(item.Name, item.Validation, await response); OnTestFinished?.Invoke(testResult); return(testResult); }
public void OnSendMessageSucess() { var header = new Dictionary <string, string>() { { "Content-Type", "application/json" } }; var body = "{name: \"Robert\"}"; _server.ResponseBody = body; var cookies = new Dictionary <string, string>(); var queryString = new Dictionary <string, string>(); var request = Requests.Create(new RequestConfig($"http://localhost:{Port}/resource", "POST", header, cookies, queryString, body)); var response = request.Send().Result; Assert.AreEqual(200, response.Status); var reader = new JsonReader.JsonReaderBody(); reader.Read(body); Assert.IsTrue(reader.Read(body).Equals(response.Body)); }
public void OnCreate_ErrorOnSendBodyInGET() { try { var header = new Dictionary <string, string>() { { "Content-Type", "application/json" } }; var body = "{name: \"Robert\"}"; var cookies = new Dictionary <string, string>(); var queryString = new Dictionary <string, string>(); var request = Requests.Create(new RequestConfig($"http://localhost:{Port}/resource", "GET", header, cookies, queryString, body)); } catch { return; } Assert.Fail(); }