generated from arcus-azure/arcus.github.template
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: added LoggingOptionTests for AzureFunctionsHttpProject
- Loading branch information
Showing
1 changed file
with
82 additions
and
0 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
src/Arcus.Templates.Tests.Integration/AzureFunctions/Http/Logging/LoggingOptionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
); | ||
} | ||
} | ||
} |