Skip to content

Commit

Permalink
TestBase allowing for internal logging etc
Browse files Browse the repository at this point in the history
  • Loading branch information
Turnerj committed Dec 31, 2018
1 parent c6aef6b commit eedd5d7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/InfinityCrawler.Tests/InfinityCrawler.Tests.csproj
Expand Up @@ -7,13 +7,17 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\InfinityCrawler\InfinityCrawler.csproj" />
<ProjectReference Include="..\InfinityCrawler.Tests.TestSite\InfinityCrawler.Tests.TestSite.csproj" />
</ItemGroup>

</Project>
34 changes: 34 additions & 0 deletions 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<ILoggerFactory>();
}

protected ILogger<T> GetLogger<T>()
{
return LoggerFactory.CreateLogger<T>();
}
}
}

0 comments on commit eedd5d7

Please sign in to comment.