From eedd5d73ec8d283c6a7c68c14544ceec2f22fe37 Mon Sep 17 00:00:00 2001 From: Turnerj Date: Tue, 1 Jan 2019 00:58:39 +1030 Subject: [PATCH] TestBase allowing for internal logging etc --- .../InfinityCrawler.Tests.csproj | 4 +++ tests/InfinityCrawler.Tests/TestBase.cs | 34 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 tests/InfinityCrawler.Tests/TestBase.cs diff --git a/tests/InfinityCrawler.Tests/InfinityCrawler.Tests.csproj b/tests/InfinityCrawler.Tests/InfinityCrawler.Tests.csproj index 6b2c15d..d104744 100644 --- a/tests/InfinityCrawler.Tests/InfinityCrawler.Tests.csproj +++ b/tests/InfinityCrawler.Tests/InfinityCrawler.Tests.csproj @@ -7,6 +7,9 @@ + + + @@ -14,6 +17,7 @@ + diff --git a/tests/InfinityCrawler.Tests/TestBase.cs b/tests/InfinityCrawler.Tests/TestBase.cs new file mode 100644 index 0000000..f0c7585 --- /dev/null +++ b/tests/InfinityCrawler.Tests/TestBase.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace InfinityCrawler.Tests +{ + [TestClass] + public class TestBase + { + private ILoggerFactory LoggerFactory { get; } + + public TestBase() + { + var serviceProvider = new ServiceCollection() + .AddLogging(builder => + { + builder.AddFilter("InfinityCrawler", LogLevel.Trace); + builder.AddConsole(); + builder.AddDebug(); + }) + .BuildServiceProvider(); + + LoggerFactory = serviceProvider.GetService(); + } + + protected ILogger GetLogger() + { + return LoggerFactory.CreateLogger(); + } + } +}