Skip to content

Commit

Permalink
tests: added LoggingOptionTests for AzureFunctionsHttpProject
Browse files Browse the repository at this point in the history
  • Loading branch information
spasal committed Jan 12, 2022
1 parent 3286e67 commit 891ebc6
Showing 1 changed file with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// Initializes a new instance of the <see cref="LoggingOptionTests"/> class.
/// </summary>
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<CannotStartTemplateProjectException>(
// Act
() => AzureFunctionsHttpProject.StartNewAsync(_configuration, _outputWriter)
);
}
}
}

0 comments on commit 891ebc6

Please sign in to comment.