-
Notifications
You must be signed in to change notification settings - Fork 766
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
1 parent
fe00658
commit 5fc421c
Showing
12 changed files
with
120 additions
and
35 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
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
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
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
69 changes: 69 additions & 0 deletions
69
...Libraries/Microsoft.Extensions.Telemetry.Tests/Buffering/LoggerFilterRuleSelectorTests.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,69 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.Extensions.Diagnostics.Buffering; | ||
using Xunit; | ||
|
||
namespace Microsoft.Extensions.Logging.Test; | ||
public class LoggerFilterRuleSelectorTests | ||
{ | ||
[Fact] | ||
public void SelectsRightRule() | ||
{ | ||
// Arrange | ||
var rules = new List<ILoggerFilterRule> | ||
{ | ||
new BufferFilterRule(null, null, null, null), | ||
new BufferFilterRule(null, null, 1, null), | ||
new BufferFilterRule(null, LogLevel.Information, 1, null), | ||
new BufferFilterRule(null, LogLevel.Information, 1, null), | ||
new BufferFilterRule(null, LogLevel.Warning, null, null), | ||
new BufferFilterRule(null, LogLevel.Warning, 2, null), | ||
new BufferFilterRule(null, LogLevel.Warning, 1, null), | ||
new BufferFilterRule("Program1.MyLogger", LogLevel.Warning, 1, null), | ||
new BufferFilterRule("Program.*MyLogger1", LogLevel.Warning, 1, null), | ||
new BufferFilterRule("Program.MyLogger", LogLevel.Warning, 1), // the best rule | ||
new BufferFilterRule("Program.MyLogger", LogLevel.Warning, 2, null), | ||
new BufferFilterRule("Program.MyLogger", null, 1, null), | ||
new BufferFilterRule(null, LogLevel.Warning, 1, null), | ||
new BufferFilterRule("Program", LogLevel.Warning, 1, null), | ||
new BufferFilterRule("Program.MyLogger", LogLevel.Warning, null, null), | ||
new BufferFilterRule("Program.MyLogger", LogLevel.Error, 1, null), | ||
}; | ||
|
||
// Act | ||
LoggerFilterRuleSelector.Select( | ||
rules, "Program.MyLogger", LogLevel.Warning, 1, out var actualResult); | ||
|
||
// Assert | ||
Assert.Same(rules[9], actualResult); | ||
} | ||
|
||
[Fact] | ||
public void WhenManyRuleApply_SelectsLast() | ||
{ | ||
// Arrange | ||
var rules = new List<ILoggerFilterRule> | ||
{ | ||
new BufferFilterRule(null, LogLevel.Information, 1, null), | ||
new BufferFilterRule(null, LogLevel.Information, 1, null), | ||
new BufferFilterRule(null, LogLevel.Warning, null, null), | ||
new BufferFilterRule(null, LogLevel.Warning, 2, null), | ||
new BufferFilterRule(null, LogLevel.Warning, 1, null), | ||
new BufferFilterRule("Program1.MyLogger", LogLevel.Warning, 1, null), | ||
new BufferFilterRule("Program.*MyLogger1", LogLevel.Warning, 1, null), | ||
new BufferFilterRule("Program.MyLogger", LogLevel.Warning, 1, null), | ||
new BufferFilterRule("Program.MyLogger*", LogLevel.Warning, 1, null), | ||
new BufferFilterRule("Program.MyLogger", LogLevel.Warning, 1), // the best rule | ||
new BufferFilterRule("Program.MyLogger*", LogLevel.Warning, 1), // same as the best, but last and should be selected | ||
}; | ||
|
||
// Act | ||
LoggerFilterRuleSelector.Select(rules, "Program.MyLogger", LogLevel.Warning, 1, out var actualResult); | ||
|
||
// Assert | ||
Assert.Same(rules.Last(), actualResult); | ||
} | ||
} |