From 7c021c429ea77dffdd877c3e2a0bcf6e881a7285 Mon Sep 17 00:00:00 2001 From: 杨宇千 Date: Wed, 25 Sep 2019 21:35:35 +0800 Subject: Init migration to dotnet core 3.0.0 . --- Timeline.Tests/Helpers/MyTestLoggerFactory.cs | 21 ++++++++++++++++----- Timeline.Tests/Helpers/MyWebApplicationFactory.cs | 6 +----- Timeline.Tests/IntegratedTests/UserAvatarTests.cs | 2 +- Timeline.Tests/Timeline.Tests.csproj | 15 +++++++-------- Timeline.Tests/UserAvatarServiceTest.cs | 4 ++-- Timeline.Tests/UserDetailServiceTest.cs | 4 ++-- Timeline/Program.cs | 3 ++- Timeline/Services/UserAvatarService.cs | 4 ++-- Timeline/Startup.cs | 18 +++++++++++------- Timeline/Timeline.csproj | 6 ++---- 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(); + var env = _factory.Server.Host.Services.GetRequiredService(); 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 @@  - netcoreapp2.2 + netcoreapp3.0 - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - + + + + + all 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(), _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(Configuration.GetSection(nameof(JwtConfig))); var jwtConfig = Configuration.GetSection(nameof(JwtConfig)).Get(); @@ -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 @@  - netcoreapp2.2 + netcoreapp3.0 false 1f6fb74d-4277-4bc0-aeea-b1fc5ffb0b43 crupest @@ -13,11 +13,9 @@ - - - + -- cgit v1.2.3