Пример #1
0
        [InlineData("{ \"name\": \" \" }")] // Just a space for name value.
        public async void No_name_returns_BadRequestObjectResult_with_help_text(string jsonBody)
        {
            var fakeApiAuthorizationService = new FakeApiAuthorizationService()
            {
                // Setup to fake athuorization success.
                ApiAuthorizationResultForTests = new ApiAuthorizationResult()
            };

            HttpRequest httpRequest = HttpRequestFactoryFixture.CreateHttpPostRequest(
                jsonBody);

            var listLogger = new ListLoggerFixture();

            var func = new HelloFunction(fakeApiAuthorizationService);

            IActionResult actionResult = await func.Run(httpRequest, listLogger);

            Assert.NotNull(actionResult);

            Assert.IsType <BadRequestObjectResult>(actionResult);

            Assert.Equal("Please pass a name the request body.", ((BadRequestObjectResult)actionResult).Value);

            Assert.NotEmpty(listLogger.LogEntries);
        }
Пример #2
0
        public async void Happy_path_returns_OkObjectResult_with_hello_text()
        {
            const string ExpecetedName = "Some Name";

            var fakeApiAuthorization = new FakeApiAuthorizationService()
            {
                // Setup to fake athuorization success.
                ApiAuthorizationResultForTests = new ApiAuthorizationResult()
            };

            string jsonBody = $"{{ \"name\": \"{ExpecetedName}\" }}";

            HttpRequest httpRequest = HttpRequestFactoryFixture.CreateHttpPostRequest(
                jsonBody);

            var listLogger = new ListLoggerFixture();

            var func = new HelloFunction(fakeApiAuthorization);

            IActionResult actionResult = await func.Run(httpRequest, listLogger);

            Assert.NotNull(actionResult);

            Assert.IsType <OkObjectResult>(actionResult);

            Assert.Equal($"Hello, {ExpecetedName}", ((OkObjectResult)actionResult).Value);

            Assert.NotEmpty(listLogger.LogEntries);

            Assert.True(listLogger.HasLogEntryMessageContaining(
                            LogLevel.Warning,
                            $"HTTP trigger function {nameof(HelloFunction)} rquest is authorized."));
        }