public async Task GetDiversityHttpTrigger_ReturnsStatusCodeNoContent_WhenDiversityDetailDoesntExist() { _resourceHelper.DoesCustomerExist(Arg.Any <Guid>()).Returns(true); _getDiversityHttpTriggerService.GetDiversityDetailIdAsync(Arg.Any <Guid>()).Returns(Task.FromResult <Guid?>(null).Result); // Act var result = await RunFunction(ValidCustomerId); // Assert Assert.IsInstanceOf <HttpResponseMessage>(result); Assert.AreEqual(HttpStatusCode.NoContent, result.StatusCode); }
public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "Customers/{customerId}/DiversityDetails")] HttpRequestMessage req, ILogger log, string customerId, [Inject] IResourceHelper resourceHelper, [Inject] IHttpRequestMessageHelper httpRequestMessageHelper, [Inject] IGetDiversityHttpTriggerService getDiversityService) { var touchpointId = httpRequestMessageHelper.GetTouchpointId(req); if (string.IsNullOrEmpty(touchpointId)) { log.LogInformation("Unable to locate 'TouchpointId' in request header."); return(HttpResponseMessageHelper.BadRequest()); } log.LogInformation("C# HTTP trigger function processed a request. " + touchpointId); if (!Guid.TryParse(customerId, out var customerGuid)) { return(HttpResponseMessageHelper.BadRequest(customerGuid)); } var doesCustomerExist = await resourceHelper.DoesCustomerExist(customerGuid); if (!doesCustomerExist) { return(HttpResponseMessageHelper.NoContent(customerGuid)); } var diversityId = await getDiversityService.GetDiversityDetailIdAsync(customerGuid); return(diversityId == null? HttpResponseMessageHelper.NoContent(customerGuid) : HttpResponseMessageHelper.Ok(diversityId.Value)); }