Skip to content

Commit f9997e2

Browse files
committed
Caching of ILoggerFactory during testing is not required anymore.
1 parent eb3de4f commit f9997e2

File tree

6 files changed

+13
-34
lines changed

6 files changed

+13
-34
lines changed

samples/Thinktecture.EntityFrameworkCore.Sqlite.Samples/Program.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Microsoft.Extensions.DependencyInjection;
22
using Thinktecture.Database;
3-
using Thinktecture.EntityFrameworkCore.BulkOperations;
43

54
namespace Thinktecture;
65

src/Thinktecture.EntityFrameworkCore.Relational/EntityFrameworkCore/Migrations/DefaultSchemaRespectingMigrationAssembly.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System.Reflection;
22
using Microsoft.EntityFrameworkCore.Infrastructure;
33
using Microsoft.EntityFrameworkCore.Migrations;
4-
using Microsoft.EntityFrameworkCore.Migrations.Operations;
54
using Microsoft.Extensions.DependencyInjection;
65

76
namespace Thinktecture.EntityFrameworkCore.Migrations;

src/Thinktecture.EntityFrameworkCore.Relational/EntityFrameworkCore/Query/ThinktectureRelationalQueryContextFactory.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Diagnostics.CodeAnalysis;
2-
using Microsoft.EntityFrameworkCore.Infrastructure;
32
using Microsoft.EntityFrameworkCore.Query;
43
using Microsoft.EntityFrameworkCore.Query.Internal;
54
using Thinktecture.EntityFrameworkCore.Infrastructure;

tests/Thinktecture.EntityFrameworkCore.Relational.Tests/IntegrationTestsBase.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Collections.Concurrent;
21
using System.Data.Common;
32
using Microsoft.Extensions.Logging;
43
using Serilog;
@@ -10,8 +9,6 @@ namespace Thinktecture;
109

1110
public class IntegrationTestsBase : SqliteDbContextIntegrationTests<DbContextWithSchema>
1211
{
13-
private static readonly ConcurrentDictionary<ITestOutputHelper, ILoggerFactory> _loggerFactoryCache = new();
14-
1512
protected Action<DbContextOptionsBuilder<DbContextWithSchema>>? ConfigureOptionsBuilder { get; set; }
1613
protected Action<ModelBuilder>? ConfigureModel { get; set; }
1714
protected string? Schema { get; set; }
@@ -43,14 +40,11 @@ private static ILoggerFactory CreateLoggerFactory(ITestOutputHelper testOutputHe
4340
{
4441
ArgumentNullException.ThrowIfNull(testOutputHelper);
4542

46-
return _loggerFactoryCache.GetOrAdd(testOutputHelper, _ =>
47-
{
48-
var loggerConfig = new LoggerConfiguration()
49-
.WriteTo.TestOutput(testOutputHelper, outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] [{SourceContext}] {Message:lj}{NewLine}{Exception}");
43+
var loggerConfig = new LoggerConfiguration()
44+
.WriteTo.TestOutput(testOutputHelper, outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] [{SourceContext}] {Message:lj}{NewLine}{Exception}");
5045

51-
return new LoggerFactory()
52-
.AddSerilog(loggerConfig.CreateLogger());
53-
});
46+
return new LoggerFactory()
47+
.AddSerilog(loggerConfig.CreateLogger());
5448
}
5549

5650
protected DbContextWithSchema CreateContextWithSchema(string schema)

tests/Thinktecture.EntityFrameworkCore.SqlServer.Tests/TestContext.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Collections.Concurrent;
21
using Microsoft.Extensions.Configuration;
32
using Microsoft.Extensions.Logging;
43
using Serilog;
@@ -11,8 +10,6 @@ public class TestContext
1110

1211
public static TestContext Instance => _lazy.Value;
1312

14-
private readonly ConcurrentDictionary<ITestOutputHelper, ILoggerFactory> _loggerFactoryCache = new();
15-
1613
public IConfiguration Configuration { get; }
1714

1815
public string ConnectionString => Configuration.GetConnectionString("default");
@@ -40,13 +37,10 @@ public ILoggerFactory GetLoggerFactory(ITestOutputHelper testOutputHelper)
4037
{
4138
ArgumentNullException.ThrowIfNull(testOutputHelper);
4239

43-
return _loggerFactoryCache.GetOrAdd(testOutputHelper, helper =>
44-
{
45-
var loggerConfig = new LoggerConfiguration()
46-
.WriteTo.TestOutput(helper, outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] [{SourceContext}] {Message:lj}{NewLine}{Exception}");
40+
var loggerConfig = new LoggerConfiguration()
41+
.WriteTo.TestOutput(testOutputHelper, outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] [{SourceContext}] {Message:lj}{NewLine}{Exception}");
4742

48-
return new LoggerFactory()
49-
.AddSerilog(loggerConfig.CreateLogger());
50-
});
43+
return new LoggerFactory()
44+
.AddSerilog(loggerConfig.CreateLogger());
5145
}
5246
}

tests/Thinktecture.EntityFrameworkCore.Sqlite.Tests/IntegrationTestsBase.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Collections.Concurrent;
21
using System.Data.Common;
32
using System.Diagnostics;
43
using Microsoft.EntityFrameworkCore.Diagnostics;
@@ -15,8 +14,6 @@ namespace Thinktecture;
1514

1615
public class IntegrationTestsBase : SqliteDbContextIntegrationTests<TestDbContext>
1716
{
18-
private static readonly ConcurrentDictionary<ITestOutputHelper, ILoggerFactory> _loggerFactoryCache = new();
19-
2017
protected Action<DbContextOptionsBuilder<TestDbContext>>? ConfigureOptionsBuilder { get; set; }
2118
protected Action<ModelBuilder>? ConfigureModel { get; set; }
2219

@@ -66,17 +63,14 @@ protected override TestDbContext CreateContext(DbContextOptions<TestDbContext> o
6663
return ctx;
6764
}
6865

69-
private ILoggerFactory CreateLoggerFactory(ITestOutputHelper testOutputHelper)
66+
private static ILoggerFactory CreateLoggerFactory(ITestOutputHelper testOutputHelper)
7067
{
7168
ArgumentNullException.ThrowIfNull(testOutputHelper);
7269

73-
return _loggerFactoryCache.GetOrAdd(testOutputHelper, helper =>
74-
{
75-
var loggerConfig = new LoggerConfiguration()
76-
.WriteTo.TestOutput(helper, outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] [{SourceContext}] {Message:lj}{NewLine}{Exception}");
70+
var loggerConfig = new LoggerConfiguration()
71+
.WriteTo.TestOutput(testOutputHelper, outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] [{SourceContext}] {Message:lj}{NewLine}{Exception}");
7772

78-
return new LoggerFactory()
79-
.AddSerilog(loggerConfig.CreateLogger());
80-
});
73+
return new LoggerFactory()
74+
.AddSerilog(loggerConfig.CreateLogger());
8175
}
8276
}

0 commit comments

Comments
 (0)