Esempio n. 1
0
        public async Task SimpleHttpFunctionWithBodyTest()
        {
            // Mock http request with body and empty query params
            mockRequest = mockManager.CreateMockRequest(mockRequestParam, person);

            var response = await simpleHttpFunction.Run(mockRequest.Object, log.Object);

            var responsevalue = ((OkObjectResult)response).Value as string;

            Assert.IsInstanceOfType(response, typeof(OkObjectResult));
            Assert.AreEqual($"Hello, {simpleManager.ToUpperCase(person.Name)}.", responsevalue);
        }
Esempio n. 2
0
        public void SimpleManagerToUpperCaseTest()
        {
            string name          = "Ivy";
            string nameUpperCase = "IVY";

            // Names are not the same (case sensetive)
            Assert.AreNotEqual(name, nameUpperCase);

            name = simpleManager.ToUpperCase(name);

            // Names should be the same now
            Assert.AreEqual(name, nameUpperCase);
        }
Esempio n. 3
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "simplehttpfunction")] HttpRequest req,
            ILogger log)
        {
            try
            {
                log.LogInformation("SimpleHttpFunction: C# HTTP trigger function processed a request.");

                string name = req.Query["name"];

                string  requestBody = await new StreamReader(req.Body).ReadToEndAsync();
                dynamic data        = JsonConvert.DeserializeObject(requestBody);
                name = name ?? data?.name;

                return(name != null
                    ? (ActionResult) new OkObjectResult($"Hello, {_simpleManager.ToUpperCase(name)}.")
                    : new BadRequestObjectResult("Please pass a name on the query string or in the request body"));
            }
            catch (Exception ex)
            {
                log.LogError(ex, ex.Message);
                return(new BadRequestObjectResult($"Error in SimpleHttpFunction: {ex.Message}"));
            }
        }