Esempio n. 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);
        }
Esempio n. 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."));
        }
Esempio n. 3
0
        public async void Health_check_is_not_healthy()
        {
            const string ExpectedBadHealthMessage = "Bad health mess.";

            var fakeApiAuthorization = new FakeApiAuthorizationService()
            {
                BadHealthMessageForTests = ExpectedBadHealthMessage
            };

            HttpRequest httpRequest = HttpRequestFactoryFixture.CreateHttpGetRequest();

            var listLogger = new ListLoggerFixture();

            var func = new HealthCheckFunction(fakeApiAuthorization);

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

            Assert.NotNull(actionResult);

            Assert.IsType <OkObjectResult>(actionResult);

            Assert.IsType <HealthCheckResult>(((OkObjectResult)actionResult).Value);

            var healthCheckResult = (HealthCheckResult)((OkObjectResult)actionResult).Value;

            Assert.False(healthCheckResult.IsHealthy);
            Assert.Equal(ExpectedBadHealthMessage, healthCheckResult.BadHealthMessage);

            Assert.NotEmpty(listLogger.LogEntries);

            Assert.True(listLogger.HasLogEntryMessageThatStartsWith(
                            LogLevel.Error,
                            $"{nameof(HealthCheckFunction)} health check failed."));
        }
Esempio n. 4
0
        public async void Authorization_fail_returns_UnauthorizedResult()
        {
            const string ExpectedFailureReason = "some reason to fail.";

            var fakeApiAuthorization = new FakeApiAuthorizationService()
            {
                // Setup for athuorization fails.
                ApiAuthorizationResultForTests = new ApiAuthorizationResult(ExpectedFailureReason)
            };

            HttpRequest httpRequest = HttpRequestFactoryFixture.CreateHttpGetRequest(
                "name",   // quertyStringKey doesn't matter.
                "world"); // quertyStringValue doesn't matter.

            var listLogger = new ListLoggerFixture();

            var func = new HelloFunction(fakeApiAuthorization);

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

            Assert.NotNull(actionResult);

            Assert.IsType <UnauthorizedResult>(actionResult);

            Assert.NotEmpty(listLogger.LogEntries);

            Assert.True(listLogger.HasLogEntryMessageContaining(
                            LogLevel.Warning,
                            ExpectedFailureReason));
        }
Esempio n. 5
0
        public async void Health_check_is_healthy()
        {
            var fakeApiAuthorization = new FakeApiAuthorizationService();

            HttpRequest httpRequest = HttpRequestFactoryFixture.CreateHttpGetRequest();

            var listLogger = new ListLoggerFixture();

            var func = new HealthCheckFunction(fakeApiAuthorization);

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

            Assert.NotNull(actionResult);

            Assert.IsType <OkObjectResult>(actionResult);

            Assert.IsType <HealthCheckResult>(((OkObjectResult)actionResult).Value);

            var healthCheckResult = (HealthCheckResult)((OkObjectResult)actionResult).Value;

            Assert.True(healthCheckResult.IsHealthy);
            Assert.Null(healthCheckResult.BadHealthMessage);
        }