From 891ebc61ccf607511e33a2093a2bd90de83bb24b Mon Sep 17 00:00:00 2001 From: Alex Spassov Simeonov Date: Wed, 12 Jan 2022 13:37:59 +0100 Subject: [PATCH] tests: added LoggingOptionTests for AzureFunctionsHttpProject --- .../Http/Logging/LoggingOptionTests.cs | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/Arcus.Templates.Tests.Integration/AzureFunctions/Http/Logging/LoggingOptionTests.cs diff --git a/src/Arcus.Templates.Tests.Integration/AzureFunctions/Http/Logging/LoggingOptionTests.cs b/src/Arcus.Templates.Tests.Integration/AzureFunctions/Http/Logging/LoggingOptionTests.cs new file mode 100644 index 00000000..537e949e --- /dev/null +++ b/src/Arcus.Templates.Tests.Integration/AzureFunctions/Http/Logging/LoggingOptionTests.cs @@ -0,0 +1,82 @@ +using System; +using System.Net; +using System.Net.Http; +using System.Threading.Tasks; +using Arcus.Templates.Tests.Integration.Fixture; +using Xunit; +using Xunit.Abstractions; + +namespace Arcus.Templates.Tests.Integration.AzureFunctions.Http.Logging +{ + [Collection(TestCollections.Integration)] + [Trait("Category", TestTraits.Integration)] + public class LoggingOptionTests + { + private readonly TestConfig _configuration; + private readonly ITestOutputHelper _outputWriter; + + /// + /// Initializes a new instance of the class. + /// + public LoggingOptionTests(ITestOutputHelper outputWriter) + { + _outputWriter = outputWriter; + _configuration = TestConfig.Create(); + } + + [Fact] + public async Task GetHealth_WithApplicationInsightsLogging_ReturnsOk() + { + // Arrange + var options = + new AzureFunctionsHttpProjectOptions() + .WithIncludeHealthChecks(); + + using (var project = await AzureFunctionsHttpProject.StartNewAsync(_configuration, options, _outputWriter)) + { + // Act + using (HttpResponseMessage response = await project.Health.GetAsync()) + { + // Assert + Assert.NotNull(response); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + } + } + } + + [Fact] + public async Task GetHealth_WithValidSerilogDefaultLogLevel_ReturnsOk() + { + // Arrange + var options = + new AzureFunctionsHttpProjectOptions() + .WithIncludeHealthChecks(); + + Environment.SetEnvironmentVariable("AzureFunctionsJobHost__Serilog__MinimumLevel__Default", "Information"); + + using (var project = await AzureFunctionsHttpProject.StartNewAsync(_configuration, options, _outputWriter)) + { + // Act + using (HttpResponseMessage response = await project.Health.GetAsync()) + { + // Assert + Assert.NotNull(response); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + } + } + } + + [Fact] + public async Task StartProject_WithInvalidSerilogDefaultLogLevel_ThrowsException() + { + // Arrange + Environment.SetEnvironmentVariable("AzureFunctionsJobHost__Serilog__MinimumLevel__Default", "InvalidLogLevel"); + + // Assert + await Assert.ThrowsAsync( + // Act + () => AzureFunctionsHttpProject.StartNewAsync(_configuration, _outputWriter) + ); + } + } +}