Skip to content

Commit

Permalink
Merge pull request #304 from btecu/verbosity
Browse files Browse the repository at this point in the history
Further reduce tests verbosity
  • Loading branch information
jaredcnance authored Jun 13, 2018
2 parents 1f474d2 + 43ac8b0 commit e79b88e
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 40 deletions.
2 changes: 1 addition & 1 deletion benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
<PackageReference Include="xunit" Version="$(xUnitVersion)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\JsonApiDotNetCore\JsonApiDotNetCore.csproj" />
<ProjectReference Include="../src/JsonApiDotNetCore/JsonApiDotNetCore.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,4 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="$(EFCoreToolsVersion)" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="$(NpgsqlPostgreSQLVersion)" />
</ItemGroup>

<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="$(EFCoreToolsVersion)" />
</ItemGroup>

</Project>
3 changes: 1 addition & 2 deletions src/Examples/JsonApiDotNetCoreExample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public Startup(IHostingEnvironment env)
public virtual IServiceProvider ConfigureServices(IServiceCollection services)
{
var loggerFactory = new LoggerFactory();
loggerFactory.AddConsole(LogLevel.Trace);
loggerFactory.AddConsole(LogLevel.Warning);

services
.AddSingleton<ILoggerFactory>(loggerFactory)
Expand Down Expand Up @@ -57,7 +57,6 @@ public virtual void Configure(
context.Database.EnsureCreated();

loggerFactory.AddConsole(Config.GetSection("Logging"));
loggerFactory.AddDebug();

app.UseJsonApi();
}
Expand Down
3 changes: 1 addition & 2 deletions src/Examples/NoEntityFrameworkExample/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using JsonApiDotNetCore.Extensions;
using JsonApiDotNetCore.Extensions;
using JsonApiDotNetCore.Services;
using JsonApiDotNetCoreExample.Data;
using JsonApiDotNetCoreExample.Models;
Expand Down Expand Up @@ -55,7 +55,6 @@ public virtual IServiceProvider ConfigureServices(IServiceCollection services)
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, AppDbContext context)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();

context.Database.EnsureCreated();

Expand Down
7 changes: 1 addition & 6 deletions src/Examples/OperationsExample/OperationsExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<ProjectReference Include="../../JsonApiDotNetCore/JsonApiDotNetCore.csproj" />
<ProjectReference Include="..\JsonApiDotNetCoreExample\JsonApiDotNetCoreExample.csproj" />
<ProjectReference Include="../JsonApiDotNetCoreExample/JsonApiDotNetCoreExample.csproj" />
</ItemGroup>

<ItemGroup>
Expand All @@ -26,9 +26,4 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="$(EFCoreToolsVersion)" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="$(NpgsqlPostgreSQLVersion)" />
</ItemGroup>

<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="$(EFCoreToolsVersion)" />
</ItemGroup>

</Project>
3 changes: 1 addition & 2 deletions src/Examples/OperationsExample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public Startup(IHostingEnvironment env)
public virtual IServiceProvider ConfigureServices(IServiceCollection services)
{
var loggerFactory = new LoggerFactory();
loggerFactory.AddConsole(LogLevel.Trace);
loggerFactory.AddConsole(LogLevel.Warning);

services.AddSingleton<ILoggerFactory>(loggerFactory);

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

loggerFactory.AddConsole(Config.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseJsonApi();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Examples/ReportsExample/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Information"
"Default": "Warning"
}
}
}
6 changes: 5 additions & 1 deletion src/JsonApiDotNetCore/Serialization/JsonApiSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ private string GetErrorJson(object responseObject, ILogger logger)
}
else
{
logger?.LogInformation("Response was not a JSONAPI entity. Serializing as plain JSON.");
if (logger?.IsEnabled(LogLevel.Information) == true)
{
logger.LogInformation("Response was not a JSONAPI entity. Serializing as plain JSON.");
}

return JsonConvert.SerializeObject(responseObject);
}
}
Expand Down
11 changes: 8 additions & 3 deletions src/JsonApiDotNetCore/Services/EntityResourceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ public virtual async Task<object> GetRelationshipAsync(TId id, string relationsh

if (relationshipName == null)
throw new JsonApiException(422, "Relationship name not specified.");

_logger.LogTrace($"Looking up '{relationshipName}'...");
if (_logger.IsEnabled(LogLevel.Trace))
{
_logger.LogTrace($"Looking up '{relationshipName}'...");
}

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

_logger?.LogInformation($"Applying paging query. Fetching page {pageManager.CurrentPage} with {pageManager.PageSize} entities");
if (_logger?.IsEnabled(LogLevel.Information) == true)
{
_logger?.LogInformation($"Applying paging query. Fetching page {pageManager.CurrentPage} with {pageManager.PageSize} entities");
}

return await _entities.PageAsync(entities, pageManager.PageSize, pageManager.CurrentPage);
}
Expand Down
13 changes: 11 additions & 2 deletions src/JsonApiDotNetCore/Services/QueryAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ public bool TryGetValue<T>(string key, out T value)
var stringValue = GetFilterValue(key);
if (stringValue == null)
{
_logger.LogInformation($"'{key}' was not found in the query collection");
if (_logger.IsEnabled(LogLevel.Information))
{
_logger.LogInformation($"'{key}' was not found in the query collection");
}

return false;
}

Expand All @@ -56,7 +60,12 @@ public bool TryGetValue<T>(string key, out T value)
}
catch (FormatException)
{
_logger.LogInformation($"'{value}' is not a valid '{typeof(T).Name}' value for query parameter {key}");
if (_logger.IsEnabled(LogLevel.Information))
{
_logger.LogInformation(
$"'{value}' is not a valid '{typeof(T).Name}' value for query parameter {key}");
}

return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public MetaStartup(IHostingEnvironment env)
public override IServiceProvider ConfigureServices(IServiceCollection services)
{
var loggerFactory = new LoggerFactory();
loggerFactory.AddConsole(LogLevel.Trace);
loggerFactory.AddConsole(LogLevel.Warning);

services
.AddSingleton<ILoggerFactory>(loggerFactory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ItemGroup>
<ProjectReference Include="../../src/Examples/JsonApiDotNetCoreExample/JsonApiDotNetCoreExample.csproj" />
<ProjectReference Include="../../src/Examples/NoEntityFrameworkExample/NoEntityFrameworkExample.csproj" />
<ProjectReference Include="..\UnitTests\UnitTests.csproj" />
<ProjectReference Include="../UnitTests/UnitTests.csproj" />
</ItemGroup>

<ItemGroup>
Expand All @@ -25,9 +25,8 @@
<PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.0" />
<PackageReference Include="Moq" Version="$(MoqVersion)" />
</ItemGroup>

<ItemGroup>
<DotNetCliToolReference Include="dotnet-xunit" Version="$(XUnitVersion)" />
<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="1.0.0" />
</ItemGroup>
</Project>
6 changes: 3 additions & 3 deletions test/JsonApiDotNetCoreExampleTests/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Error",
"System": "Information",
"Microsoft": "Information"
"Default": "Warning",
"System": "Warning",
"Microsoft": "Warning"
}
}
}
2 changes: 1 addition & 1 deletion test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<ProjectReference Include="../../src/Examples/JsonApiDotNetCoreExample/JsonApiDotNetCoreExample.csproj" />
<ProjectReference Include="../../test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj" />
<ProjectReference Include="../../src/Examples/NoEntityFrameworkExample/NoEntityFrameworkExample.csproj" />
<ProjectReference Include="..\UnitTests\UnitTests.csproj" />
<ProjectReference Include="../UnitTests/UnitTests.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
Expand Down
6 changes: 3 additions & 3 deletions test/NoEntityFrameworkTests/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
"Default": "Warning",
"System": "Warning",
"Microsoft": "Warning"
}
}
}
4 changes: 2 additions & 2 deletions test/OperationsExampleTests/OperationsExampleTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Examples\OperationsExample\OperationsExample.csproj" />
<ProjectReference Include="..\UnitTests\UnitTests.csproj" />
<ProjectReference Include="../../src/Examples/OperationsExample/OperationsExample.csproj" />
<ProjectReference Include="../UnitTests/UnitTests.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="xunit.runner.json;appsettings.json">
Expand Down
4 changes: 2 additions & 2 deletions test/UnitTests/UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\JsonApiDotNetCore\JsonApiDotNetCore.csproj" />
<ProjectReference Include="..\..\src\Examples\JsonApiDotNetCoreExample\JsonApiDotNetCoreExample.csproj" />
<ProjectReference Include="../../src/JsonApiDotNetCore/JsonApiDotNetCore.csproj" />
<ProjectReference Include="../../src/Examples/JsonApiDotNetCoreExample/JsonApiDotNetCoreExample.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
Expand Down

0 comments on commit e79b88e

Please sign in to comment.