Ejemplo n.º 1
0
        public async Task GetGoalByIdHttpTrigger_ReturnsStatusCodeOk_WhenGoalDoesNotExist()
        {
            _resourceHelper.DoesCustomerExist(Arg.Any <Guid>()).Returns(true);
            _resourceHelper.DoesInteractionExistAndBelongToCustomer(Arg.Any <Guid>(), Arg.Any <Guid>()).Returns(true);
            _resourceHelper.DoesActionPlanExistAndBelongToCustomer(Arg.Any <Guid>(), Arg.Any <Guid>(), Arg.Any <Guid>()).Returns(true);

            _getGoalByIdHttpTriggerService.GetGoalForCustomerAsync(Arg.Any <Guid>(), Arg.Any <Guid>()).Returns(Task.FromResult <Models.Goal>(null).Result);

            // Act
            var result = await RunFunction(ValidCustomerId, ValidInteractionId, ValidActionPlanId, ValidGoalId);

            // Assert
            Assert.IsInstanceOf <HttpResponseMessage>(result);
            Assert.AreEqual(HttpStatusCode.NoContent, result.StatusCode);
        }
Ejemplo n.º 2
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "Customers/{customerId}/Interactions/{interactionId}/ActionPlans/{actionPlanId}/Goals/{goalId}")] HttpRequestMessage req, ILogger log, string customerId, string interactionId, string actionPlanId, string goalId,
                                                           [Inject] IResourceHelper resourceHelper,
                                                           [Inject] IHttpRequestMessageHelper httpRequestMessageHelper,
                                                           [Inject] IGetGoalByIdHttpTriggerService goalGetService)
        {
            var touchpointId = httpRequestMessageHelper.GetTouchpointId(req);

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

            log.LogInformation("Get Goal By Id C# HTTP trigger function  processed a request. " + touchpointId);

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

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

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

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

            var doesCustomerExist = await resourceHelper.DoesCustomerExist(customerGuid);

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

            var doesInteractionExist = resourceHelper.DoesInteractionExistAndBelongToCustomer(interactionGuid, customerGuid);

            if (!doesInteractionExist)
            {
                return(HttpResponseMessageHelper.NoContent(interactionGuid));
            }

            var doesActionPlanExist = resourceHelper.DoesActionPlanExistAndBelongToCustomer(actionPlanGuid, interactionGuid, customerGuid);

            if (!doesActionPlanExist)
            {
                return(HttpResponseMessageHelper.NoContent(actionPlanGuid));
            }

            var action = await goalGetService.GetGoalForCustomerAsync(customerGuid, goalGuid);

            return(action == null?
                   HttpResponseMessageHelper.NoContent(customerGuid) :
                       HttpResponseMessageHelper.Ok(JsonHelper.SerializeObject(action)));
        }