Esempio n. 1
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "Customers/{customerId}/ActionPlans")] HttpRequestMessage req, ILogger log, string customerId,
                                                           [Inject] IResourceHelper resourceHelper,
                                                           [Inject] IHttpRequestMessageHelper httpRequestMessageHelper,
                                                           [Inject] IGetActionPlanHttpTriggerService actionPlanGetService)
        {
            var touchpointId = httpRequestMessageHelper.GetTouchpointId(req);

            if (string.IsNullOrEmpty(touchpointId))
            {
                log.LogInformation("Unable to locate 'TouchpointId' in request header");
                return(HttpResponseMessageHelper.BadRequest());
            }

            log.LogInformation("Get Action Plan 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 actionPlans = await actionPlanGetService.GetActionPlansAsync(customerGuid);

            return(actionPlans == null?
                   HttpResponseMessageHelper.NoContent(customerGuid) :
                       HttpResponseMessageHelper.Ok(JsonHelper.SerializeObjects(actionPlans)));
        }
        public void Setup()
        {
            _request = new HttpRequestMessage()
            {
                Content    = new StringContent(string.Empty),
                RequestUri =
                    new Uri($"http://localhost:7071/api/Customers/7E467BDB-213F-407A-B86A-1954053D3C24/ActionPlans")
            };

            _log            = Substitute.For <ILogger>();
            _resourceHelper = Substitute.For <IResourceHelper>();
            _getActionPlanHttpTriggerService = Substitute.For <IGetActionPlanHttpTriggerService>();
            _httpRequestMessageHelper        = Substitute.For <IHttpRequestMessageHelper>();
            _httpRequestMessageHelper.GetTouchpointId(_request).Returns("0000000001");
        }