Skip to content

Commit e79b88e

Browse files
authored
Merge pull request #304 from btecu/verbosity
Further reduce tests verbosity
2 parents 1f474d2 + 43ac8b0 commit e79b88e

File tree

17 files changed

+44
-40
lines changed

17 files changed

+44
-40
lines changed

benchmarks/Benchmarks.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
<PackageReference Include="xunit" Version="$(xUnitVersion)" />
1111
</ItemGroup>
1212
<ItemGroup>
13-
<ProjectReference Include="..\src\JsonApiDotNetCore\JsonApiDotNetCore.csproj" />
13+
<ProjectReference Include="../src/JsonApiDotNetCore/JsonApiDotNetCore.csproj" />
1414
</ItemGroup>
1515
</Project>

src/Examples/JsonApiDotNetCoreExample/JsonApiDotNetCoreExample.csproj

-5
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,4 @@
2525
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="$(EFCoreToolsVersion)" />
2626
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="$(NpgsqlPostgreSQLVersion)" />
2727
</ItemGroup>
28-
29-
<ItemGroup>
30-
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="$(EFCoreToolsVersion)" />
31-
</ItemGroup>
32-
3328
</Project>

src/Examples/JsonApiDotNetCoreExample/Startup.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public Startup(IHostingEnvironment env)
2828
public virtual IServiceProvider ConfigureServices(IServiceCollection services)
2929
{
3030
var loggerFactory = new LoggerFactory();
31-
loggerFactory.AddConsole(LogLevel.Trace);
31+
loggerFactory.AddConsole(LogLevel.Warning);
3232

3333
services
3434
.AddSingleton<ILoggerFactory>(loggerFactory)
@@ -57,7 +57,6 @@ public virtual void Configure(
5757
context.Database.EnsureCreated();
5858

5959
loggerFactory.AddConsole(Config.GetSection("Logging"));
60-
loggerFactory.AddDebug();
6160

6261
app.UseJsonApi();
6362
}

src/Examples/NoEntityFrameworkExample/Startup.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using JsonApiDotNetCore.Extensions;
1+
using JsonApiDotNetCore.Extensions;
22
using JsonApiDotNetCore.Services;
33
using JsonApiDotNetCoreExample.Data;
44
using JsonApiDotNetCoreExample.Models;
@@ -55,7 +55,6 @@ public virtual IServiceProvider ConfigureServices(IServiceCollection services)
5555
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, AppDbContext context)
5656
{
5757
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
58-
loggerFactory.AddDebug();
5958

6059
context.Database.EnsureCreated();
6160

src/Examples/OperationsExample/OperationsExample.csproj

+1-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<ItemGroup>
1010
<ProjectReference Include="../../JsonApiDotNetCore/JsonApiDotNetCore.csproj" />
11-
<ProjectReference Include="..\JsonApiDotNetCoreExample\JsonApiDotNetCoreExample.csproj" />
11+
<ProjectReference Include="../JsonApiDotNetCoreExample/JsonApiDotNetCoreExample.csproj" />
1212
</ItemGroup>
1313

1414
<ItemGroup>
@@ -26,9 +26,4 @@
2626
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="$(EFCoreToolsVersion)" />
2727
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="$(NpgsqlPostgreSQLVersion)" />
2828
</ItemGroup>
29-
30-
<ItemGroup>
31-
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="$(EFCoreToolsVersion)" />
32-
</ItemGroup>
33-
3429
</Project>

src/Examples/OperationsExample/Startup.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public Startup(IHostingEnvironment env)
2727
public virtual IServiceProvider ConfigureServices(IServiceCollection services)
2828
{
2929
var loggerFactory = new LoggerFactory();
30-
loggerFactory.AddConsole(LogLevel.Trace);
30+
loggerFactory.AddConsole(LogLevel.Warning);
3131

3232
services.AddSingleton<ILoggerFactory>(loggerFactory);
3333

@@ -47,7 +47,6 @@ public virtual void Configure(
4747
context.Database.EnsureCreated();
4848

4949
loggerFactory.AddConsole(Config.GetSection("Logging"));
50-
loggerFactory.AddDebug();
5150
app.UseJsonApi();
5251
}
5352

src/Examples/ReportsExample/appsettings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"Logging": {
33
"IncludeScopes": false,
44
"LogLevel": {
5-
"Default": "Information"
5+
"Default": "Warning"
66
}
77
}
88
}

src/JsonApiDotNetCore/Serialization/JsonApiSerializer.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ private string GetErrorJson(object responseObject, ILogger logger)
6565
}
6666
else
6767
{
68-
logger?.LogInformation("Response was not a JSONAPI entity. Serializing as plain JSON.");
68+
if (logger?.IsEnabled(LogLevel.Information) == true)
69+
{
70+
logger.LogInformation("Response was not a JSONAPI entity. Serializing as plain JSON.");
71+
}
72+
6973
return JsonConvert.SerializeObject(responseObject);
7074
}
7175
}

src/JsonApiDotNetCore/Services/EntityResourceService.cs

+8-3
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ public virtual async Task<object> GetRelationshipAsync(TId id, string relationsh
8989

9090
if (relationshipName == null)
9191
throw new JsonApiException(422, "Relationship name not specified.");
92-
93-
_logger.LogTrace($"Looking up '{relationshipName}'...");
92+
if (_logger.IsEnabled(LogLevel.Trace))
93+
{
94+
_logger.LogTrace($"Looking up '{relationshipName}'...");
95+
}
9496

9597
var entity = await _entities.GetAndIncludeAsync(id, relationshipName);
9698
// TODO: it would be better if we could distinguish whether or not the relationship was not found,
@@ -166,7 +168,10 @@ protected virtual async Task<IEnumerable<T>> ApplyPageQueryAsync(IQueryable<T> e
166168
if (!pageManager.IsPaginated)
167169
return await _entities.ToListAsync(entities);
168170

169-
_logger?.LogInformation($"Applying paging query. Fetching page {pageManager.CurrentPage} with {pageManager.PageSize} entities");
171+
if (_logger?.IsEnabled(LogLevel.Information) == true)
172+
{
173+
_logger?.LogInformation($"Applying paging query. Fetching page {pageManager.CurrentPage} with {pageManager.PageSize} entities");
174+
}
170175

171176
return await _entities.PageAsync(entities, pageManager.PageSize, pageManager.CurrentPage);
172177
}

src/JsonApiDotNetCore/Services/QueryAccessor.cs

+11-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ public bool TryGetValue<T>(string key, out T value)
4545
var stringValue = GetFilterValue(key);
4646
if (stringValue == null)
4747
{
48-
_logger.LogInformation($"'{key}' was not found in the query collection");
48+
if (_logger.IsEnabled(LogLevel.Information))
49+
{
50+
_logger.LogInformation($"'{key}' was not found in the query collection");
51+
}
52+
4953
return false;
5054
}
5155

@@ -56,7 +60,12 @@ public bool TryGetValue<T>(string key, out T value)
5660
}
5761
catch (FormatException)
5862
{
59-
_logger.LogInformation($"'{value}' is not a valid '{typeof(T).Name}' value for query parameter {key}");
63+
if (_logger.IsEnabled(LogLevel.Information))
64+
{
65+
_logger.LogInformation(
66+
$"'{value}' is not a valid '{typeof(T).Name}' value for query parameter {key}");
67+
}
68+
6069
return false;
6170
}
6271
}

test/JsonApiDotNetCoreExampleTests/Helpers/Startups/MetaStartup.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public MetaStartup(IHostingEnvironment env)
2020
public override IServiceProvider ConfigureServices(IServiceCollection services)
2121
{
2222
var loggerFactory = new LoggerFactory();
23-
loggerFactory.AddConsole(LogLevel.Trace);
23+
loggerFactory.AddConsole(LogLevel.Warning);
2424

2525
services
2626
.AddSingleton<ILoggerFactory>(loggerFactory)

test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<ItemGroup>
1414
<ProjectReference Include="../../src/Examples/JsonApiDotNetCoreExample/JsonApiDotNetCoreExample.csproj" />
1515
<ProjectReference Include="../../src/Examples/NoEntityFrameworkExample/NoEntityFrameworkExample.csproj" />
16-
<ProjectReference Include="..\UnitTests\UnitTests.csproj" />
16+
<ProjectReference Include="../UnitTests/UnitTests.csproj" />
1717
</ItemGroup>
1818

1919
<ItemGroup>
@@ -25,9 +25,8 @@
2525
<PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.0" />
2626
<PackageReference Include="Moq" Version="$(MoqVersion)" />
2727
</ItemGroup>
28-
28+
2929
<ItemGroup>
3030
<DotNetCliToolReference Include="dotnet-xunit" Version="$(XUnitVersion)" />
31-
<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="1.0.0" />
3231
</ItemGroup>
3332
</Project>

test/JsonApiDotNetCoreExampleTests/appsettings.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"Logging": {
66
"IncludeScopes": false,
77
"LogLevel": {
8-
"Default": "Error",
9-
"System": "Information",
10-
"Microsoft": "Information"
8+
"Default": "Warning",
9+
"System": "Warning",
10+
"Microsoft": "Warning"
1111
}
1212
}
1313
}

test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<ProjectReference Include="../../src/Examples/JsonApiDotNetCoreExample/JsonApiDotNetCoreExample.csproj" />
1818
<ProjectReference Include="../../test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj" />
1919
<ProjectReference Include="../../src/Examples/NoEntityFrameworkExample/NoEntityFrameworkExample.csproj" />
20-
<ProjectReference Include="..\UnitTests\UnitTests.csproj" />
20+
<ProjectReference Include="../UnitTests/UnitTests.csproj" />
2121
</ItemGroup>
2222
<ItemGroup>
2323
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />

test/NoEntityFrameworkTests/appsettings.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"Logging": {
66
"IncludeScopes": false,
77
"LogLevel": {
8-
"Default": "Debug",
9-
"System": "Information",
10-
"Microsoft": "Information"
8+
"Default": "Warning",
9+
"System": "Warning",
10+
"Microsoft": "Warning"
1111
}
1212
}
1313
}

test/OperationsExampleTests/OperationsExampleTests.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
1414
</ItemGroup>
1515
<ItemGroup>
16-
<ProjectReference Include="..\..\src\Examples\OperationsExample\OperationsExample.csproj" />
17-
<ProjectReference Include="..\UnitTests\UnitTests.csproj" />
16+
<ProjectReference Include="../../src/Examples/OperationsExample/OperationsExample.csproj" />
17+
<ProjectReference Include="../UnitTests/UnitTests.csproj" />
1818
</ItemGroup>
1919
<ItemGroup>
2020
<None Update="xunit.runner.json;appsettings.json">

test/UnitTests/UnitTests.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<IsPackable>false</IsPackable>
55
</PropertyGroup>
66
<ItemGroup>
7-
<ProjectReference Include="..\..\src\JsonApiDotNetCore\JsonApiDotNetCore.csproj" />
8-
<ProjectReference Include="..\..\src\Examples\JsonApiDotNetCoreExample\JsonApiDotNetCoreExample.csproj" />
7+
<ProjectReference Include="../../src/JsonApiDotNetCore/JsonApiDotNetCore.csproj" />
8+
<ProjectReference Include="../../src/Examples/JsonApiDotNetCoreExample/JsonApiDotNetCoreExample.csproj" />
99
</ItemGroup>
1010
<ItemGroup>
1111
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />

0 commit comments

Comments
 (0)