mirror of
https://github.com/Azure/DotNetty.git
synced 2026-10-20 15:42:30 +08:00
797629ac1b
* Add some missing method to LoggingHandler * Avoid to alloc an huge error message when the test not failed. * Update the unittest * Update Microsoft.NET.Test.Sdk from 15.0.0 to 15.7.2, fix that unable to debug an unittest for the second time. * Disable parallelization for InternalLoggerFactoryTest.TestMockReturned to avoid an rare test failure. * Remove `dotnet-xunit` since it's never used and will be discontinued, see https://xunit.github.io/releases/2.4-beta2 * Remove space from filename * Switch back to `DiscardSomeReadBytes` since it's avaliable * Rework some logic in TlsHandler * Make sure TlsHandler.MediationStream works well with different style of aync calls(Still not work for Mono, see #374) * Rework some logic in #366, now always close TlsHandler.MediationStream in TlsHandler.HandleFailure since it's never exported. * Workaround to fix issue 'Microsoft/vstest#1129'. * Change the default of TcpServerSocketChannel.Metadata.defaultMaxMessagesPerRead to 1
62 lines
2.3 KiB
C#
62 lines
2.3 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
namespace DotNetty.Common.Tests.Internal.Logging
|
|
{
|
|
using System;
|
|
using DotNetty.Common.Internal.Logging;
|
|
using DotNetty.Tests.Common;
|
|
using Microsoft.Extensions.Logging;
|
|
using Moq;
|
|
using Xunit;
|
|
|
|
[CollectionDefinition(nameof(InternalLoggerFactoryTest), DisableParallelization = true)]
|
|
public class InternalLoggerFactoryTest
|
|
{
|
|
// todo: CodeContracts on CI
|
|
//[Fact]
|
|
//public void ShouldNotAllowNullDefaultFactory()
|
|
//{
|
|
// Assert.ThrowsAny<Exception>(() => InternalLoggerFactory.DefaultFactory = null);
|
|
//}
|
|
|
|
[Fact]
|
|
public void ShouldGetInstance()
|
|
{
|
|
IInternalLogger one = InternalLoggerFactory.GetInstance("helloWorld");
|
|
IInternalLogger two = InternalLoggerFactory.GetInstance<string>();
|
|
|
|
Assert.NotNull(one);
|
|
Assert.NotNull(two);
|
|
Assert.NotSame(one, two);
|
|
}
|
|
|
|
[Fact]
|
|
public void TestMockReturned()
|
|
{
|
|
Mock<ILogger> mock;
|
|
using (SetupMockLogger(out mock))
|
|
{
|
|
mock.Setup(x => x.IsEnabled(LogLevel.Trace)).Returns(true).Verifiable();
|
|
|
|
IInternalLogger logger = InternalLoggerFactory.GetInstance("mock");
|
|
|
|
Assert.True(logger.TraceEnabled);
|
|
mock.Verify(x => x.IsEnabled(LogLevel.Trace), Times.Once);
|
|
}
|
|
}
|
|
|
|
static IDisposable SetupMockLogger(out Mock<ILogger> loggerMock)
|
|
{
|
|
ILoggerFactory oldLoggerFactory = InternalLoggerFactory.DefaultFactory;
|
|
var loggerFactory = new LoggerFactory();
|
|
var factoryMock = new Mock<ILoggerProvider>(MockBehavior.Strict);
|
|
ILoggerProvider mockFactory = factoryMock.Object;
|
|
loggerMock = new Mock<ILogger>(MockBehavior.Strict);
|
|
loggerFactory.AddProvider(mockFactory);
|
|
factoryMock.Setup(x => x.CreateLogger("mock")).Returns(loggerMock.Object);
|
|
InternalLoggerFactory.DefaultFactory = loggerFactory;
|
|
return new Disposable(() => InternalLoggerFactory.DefaultFactory = oldLoggerFactory);
|
|
}
|
|
}
|
|
} |