public async Task GetAddressHttpTrigger_ReturnsStatusCodeNoContent_WhenAddressDoesNotExist() { _resourceHelper.DoesCustomerExist(Arg.Any <Guid>()).Returns(true); _getAddressHttpTriggerService.GetAddressesAsync(Arg.Any <Guid>()).Returns(Task.FromResult <List <Models.Address> >(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}/Addresses")] HttpRequestMessage req, ILogger log, string customerId, [Inject] IResourceHelper resourceHelper, [Inject] IHttpRequestMessageHelper httpRequestMessageHelper, [Inject] IGetAddressHttpTriggerService getAddressService) { var touchpointId = httpRequestMessageHelper.GetTouchpointId(req); if (string.IsNullOrEmpty(touchpointId)) { log.LogInformation("Unable to locate 'TouchpointId' in request header"); return(HttpResponseMessageHelper.BadRequest()); } log.LogInformation("Get Address C# HTTP trigger function processed a request. By Touchpoint " + 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 addresses = await getAddressService.GetAddressesAsync(customerGuid); return(addresses == null? HttpResponseMessageHelper.NoContent(customerGuid) : HttpResponseMessageHelper.Ok(JsonHelper.SerializeObjects(addresses))); }