public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "Customers/{customerId}/Interactions/{interactionId}/WebChats")] HttpRequestMessage req, ILogger log, string customerId, string interactionId, [Inject] IResourceHelper resourceHelper, [Inject] IHttpRequestMessageHelper httpRequestMessageHelper, [Inject] IGetWebChatHttpTriggerService webChatGetService) { var touchpointId = httpRequestMessageHelper.GetTouchpointId(req); if (string.IsNullOrEmpty(touchpointId)) { log.LogInformation("Unable to locate 'TouchpointId' in request header."); return(HttpResponseMessageHelper.BadRequest()); } log.LogInformation("Get Web Chat C# HTTP trigger function processed a request. By Touchpoint. " + touchpointId); if (!Guid.TryParse(customerId, out var customerGuid)) { return(HttpResponseMessageHelper.BadRequest(customerGuid)); } if (!Guid.TryParse(interactionId, out var interactionGuid)) { return(HttpResponseMessageHelper.BadRequest(interactionGuid)); } var doesCustomerExist = await resourceHelper.DoesCustomerExist(customerGuid); if (!doesCustomerExist) { return(HttpResponseMessageHelper.NoContent(customerGuid)); } var doesInteractionExist = resourceHelper.DoesInteractionResourceExistAndBelongToCustomer(interactionGuid, customerGuid); if (!doesInteractionExist) { return(HttpResponseMessageHelper.NoContent(interactionGuid)); } var webChats = await webChatGetService.GetWebChatsForCustomerAsync(customerGuid, interactionGuid); return(webChats == null? HttpResponseMessageHelper.NoContent(customerGuid) : HttpResponseMessageHelper.Ok(JsonHelper.SerializeObjects(webChats))); }
public void Setup() { _request = new HttpRequestMessage() { Content = new StringContent(string.Empty), RequestUri = new Uri($"http://localhost:7071/api/Customers/7E467BDB-213F-407A-B86A-1954053D3C24/WebChats" + $"Customers/7E467BDB-213F-407A-B86A-1954053D3C24/" + $"Interactions/1e1a555c-9633-4e12-ab28-09ed60d51cb3/" + $"WebChats") }; _log = Substitute.For <ILogger>(); _resourceHelper = Substitute.For <IResourceHelper>(); _getWebChatHttpTriggerService = Substitute.For <IGetWebChatHttpTriggerService>(); _httpRequestMessageHelper = Substitute.For <IHttpRequestMessageHelper>(); _httpRequestMessageHelper.GetTouchpointId(_request).Returns("0000000001"); }