diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 8d3ee90..34b8852 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -21,6 +21,7 @@ jobs: env: Solution_Path: WpfExtended.sln Actions_Allow_Unsecure_Commands: true + Test_Project_Path: WpfExtended.Test\WpfExtended.Tests.csproj steps: - name: Checkout diff --git a/WpfExtended.Test/Configuration/DefaultOptionsManagerTests.cs b/WpfExtended.Test/Configuration/DefaultOptionsManagerTests.cs new file mode 100644 index 0000000..c8e06fa --- /dev/null +++ b/WpfExtended.Test/Configuration/DefaultOptionsManagerTests.cs @@ -0,0 +1,26 @@ +using FluentAssertions; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Windows.Extensions; + +namespace WpfExtended.Tests.Configuration +{ + [TestClass] + public class DefaultOptionsManagerTests + { + private readonly DefaultOptionsManager optionsManager = new(); + + [TestMethod] + public void GetOptions_ReturnsDefault() + { + var options = this.optionsManager.GetOptions(); + + options.Should().BeNull(); + } + + [TestMethod] + public void UpdateOptions_Succeeds() + { + this.optionsManager.UpdateOptions(string.Empty); + } + } +} diff --git a/WpfExtended.Test/Configuration/LiveOptionsResolverTests.cs b/WpfExtended.Test/Configuration/LiveOptionsResolverTests.cs new file mode 100644 index 0000000..fb7c57f --- /dev/null +++ b/WpfExtended.Test/Configuration/LiveOptionsResolverTests.cs @@ -0,0 +1,69 @@ +using FluentAssertions; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using System; +using System.Windows.Extensions; + +namespace WpfExtended.Tests.Configuration +{ + [TestClass] + public class LiveOptionsResolverTests + { + private readonly LiveOptionsResolver liveOptionsResolver = new(); + private readonly Mock serviceProviderMock = new(); + private readonly Mock optionsManagerMock = new(); + + [TestMethod] + public void CanResolve_ILiveOptions_ReturnsTrue() + { + var type = typeof(ILiveOptions); + + var canResolve = this.liveOptionsResolver.CanResolve(type); + + canResolve.Should().BeTrue(); + } + + [TestMethod] + public void CanResolve_AnythingElse_ReturnsFalse() + { + var types = new Type[] { typeof(object), typeof(string), typeof(LiveOptionsResolverTests), typeof(int) }; + + foreach (var type in types) + { + var canResolve = this.liveOptionsResolver.CanResolve(type); + + canResolve.Should().BeFalse(); + } + } + + [TestMethod] + public void Resolve_ILiveOptions_ReturnsILiveOptions() + { + this.SetupServiceProvider(); + + var liveOptions = this.liveOptionsResolver.Resolve(this.serviceProviderMock.Object, typeof(ILiveOptions)); + + liveOptions.Should().BeAssignableTo>(); + } + + [TestMethod] + public void Resolve_AnythingElse_Throws() + { + this.SetupServiceProvider(); + + Action action = new(() => + { + this.liveOptionsResolver.Resolve(this.serviceProviderMock.Object, typeof(string)); + }); + + action.Should().Throw(); + } + + private void SetupServiceProvider() + { + this.serviceProviderMock + .Setup(u => u.GetService()) + .Returns(this.optionsManagerMock.Object); + } + } +} diff --git a/WpfExtended.Test/Configuration/LiveUpdateableOptionsResolverTests.cs b/WpfExtended.Test/Configuration/LiveUpdateableOptionsResolverTests.cs new file mode 100644 index 0000000..7eb48a1 --- /dev/null +++ b/WpfExtended.Test/Configuration/LiveUpdateableOptionsResolverTests.cs @@ -0,0 +1,69 @@ +using FluentAssertions; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using System; +using System.Windows.Extensions; + +namespace WpfExtended.Tests.Configuration +{ + [TestClass] + public class LiveUpdateableOptionsResolverTests + { + private readonly LiveUpdateableOptionsResolver liveUpdateableOptionsResolver = new(); + private readonly Mock serviceProviderMock = new(); + private readonly Mock optionsManagerMock = new(); + + [TestMethod] + public void CanResolve_ILiveUpdateableOptions_ReturnsTrue() + { + var type = typeof(ILiveUpdateableOptions); + + var canResolve = this.liveUpdateableOptionsResolver.CanResolve(type); + + canResolve.Should().BeTrue(); + } + + [TestMethod] + public void CanResolve_AnythingElse_ReturnsFalse() + { + var types = new Type[] { typeof(object), typeof(string), typeof(LiveOptionsResolverTests), typeof(int) }; + + foreach (var type in types) + { + var canResolve = this.liveUpdateableOptionsResolver.CanResolve(type); + + canResolve.Should().BeFalse(); + } + } + + [TestMethod] + public void Resolve_ILiveUpdateableOptions_ReturnsILiveUpdateableOptions() + { + this.SetupServiceProvider(); + + var liveOptions = this.liveUpdateableOptionsResolver.Resolve(this.serviceProviderMock.Object, typeof(ILiveUpdateableOptions)); + + liveOptions.Should().BeAssignableTo>(); + } + + [TestMethod] + public void Resolve_AnythingElse_Throws() + { + this.SetupServiceProvider(); + + Action action = new(() => + { + this.liveUpdateableOptionsResolver.Resolve(this.serviceProviderMock.Object, typeof(string)); + }); + + action.Should().Throw(); + } + + private void SetupServiceProvider() + { + this.serviceProviderMock + .Setup(u => u.GetService()) + .Returns(this.optionsManagerMock.Object); + } + } +} diff --git a/WpfExtended.Test/Configuration/LiveUpdateableOptionsWrapperTests.cs b/WpfExtended.Test/Configuration/LiveUpdateableOptionsWrapperTests.cs new file mode 100644 index 0000000..878eab8 --- /dev/null +++ b/WpfExtended.Test/Configuration/LiveUpdateableOptionsWrapperTests.cs @@ -0,0 +1,44 @@ +using FluentAssertions; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using System.Windows.Extensions; + +namespace WpfExtended.Tests.Configuration +{ + [TestClass] + public class LiveUpdateableOptionsWrapperTests + { + private LiveUpdateableOptionsWrapper optionsWrapper; + private readonly Mock optionsManagerMock = new(); + + [TestInitialize] + public void TestInitialize() + { + this.optionsWrapper = new LiveUpdateableOptionsWrapper(optionsManagerMock.Object); + } + + [TestMethod] + public void GetValue_ReturnsValue() + { + this.optionsManagerMock + .Setup(u => u.GetOptions()) + .Returns("hello"); + + var value = this.optionsWrapper.Value; + + value.Should().Be("hello"); + } + + [TestMethod] + public void UpdateOption_CallsOptionsManager() + { + this.optionsManagerMock + .Setup(u => u.UpdateOptions(It.IsAny())) + .Verifiable(); + + this.optionsWrapper.UpdateOption(); + + this.optionsManagerMock.Verify(); + } + } +} diff --git a/WpfExtended.Test/Configuration/OptionsResolverTests.cs b/WpfExtended.Test/Configuration/OptionsResolverTests.cs new file mode 100644 index 0000000..9b5dc69 --- /dev/null +++ b/WpfExtended.Test/Configuration/OptionsResolverTests.cs @@ -0,0 +1,72 @@ +using FluentAssertions; +using Microsoft.Extensions.Options; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using System; +using System.Windows.Extensions; + +namespace WpfExtended.Tests.Configuration +{ + [TestClass] + public class OptionsResolverTests + { + private readonly OptionsResolver optionsResolver = new(); + private readonly Mock serviceProviderMock = new(); + private readonly Mock optionsManagerMock = new(); + + public Mock OptionsManagerMock => optionsManagerMock; + + [TestMethod] + public void CanResolve_ILiveOptions_ReturnsTrue() + { + var type = typeof(IOptions); + + var canResolve = this.optionsResolver.CanResolve(type); + + canResolve.Should().BeTrue(); + } + + [TestMethod] + public void CanResolve_AnythingElse_ReturnsFalse() + { + var types = new Type[] { typeof(object), typeof(string), typeof(OptionsResolverTests), typeof(int) }; + + foreach (var type in types) + { + var canResolve = this.optionsResolver.CanResolve(type); + + canResolve.Should().BeFalse(); + } + } + + [TestMethod] + public void Resolve_IOptions_ReturnsIOptions() + { + this.SetupServiceProvider(); + + var liveOptions = this.optionsResolver.Resolve(this.serviceProviderMock.Object, typeof(IOptions)); + + liveOptions.Should().BeAssignableTo>(); + } + + [TestMethod] + public void Resolve_AnythingElse_Throws() + { + this.SetupServiceProvider(); + + Action action = new(() => + { + this.optionsResolver.Resolve(this.serviceProviderMock.Object, typeof(string)); + }); + + action.Should().Throw(); + } + + private void SetupServiceProvider() + { + this.serviceProviderMock + .Setup(u => u.GetService()) + .Returns(this.OptionsManagerMock.Object); + } + } +} diff --git a/WpfExtended.Test/Configuration/UpdateableOptionsResolverTests.cs b/WpfExtended.Test/Configuration/UpdateableOptionsResolverTests.cs new file mode 100644 index 0000000..f6e2506 --- /dev/null +++ b/WpfExtended.Test/Configuration/UpdateableOptionsResolverTests.cs @@ -0,0 +1,73 @@ +using FluentAssertions; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Extensions; + +namespace WpfExtended.Tests.Configuration +{ + [TestClass] + public class UpdateableOptionsResolverTests + { + private readonly UpdateableOptionsResolver updateableOptionsResolver = new(); + private readonly Mock serviceProviderMock = new(); + private readonly Mock optionsManagerMock = new(); + + [TestMethod] + public void CanResolve_ILiveOptions_ReturnsTrue() + { + var type = typeof(IUpdateableOptions); + + var canResolve = this.updateableOptionsResolver.CanResolve(type); + + canResolve.Should().BeTrue(); + } + + [TestMethod] + public void CanResolve_AnythingElse_ReturnsFalse() + { + var types = new Type[] { typeof(object), typeof(string), typeof(UpdateableOptionsResolverTests), typeof(int) }; + + foreach (var type in types) + { + var canResolve = this.updateableOptionsResolver.CanResolve(type); + + canResolve.Should().BeFalse(); + } + } + + [TestMethod] + public void Resolve_IUpdateableOptions_ReturnsIUpdateableOptions() + { + this.SetupServiceProvider(); + + var liveOptions = this.updateableOptionsResolver.Resolve(this.serviceProviderMock.Object, typeof(IUpdateableOptions)); + + liveOptions.Should().BeAssignableTo>(); + } + + [TestMethod] + public void Resolve_AnythingElse_Throws() + { + this.SetupServiceProvider(); + + Action action = new(() => + { + this.updateableOptionsResolver.Resolve(this.serviceProviderMock.Object, typeof(string)); + }); + + action.Should().Throw(); + } + + private void SetupServiceProvider() + { + this.serviceProviderMock + .Setup(u => u.GetService()) + .Returns(this.optionsManagerMock.Object); + } + } +} diff --git a/WpfExtended.Test/Configuration/UpdateableOptionsWrapperTests.cs b/WpfExtended.Test/Configuration/UpdateableOptionsWrapperTests.cs new file mode 100644 index 0000000..19b1fd6 --- /dev/null +++ b/WpfExtended.Test/Configuration/UpdateableOptionsWrapperTests.cs @@ -0,0 +1,47 @@ +using FluentAssertions; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using System; +using System.Windows.Extensions; + +namespace WpfExtended.Tests.Configuration +{ + [TestClass] + public class UpdateableOptionsWrapperTests + { + private const string Value = "hello"; + + private UpdateableOptionsWrapper optionsWrapper; + private readonly Mock optionsManagerMock = new(); + + [TestInitialize] + public void TestInitialize() + { + this.optionsWrapper = new UpdateableOptionsWrapper(optionsManagerMock.Object, Value); + } + + [TestMethod] + public void GetValue_ReturnsValue() + { + this.optionsManagerMock + .Setup(u => u.GetOptions()) + .Throws(); + + var value = this.optionsWrapper.Value; + + value.Should().Be(Value); + } + + [TestMethod] + public void UpdateOption_CallsOptionsManager() + { + this.optionsManagerMock + .Setup(u => u.UpdateOptions(It.IsAny())) + .Verifiable(); + + this.optionsWrapper.UpdateOption(); + + this.optionsManagerMock.Verify(); + } + } +} diff --git a/WpfExtended.Test/Http/HttpClientResolverTests.cs b/WpfExtended.Test/Http/HttpClientResolverTests.cs new file mode 100644 index 0000000..51eead4 --- /dev/null +++ b/WpfExtended.Test/Http/HttpClientResolverTests.cs @@ -0,0 +1,86 @@ +using FluentAssertions; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Debug; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using System; +using System.Http; +using System.Net.Http; +using System.Windows.Extensions.Http; +using WpfExtended.Logging; + +namespace WpfExtended.Tests.Http +{ + [TestClass] + public class HttpClientResolverTests + { + private readonly HttpClientResolver httpClientResolver = new(); + private readonly Mock serviceProviderMock = new(); + + [TestMethod] + public void CanResolve_IHttpClient_ReturnsTrue() + { + var type = typeof(IHttpClient<>); + + var canResolve = this.httpClientResolver.CanResolve(type); + + canResolve.Should().BeTrue(); + } + + [TestMethod] + public void CanResolve_AnythingElse_ReturnsFalse() + { + var types = new Type[] { typeof(HttpClient), typeof(object), typeof(string), typeof(HttpClientResolverTests), typeof(int) }; + + foreach (var type in types) + { + var canResolve = this.httpClientResolver.CanResolve(type); + + canResolve.Should().BeFalse(); + } + } + + [TestMethod] + public void Resolve_TypedClient_ReturnsIHttpClient() + { + this.ServiceProviderMockReturnLogger(); + + var client = this.httpClientResolver.Resolve(this.serviceProviderMock.Object, typeof(IHttpClient)); + + client.Should().BeAssignableTo>(); + } + + [TestMethod] + public void Resolve_NonGenericType_Throws() + { + this.ServiceProviderMockReturnLogger(); + + Action action = new(() => + { + this.httpClientResolver.Resolve(this.serviceProviderMock.Object, typeof(IHttpClient<>)); + }); + + action.Should().Throw(); + } + + [TestMethod] + public void Resolve_RandomType_Throws() + { + this.ServiceProviderMockReturnLogger(); + + Action action = new(() => + { + this.httpClientResolver.Resolve(this.serviceProviderMock.Object, typeof(string)); + }); + + action.Should().Throw(); + } + + private void ServiceProviderMockReturnLogger() + { + this.serviceProviderMock + .Setup(u => u.GetService(It.IsAny())) + .Returns(new CVLogger(string.Empty, new Mock().Object)); + } + } +} diff --git a/WpfExtended.Test/Http/HttpMessageLogger.cs b/WpfExtended.Test/Http/HttpMessageLogger.cs deleted file mode 100644 index 7998a40..0000000 --- a/WpfExtended.Test/Http/HttpMessageLogger.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Microsoft.Extensions.Logging; -using System.Extensions; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; - -namespace WpfExtended.Tests.Http -{ - public class HttpMessageLogger : DelegatingHandler - { - private readonly ILogger logger; - public HttpMessageLogger(ILogger logger, HttpMessageHandler innerHandler) : base(innerHandler) - { - this.logger = logger.ThrowIfNull(nameof(logger)); - } - - protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) - { - this.logger.LogInformation($"{request.Method} - {request.RequestUri}"); - var response = await base.SendAsync(request, cancellationToken); - this.logger.LogInformation($"{response.RequestMessage.RequestUri} - {response.StatusCode}"); - return response; - } - } -} diff --git a/WpfExtended.Test/Logging/CVLoggerProviderTests.cs b/WpfExtended.Test/Logging/CVLoggerProviderTests.cs new file mode 100644 index 0000000..c0561d8 --- /dev/null +++ b/WpfExtended.Test/Logging/CVLoggerProviderTests.cs @@ -0,0 +1,44 @@ +using FluentAssertions; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using WpfExtended.Logging; +using WpfExtended.Models; + +namespace WpfExtended.Tests.Logging +{ + [TestClass] + public class CVLoggerProviderTests + { + private readonly Mock logsWriterMock = new(); + private CVLoggerProvider cVLoggerProvider; + + [TestInitialize] + public void TestInitialize() + { + this.cVLoggerProvider = new CVLoggerProvider(this.logsWriterMock.Object); + } + + [TestMethod] + public void CreateLogger_CreatesNewLogger() + { + var logger = this.cVLoggerProvider.CreateLogger(string.Empty); + + logger.Should().NotBeNull(); + } + + [TestMethod] + public void LogEntry_CallsLogWriter() + { + this.cVLoggerProvider.LogEntry(new Log()); + + this.logsWriterMock.Verify(); + } + + private void SetupLogsWriter() + { + this.logsWriterMock + .Setup(u => u.WriteLog(It.IsAny())) + .Verifiable(); + } + } +} diff --git a/WpfExtended.Test/Logging/CVLoggerTests.cs b/WpfExtended.Test/Logging/CVLoggerTests.cs new file mode 100644 index 0000000..529ff4d --- /dev/null +++ b/WpfExtended.Test/Logging/CVLoggerTests.cs @@ -0,0 +1,77 @@ +using FluentAssertions; +using Microsoft.Extensions.Logging; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using System; +using WpfExtended.Logging; +using WpfExtended.Models; + +namespace WpfExtended.Tests.Logging +{ + [TestClass] + public class CVLoggerTests + { + private readonly Mock cvLoggerProviderMock = new(); + private CVLogger cVLogger; + + [TestInitialize] + public void TestInitialize() + { + this.cVLogger = new CVLogger(string.Empty, this.cvLoggerProviderMock.Object); + } + + [TestMethod] + public void BeginScope_ReturnsNull() + { + var scope = this.cVLogger.BeginScope(string.Empty); + + scope.Should().BeNull(); + } + + [TestMethod] + [DataRow(LogLevel.Debug)] + [DataRow(LogLevel.Trace)] + [DataRow(LogLevel.Information)] + [DataRow(LogLevel.Warning)] + [DataRow(LogLevel.Error)] + [DataRow(LogLevel.Critical)] + public void IsEnabled_OnAllLogLevels_ReturnsTrue(LogLevel logLevel) + { + var enabled = this.cVLogger.IsEnabled(logLevel); + + enabled.Should().BeTrue(); + } + + [TestMethod] + public void Log_CallsFormatter() + { + var called = false; + Func messageFormatter = new((state, exception) => + { + called = true; + return string.Empty; + }); + + this.cVLogger.Log(LogLevel.Debug, new EventId(), "Some message", new Exception(), messageFormatter); + + called.Should().BeTrue(); + } + + [TestMethod] + public void Log_CallsLogsProvider() + { + this.SetupLoggerProvider(); + + this.cVLogger.Log(LogLevel.Debug, new EventId(), "Some message", new Exception(), new Func((s, e) => string.Empty)); + + this.cvLoggerProviderMock.Verify(); + } + + private void SetupLoggerProvider() + { + this.cvLoggerProviderMock + .Setup(u => u.LogEntry(It.IsAny())) + .Verifiable(); + } + } +} diff --git a/WpfExtended.Test/Logging/DebugLogsWriterTests.cs b/WpfExtended.Test/Logging/DebugLogsWriterTests.cs new file mode 100644 index 0000000..7b4bb74 --- /dev/null +++ b/WpfExtended.Test/Logging/DebugLogsWriterTests.cs @@ -0,0 +1,31 @@ +using FluentAssertions; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using WpfExtended.Logging; +using WpfExtended.Models; + +namespace WpfExtended.Tests.Logging +{ + [TestClass] + public class DebugLogsWriterTests + { + private readonly DebugLogsWriter logsWriter = new(); + + [TestMethod] + public void WriteLog_Succeeds() + { + this.logsWriter.WriteLog(new Log()); + } + + [TestMethod] + public void WriteNullLog_Throws() + { + Action action = new(() => + { + this.logsWriter.WriteLog(null); + }); + + action.Should().Throw(); + } + } +} diff --git a/WpfExtended.Test/Logging/LoggerResolverTests.cs b/WpfExtended.Test/Logging/LoggerResolverTests.cs new file mode 100644 index 0000000..36e4584 --- /dev/null +++ b/WpfExtended.Test/Logging/LoggerResolverTests.cs @@ -0,0 +1,109 @@ +using FluentAssertions; +using Microsoft.Extensions.Logging; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using System; +using System.Windows.Extensions.Logging; +using WpfExtended.Logging; + +namespace WpfExtended.Tests.Logging +{ + [TestClass] + public class LoggerResolverTests + { + private readonly Mock serviceProviderMock = new(); + private readonly Mock loggerFactoryMock = new(); + private readonly Mock loggerMock = new(); + private readonly LoggerResolver loggerResolver = new(); + + [TestMethod] + public void CanResolve_ILogger_ReturnsTrue() + { + var type = typeof(ILogger); + + var canResolve = this.loggerResolver.CanResolve(type); + + canResolve.Should().BeTrue(); + } + + [TestMethod] + public void CanResolve_GenericILogger_ReturnsTrue() + { + var type = typeof(ILogger); + + var canResolve = this.loggerResolver.CanResolve(type); + + canResolve.Should().BeTrue(); + } + + [TestMethod] + public void CanResolve_AnythingElse_ReturnsFalse() + { + var types = new Type[] { typeof(CVLogger), typeof(object), typeof(string), typeof(LoggerResolverTests), typeof(int) }; + + foreach(var type in types) + { + var canResolve = this.loggerResolver.CanResolve(type); + + canResolve.Should().BeFalse(); + } + } + + [TestMethod] + public void Resolve_ILogger_ReturnsILogger() + { + this.SetupIServiceProvider(); + + var logger = this.loggerResolver.Resolve(this.serviceProviderMock.Object, typeof(ILogger)); + + logger.Should().BeAssignableTo(); + } + + [TestMethod] + public void Resolve_TypedILogger_ReturnsTypedILogger() + { + this.SetupIServiceProvider(); + + var logger = this.loggerResolver.Resolve(this.serviceProviderMock.Object, typeof(ILogger)); + + logger.Should().BeAssignableTo>(); + } + + [TestMethod] + public void Resolve_RandomType_Throws() + { + this.SetupIServiceProvider(); + + Action action = new(() => + { + this.loggerResolver.Resolve(this.serviceProviderMock.Object, typeof(string)); + }); + + action.Should().Throw(); + } + + [TestMethod] + public void Resolve_NonTypedGeneric_Throws() + { + this.SetupIServiceProvider(); + + Action action = new(() => + { + this.loggerResolver.Resolve(this.serviceProviderMock.Object, typeof(ILogger<>)); + }); + + action.Should().Throw(); + } + + private void SetupIServiceProvider() + { + this.serviceProviderMock + .Setup(u => u.GetService()) + .Returns(this.loggerFactoryMock.Object); + + this.loggerFactoryMock + .Setup(u => u.CreateLogger(It.IsAny())) + .Returns(this.loggerMock.Object); + } + } +} diff --git a/WpfExtended.Test/Controls/CaptionedImage.xaml b/WpfExtended.Test/TestApplication/Controls/CaptionedImage.xaml similarity index 100% rename from WpfExtended.Test/Controls/CaptionedImage.xaml rename to WpfExtended.Test/TestApplication/Controls/CaptionedImage.xaml diff --git a/WpfExtended.Test/Controls/CaptionedImage.xaml.cs b/WpfExtended.Test/TestApplication/Controls/CaptionedImage.xaml.cs similarity index 100% rename from WpfExtended.Test/Controls/CaptionedImage.xaml.cs rename to WpfExtended.Test/TestApplication/Controls/CaptionedImage.xaml.cs diff --git a/WpfExtended.Test/Launcher.cs b/WpfExtended.Test/TestApplication/Launcher.cs similarity index 74% rename from WpfExtended.Test/Launcher.cs rename to WpfExtended.Test/TestApplication/Launcher.cs index 50111e2..b704574 100644 --- a/WpfExtended.Test/Launcher.cs +++ b/WpfExtended.Test/TestApplication/Launcher.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Http.Logging; +using Microsoft.Extensions.Logging; using Slim; using System; using System.Extensions; @@ -15,22 +16,17 @@ namespace WpfExtended.Tests { private static Launcher Instance { get; } = new Launcher(); - [STAThread] - public static int Main() - { - return Instance.Run(); - } - protected override void SetupServiceManager(IServiceManager serviceManager) { serviceManager.RegisterDebugLoggerFactory(); serviceManager.RegisterResolver( new HttpClientResolver() - .WithHttpMessageHandlerFactory((sp, category) => + .WithHttpMessageHandlerFactory((serviceProvider, categoryType) => { - var loggerType = typeof(ILogger<>).MakeGenericType(category); - var logger = sp.GetService(loggerType).As(); - return new HttpMessageLogger(logger, new HttpClientHandler()); + var loggerType = typeof(ILogger<>).MakeGenericType(categoryType); + var logger = serviceProvider.GetService(loggerType).As(); + var handler = new LoggingHttpMessageHandler(logger) { InnerHandler = new HttpClientHandler() }; + return handler; })); serviceManager.RegisterOptionsManager(); } diff --git a/WpfExtended.Test/MainWindow.xaml b/WpfExtended.Test/TestApplication/MainWindow.xaml similarity index 100% rename from WpfExtended.Test/MainWindow.xaml rename to WpfExtended.Test/TestApplication/MainWindow.xaml diff --git a/WpfExtended.Test/MainWindow.xaml.cs b/WpfExtended.Test/TestApplication/MainWindow.xaml.cs similarity index 100% rename from WpfExtended.Test/MainWindow.xaml.cs rename to WpfExtended.Test/TestApplication/MainWindow.xaml.cs diff --git a/WpfExtended.Test/Utilities/TypeCrawler.cs b/WpfExtended.Test/TestApplication/Utilities/TypeCrawler.cs similarity index 100% rename from WpfExtended.Test/Utilities/TypeCrawler.cs rename to WpfExtended.Test/TestApplication/Utilities/TypeCrawler.cs diff --git a/WpfExtended.Test/WpfExtended.Tests.csproj b/WpfExtended.Test/WpfExtended.Tests.csproj index bdf8611..3332496 100644 --- a/WpfExtended.Test/WpfExtended.Tests.csproj +++ b/WpfExtended.Test/WpfExtended.Tests.csproj @@ -1,12 +1,21 @@  - WinExe + Library net5.0-windows true + + + + + + + + + diff --git a/WpfExtended/Logging/CVLogger.cs b/WpfExtended/Logging/CVLogger.cs index 3445610..04ea112 100644 --- a/WpfExtended/Logging/CVLogger.cs +++ b/WpfExtended/Logging/CVLogger.cs @@ -8,12 +8,12 @@ namespace WpfExtended.Logging public sealed class CVLogger : ILogger { private readonly string category; - private readonly CVLoggerProvider cvLoggerProvider; + private readonly ICVLoggerProvider cvLoggerProvider; - public CVLogger(string category, CVLoggerProvider debugLoggerProvider) + public CVLogger(string category, ICVLoggerProvider cvLoggerProvider) { this.category = category; - this.cvLoggerProvider = debugLoggerProvider.ThrowIfNull(nameof(debugLoggerProvider)); + this.cvLoggerProvider = cvLoggerProvider.ThrowIfNull(nameof(cvLoggerProvider)); } public IDisposable BeginScope(TState state) diff --git a/WpfExtended/Logging/CVLoggerProvider.cs b/WpfExtended/Logging/CVLoggerProvider.cs index 69451a1..7356a9f 100644 --- a/WpfExtended/Logging/CVLoggerProvider.cs +++ b/WpfExtended/Logging/CVLoggerProvider.cs @@ -5,7 +5,7 @@ using WpfExtended.Models; namespace WpfExtended.Logging { - public sealed class CVLoggerProvider : ILoggerProvider + public sealed class CVLoggerProvider : ICVLoggerProvider { private readonly ILogsWriter logsManager; private CorrelationVector correlationVector; diff --git a/WpfExtended/Logging/ICVLoggerProvider.cs b/WpfExtended/Logging/ICVLoggerProvider.cs new file mode 100644 index 0000000..7e07275 --- /dev/null +++ b/WpfExtended/Logging/ICVLoggerProvider.cs @@ -0,0 +1,10 @@ +using Microsoft.Extensions.Logging; +using WpfExtended.Models; + +namespace WpfExtended.Logging +{ + public interface ICVLoggerProvider : ILoggerProvider + { + void LogEntry(Log log); + } +} diff --git a/WpfExtended/Logging/LoggerResolver.cs b/WpfExtended/Logging/LoggerResolver.cs index 7a56861..b766b7c 100644 --- a/WpfExtended/Logging/LoggerResolver.cs +++ b/WpfExtended/Logging/LoggerResolver.cs @@ -23,10 +23,14 @@ namespace System.Windows.Extensions.Logging { return ResolveScopedLogger(serviceProvider, type); } - else + else if (type == typeof(ILogger)) { return ResolveLogger(serviceProvider, type); } + else + { + throw new InvalidOperationException($"{nameof(LoggerResolver)} cannot resolve an object of type {type.Name}"); + } } private static object ResolveScopedLogger(Slim.IServiceProvider serviceProvider, Type type) diff --git a/WpfExtended/WpfExtended.csproj b/WpfExtended/WpfExtended.csproj index b32fc6a..fcca8e8 100644 --- a/WpfExtended/WpfExtended.csproj +++ b/WpfExtended/WpfExtended.csproj @@ -6,7 +6,7 @@ true true License.txt - 0.5 + 0.5.1 latest Extension library for Windows Presentation Platform.