public void Execute() { try { foreach (var endpointEvent in this.EndpointEvents) { string url = $"{endpointEvent.Endpoint.Protocol}://{endpointEvent.Endpoint.Host}:{endpointEvent.Endpoint.Port}/{endpointEvent.Event.Path}"; this.Logger.LogDebug(url); dynamic response; dynamic body = JsonUtility.Deserialize <dynamic>(endpointEvent.Event.Body); switch (endpointEvent.Event.EnumType) { case EventType.Get: response = RestfulUtility.Get <dynamic>(url, new List <Header> { }); break; case EventType.Post: response = RestfulUtility.Post <dynamic, dynamic>(url, new Package <dynamic> { Headers = new List <Header> { }, Body = body }); break; case EventType.Put: response = RestfulUtility.Put <dynamic, dynamic>(url, new Package <dynamic> { Headers = new List <Header> { }, Body = body }); break; case EventType.Patch: response = RestfulUtility.Patch <dynamic, dynamic>(url, new Package <dynamic> { Headers = new List <Header> { }, Body = body }, "application/json-patch+json"); break; case EventType.Delete: response = RestfulUtility.Delete <dynamic>(url, new List <Header> { }); break; default: break; } } } catch (Exception exception) { this.Logger.LogError(exception.Message); } }
public void TestRestfulUtilityPost() { string url = $"{this.BaseUrl}/post"; string token = "<token>"; var response = RestfulUtility.Post <Request, Response>(url, token, new Package <Request> { Headers = new List <Header> { new Header { Key = "Trace-Id", Value = "FEWBOX001" } }, Body = new Request { Name = "FewBox" } }); Assert.IsNotNull(response); Assert.AreEqual($"Bearer {token}", response.Headers["Authorization"].Value); Assert.AreEqual($"FEWBOX001", response.Headers["Trace-Id"].Value); Assert.AreEqual($"FewBox", response.Json["Name"].Value); Assert.AreEqual($"FewBox", JsonUtility.Deserialize <Request>(response.Data).Name); }