aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Timeline.Tests/Helpers/MyTestLoggerFactory.cs21
-rw-r--r--Timeline.Tests/Helpers/MyWebApplicationFactory.cs6
-rw-r--r--Timeline.Tests/IntegratedTests/UserAvatarTests.cs2
-rw-r--r--Timeline.Tests/Timeline.Tests.csproj15
-rw-r--r--Timeline.Tests/UserAvatarServiceTest.cs4
-rw-r--r--Timeline.Tests/UserDetailServiceTest.cs4
-rw-r--r--Timeline/Program.cs3
-rw-r--r--Timeline/Services/UserAvatarService.cs4
-rw-r--r--Timeline/Startup.cs18
-rw-r--r--Timeline/Timeline.csproj6
10 files changed, 46 insertions, 37 deletions
diff --git a/Timeline.Tests/Helpers/MyTestLoggerFactory.cs b/Timeline.Tests/Helpers/MyTestLoggerFactory.cs
index 40c6a77e..b9960378 100644
--- a/Timeline.Tests/Helpers/MyTestLoggerFactory.cs
+++ b/Timeline.Tests/Helpers/MyTestLoggerFactory.cs
@@ -1,14 +1,25 @@
-using Microsoft.Extensions.Logging;
-using Microsoft.Extensions.Logging.Testing;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Logging.Abstractions;
using Xunit.Abstractions;
namespace Timeline.Tests.Helpers
{
- public static class MyTestLoggerFactory
+ public static class Logging
{
- public static LoggerFactory Create(ITestOutputHelper outputHelper)
+ public static ILoggerFactory Create(ITestOutputHelper outputHelper)
{
- return new LoggerFactory(new[] { new XunitLoggerProvider(outputHelper) });
+ // TODO: Use test output.
+ return NullLoggerFactory.Instance;
+ }
+
+ public static IWebHostBuilder ConfigureTestLogging(this IWebHostBuilder builder)
+ {
+ builder.ConfigureLogging(logging =>
+ {
+ //logging.AddXunit(outputHelper);
+ });
+ return builder;
}
}
}
diff --git a/Timeline.Tests/Helpers/MyWebApplicationFactory.cs b/Timeline.Tests/Helpers/MyWebApplicationFactory.cs
index 1a9fe01e..dfbe6620 100644
--- a/Timeline.Tests/Helpers/MyWebApplicationFactory.cs
+++ b/Timeline.Tests/Helpers/MyWebApplicationFactory.cs
@@ -58,11 +58,7 @@ namespace Timeline.Tests.Helpers
return factory.WithWebHostBuilder(builder =>
{
- builder
- .ConfigureLogging(logging =>
- {
- logging.AddXunit(outputHelper);
- })
+ builder.ConfigureTestLogging()
.ConfigureServices(services =>
{
services.AddEntityFrameworkSqlite();
diff --git a/Timeline.Tests/IntegratedTests/UserAvatarTests.cs b/Timeline.Tests/IntegratedTests/UserAvatarTests.cs
index fd0c2ef4..2a3442d1 100644
--- a/Timeline.Tests/IntegratedTests/UserAvatarTests.cs
+++ b/Timeline.Tests/IntegratedTests/UserAvatarTests.cs
@@ -55,7 +55,7 @@ namespace Timeline.Tests.IntegratedTests
.And.Should().HaveBodyAsCommonResponseWithCode(UserAvatarController.ErrorCodes.Get_UserNotExist);
}
- var env = _factory.Server.Host.Services.GetRequiredService<IHostingEnvironment>();
+ var env = _factory.Server.Host.Services.GetRequiredService<IWebHostEnvironment>();
var defaultAvatarData = await File.ReadAllBytesAsync(Path.Combine(env.ContentRootPath, "default-avatar.png"));
async Task GetReturnDefault(string username = "user")
diff --git a/Timeline.Tests/Timeline.Tests.csproj b/Timeline.Tests/Timeline.Tests.csproj
index 72bbc418..1852da5f 100644
--- a/Timeline.Tests/Timeline.Tests.csproj
+++ b/Timeline.Tests/Timeline.Tests.csproj
@@ -1,20 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
- <TargetFramework>netcoreapp2.2</TargetFramework>
+ <TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
- <PackageReference Include="coverlet.collector" Version="1.0.1">
+ <PackageReference Include="coverlet.collector" Version="1.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
- <PackageReference Include="FluentAssertions" Version="5.8.0" />
- <PackageReference Include="Microsoft.AspNetCore.App" />
- <PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="2.2.0" />
- <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" />
- <PackageReference Include="Microsoft.Extensions.Logging.Testing" Version="2.2.0-rtm-35646" />
- <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
+ <PackageReference Include="FluentAssertions" Version="5.9.0" />
+ <PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
+ <PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.0.0" />
+ <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.0.0" />
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
diff --git a/Timeline.Tests/UserAvatarServiceTest.cs b/Timeline.Tests/UserAvatarServiceTest.cs
index e059602d..93bb70ae 100644
--- a/Timeline.Tests/UserAvatarServiceTest.cs
+++ b/Timeline.Tests/UserAvatarServiceTest.cs
@@ -151,7 +151,7 @@ namespace Timeline.Tests
private readonly MockDefaultUserAvatarProvider _mockDefaultUserAvatarProvider;
- private readonly LoggerFactory _loggerFactory;
+ private readonly ILoggerFactory _loggerFactory;
private readonly TestDatabase _database;
private readonly IETagGenerator _eTagGenerator;
@@ -162,7 +162,7 @@ namespace Timeline.Tests
{
_mockDefaultUserAvatarProvider = mockDefaultUserAvatarProvider;
- _loggerFactory = MyTestLoggerFactory.Create(outputHelper);
+ _loggerFactory = Logging.Create(outputHelper);
_database = new TestDatabase();
_eTagGenerator = new ETagGenerator();
diff --git a/Timeline.Tests/UserDetailServiceTest.cs b/Timeline.Tests/UserDetailServiceTest.cs
index 7bbb2246..98613429 100644
--- a/Timeline.Tests/UserDetailServiceTest.cs
+++ b/Timeline.Tests/UserDetailServiceTest.cs
@@ -15,14 +15,14 @@ namespace Timeline.Tests
{
public class UserDetailServiceTest : IDisposable
{
- private readonly LoggerFactory _loggerFactory;
+ private readonly ILoggerFactory _loggerFactory;
private readonly TestDatabase _database;
private readonly UserDetailService _service;
public UserDetailServiceTest(ITestOutputHelper outputHelper)
{
- _loggerFactory = MyTestLoggerFactory.Create(outputHelper);
+ _loggerFactory = Logging.Create(outputHelper);
_database = new TestDatabase();
_service = new UserDetailService(_loggerFactory.CreateLogger<UserDetailService>(), _database.DatabaseContext);
diff --git a/Timeline/Program.cs b/Timeline/Program.cs
index f343de44..dfc93b9e 100644
--- a/Timeline/Program.cs
+++ b/Timeline/Program.cs
@@ -2,6 +2,7 @@ using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.FileProviders;
+using Microsoft.Extensions.Hosting;
namespace Timeline
{
@@ -10,7 +11,7 @@ namespace Timeline
public static void Main(string[] args)
{
CreateWebHostBuilder(args)
- .ConfigureAppConfiguration((context, config) =>
+ .ConfigureAppConfiguration((context, config) =>
{
if (context.HostingEnvironment.IsProduction())
config.AddJsonFile(new PhysicalFileProvider("/etc/webapp/timeline/"), "config.json", true, true);
diff --git a/Timeline/Services/UserAvatarService.cs b/Timeline/Services/UserAvatarService.cs
index 5c380dd8..ecec5a31 100644
--- a/Timeline/Services/UserAvatarService.cs
+++ b/Timeline/Services/UserAvatarService.cs
@@ -121,7 +121,7 @@ namespace Timeline.Services
public class DefaultUserAvatarProvider : IDefaultUserAvatarProvider
{
- private readonly IHostingEnvironment _environment;
+ private readonly IWebHostEnvironment _environment;
private readonly IETagGenerator _eTagGenerator;
@@ -129,7 +129,7 @@ namespace Timeline.Services
private DateTime _cacheLastModified;
private string _cacheETag;
- public DefaultUserAvatarProvider(IHostingEnvironment environment, IETagGenerator eTagGenerator)
+ public DefaultUserAvatarProvider(IWebHostEnvironment environment, IETagGenerator eTagGenerator)
{
_environment = environment;
_eTagGenerator = eTagGenerator;
diff --git a/Timeline/Startup.cs b/Timeline/Startup.cs
index b5a5106b..f5ffe94e 100644
--- a/Timeline/Startup.cs
+++ b/Timeline/Startup.cs
@@ -1,11 +1,11 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpOverrides;
-using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
using Timeline.Authenticate;
using Timeline.Configs;
using Timeline.Entities;
@@ -16,23 +16,23 @@ namespace Timeline
{
public class Startup
{
- public Startup(IConfiguration configuration, IHostingEnvironment environment)
+ public Startup(IConfiguration configuration, IWebHostEnvironment environment)
{
Environment = environment;
Configuration = configuration;
}
- public IHostingEnvironment Environment { get; }
+ public IWebHostEnvironment Environment { get; }
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc()
- .ConfigureApiBehaviorOptions(options =>{
+ .ConfigureApiBehaviorOptions(options =>
+ {
options.InvalidModelStateResponseFactory = InvalidModelResponseFactory.Factory;
- })
- .SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
+ });
services.Configure<JwtConfig>(Configuration.GetSection(nameof(JwtConfig)));
var jwtConfig = Configuration.GetSection(nameof(JwtConfig)).Get<JwtConfig>();
@@ -75,9 +75,13 @@ namespace Timeline
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
+ app.UseRouting();
+
app.UseAuthentication();
- app.UseMvc();
+ app.UseEndpoints(endpoints =>
+ {
+ });
}
}
}
diff --git a/Timeline/Timeline.csproj b/Timeline/Timeline.csproj
index d414ab2f..836376d9 100644
--- a/Timeline/Timeline.csproj
+++ b/Timeline/Timeline.csproj
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
- <TargetFramework>netcoreapp2.2</TargetFramework>
+ <TargetFramework>netcoreapp3.0</TargetFramework>
<IsPackable>false</IsPackable>
<UserSecretsId>1f6fb74d-4277-4bc0-aeea-b1fc5ffb0b43</UserSecretsId>
<Authors>crupest</Authors>
@@ -13,11 +13,9 @@
</ItemGroup>
<ItemGroup>
- <PackageReference Include="Microsoft.AspNetCore.App" />
- <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
- <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.2.0" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql.Design" Version="1.1.2" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-dev002868" />
+ <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.5.0" />
</ItemGroup>
</Project>