Skip to content

Commit

Permalink
Fix tests that would fail if run together
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisDyallo committed Aug 13, 2024
1 parent 8f056a6 commit c0dbd99
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions Yubico.Core/tests/Yubico/Core/Logging/LogTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,33 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using Microsoft.Extensions.Logging;
using Moq;
using Xunit;

namespace Yubico.Core.Logging
{
public class LogTests
public class LogTests : IDisposable
{
private readonly ILoggerFactory _originalFactory = Log.Instance;

#pragma warning disable CA1816
public void Dispose()
#pragma warning restore CA1816
{
// Reset to the original factory after each test
Log.Instance = _originalFactory;
}

// Ensure that the default LoggerFactory is created when no configuration is provided.
[Fact]
public void DefaultLoggerFactory_IsCreated_WhenNoConfigurationProvided()
{
// Act
ILoggerFactory loggerFactory = Log.Instance;

// Assert
Assert.NotNull(loggerFactory);
ILogger logger = loggerFactory.CreateLogger<LogTests>();
Expand All @@ -39,10 +51,10 @@ public void ManualLoggerFactory_SettingInstance_OverridesDefaultFactory()
// Arrange
var mockLoggerFactory = new Mock<ILoggerFactory>();
Log.Instance = mockLoggerFactory.Object;

// Act
ILoggerFactory actualFactory = Log.Instance;

// Assert
Assert.Same(mockLoggerFactory.Object, actualFactory);
}
Expand Down

0 comments on commit c0dbd99

Please sign in to comment.