-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
53 additions
and
4 deletions.
There are no files selected for viewing
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
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
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,40 @@ | ||
using System; | ||
using System.IO; | ||
using Kiota.Builder.Logging; | ||
using Microsoft.Extensions.Logging; | ||
using Xunit; | ||
|
||
namespace Kiota.Builder.Tests.Logging; | ||
|
||
public sealed class FileLoggerTests : IDisposable | ||
{ | ||
private readonly string _logDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); | ||
public FileLoggerTests() | ||
{ | ||
Directory.CreateDirectory(_logDirectory); | ||
} | ||
[Fact] | ||
public void CleansUpFileWhenNoLogs() | ||
{ | ||
using (var logger = new FileLogLogger(_logDirectory, LogLevel.Warning, "test")) | ||
{ //using this format intentionally to ensure the dispose is called before the assert | ||
logger.LogInformation("test"); | ||
} | ||
Assert.False(File.Exists(Path.Combine(_logDirectory, FileLogLogger.LogFileName))); | ||
} | ||
[Fact] | ||
public void KeepsLogFileWhenLogs() | ||
{ | ||
using (var logger = new FileLogLogger(_logDirectory, LogLevel.Warning, "test")) | ||
{ //using this format intentionally to ensure the dispose is called before the assert | ||
logger.LogWarning("test"); | ||
} | ||
Assert.True(File.Exists(Path.Combine(_logDirectory, FileLogLogger.LogFileName))); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
if (Directory.Exists(_logDirectory)) | ||
Directory.Delete(_logDirectory, true); | ||
} | ||
} |