Beispiel #1
0
        public async Task GetAddressByIdHttpTrigger_ReturnsStatusCodeNoContent_WhenAddressDoesNotExist()
        {
            _resourceHelper.DoesCustomerExist(Arg.Any <Guid>()).Returns(true);

            _getAddressByIdHttpTriggerService.GetAddressForCustomerAsync(Arg.Any <Guid>(), Arg.Any <Guid>()).Returns(Task.FromResult <Models.Address>(null).Result);

            // Act
            var result = await RunFunction(ValidCustomerId, ValidAddressId);

            // Assert
            Assert.IsInstanceOf <HttpResponseMessage>(result);
            Assert.AreEqual(HttpStatusCode.NoContent, result.StatusCode);
        }
Beispiel #2
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "Customers/{customerId}/Addresses/{addressId}")] HttpRequestMessage req, ILogger log, string customerId, string addressId,
                                                           [Inject] IResourceHelper resourceHelper,
                                                           [Inject] IHttpRequestMessageHelper httpRequestMessageHelper,
                                                           [Inject] IGetAddressByIdHttpTriggerService getAddressByIdService)
        {
            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 By Id C# HTTP trigger function  processed a request. By Touchpoint " + touchpointId);

            if (!Guid.TryParse(customerId, out var customerGuid))
            {
                return(HttpResponseMessageHelper.BadRequest(customerGuid));
            }

            if (!Guid.TryParse(addressId, out var addressGuid))
            {
                return(HttpResponseMessageHelper.BadRequest(addressGuid));
            }

            var doesCustomerExist = await resourceHelper.DoesCustomerExist(customerGuid);

            if (!doesCustomerExist)
            {
                return(HttpResponseMessageHelper.NoContent(customerGuid));
            }

            var address = await getAddressByIdService.GetAddressForCustomerAsync(customerGuid, addressGuid);

            return(address == null?
                   HttpResponseMessageHelper.NoContent(addressGuid) :
                       HttpResponseMessageHelper.Ok(JsonHelper.SerializeObject(address)));
        }