Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate to asp.net core 3.0 #28

Merged
merged 28 commits into from Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b3c73f2
add retryHelper
WeihanLi Sep 11, 2019
95efa36
update to aspnetcore3.0
WeihanLi Sep 24, 2019
c40834c
disable dotnet build
WeihanLi Sep 24, 2019
4347c22
update Dockerfile
WeihanLi Sep 24, 2019
7e1573f
fix error for asp.net core 3.0
WeihanLi Sep 24, 2019
f05b537
use sqlServer instead of mysql
WeihanLi Sep 24, 2019
f0dd9b3
add Globalization Invariant Mode config
WeihanLi Sep 24, 2019
9f707df
install icu-lib
WeihanLi Sep 24, 2019
4d07d60
update DOckerfile, set DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false
WeihanLi Sep 25, 2019
9ebe52e
update swagger/update test to 3.0
WeihanLi Sep 25, 2019
619f796
update entityFramework extension
WeihanLi Sep 25, 2019
cd02027
add cleanData.sql
WeihanLi Sep 25, 2019
2f4e696
downgrade ef to 2.x
WeihanLi Sep 26, 2019
de4321e
fix init notice data
WeihanLi Sep 26, 2019
18da9fd
update swagger version
WeihanLi Oct 8, 2019
96046da
fix init data, only supper for admin user
WeihanLi Oct 8, 2019
6198322
integrate with swagger
WeihanLi Oct 8, 2019
f614ac9
remove admin route
WeihanLi Oct 8, 2019
c760901
fix test
WeihanLi Oct 8, 2019
5b841d2
use swagger before useRounting
WeihanLi Oct 10, 2019
fdd2835
update build agent image
WeihanLi Oct 10, 2019
d3c4bec
output dotnet info on ci build
WeihanLi Oct 10, 2019
332ae14
update pipeline config
WeihanLi Oct 10, 2019
64e7511
update the method get framework version
WeihanLi Oct 10, 2019
6e5a824
update footer
WeihanLi Oct 10, 2019
c147e77
update ChatBotHelper
WeihanLi Oct 10, 2019
cf23e66
update mvcSimplePager
WeihanLi Oct 10, 2019
6a55519
update dependency
WeihanLi Oct 11, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -15,6 +15,7 @@

# Build results
[Dd]ebug/
[Oo]ut/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
Expand Down
18 changes: 2 additions & 16 deletions ActivityReservation.API.Test/APITestFixture.cs
@@ -1,12 +1,11 @@
using System;
using System.Linq;
using System.Net.Http;
using System.Net.NetworkInformation;
using ActivityReservation.Database;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using WeihanLi.Common.Helpers;
using Xunit;

namespace ActivityReservation.API.Test
Expand All @@ -23,7 +22,7 @@ public class APITestFixture : IDisposable

public APITestFixture()
{
var baseUrl = $"http://localhost:{GetRandomPort()}";
var baseUrl = $"http://localhost:{NetHelper.GetRandomPort()}";
_server = WebHost.CreateDefaultBuilder()
.UseUrls(baseUrl)
.UseStartup<TestStartup>()
Expand Down Expand Up @@ -66,19 +65,6 @@ public void Dispose()

Console.WriteLine("test end");
}

private static int GetRandomPort()
{
var random = new Random();
var randomPort = random.Next(10000, 65535);

while (IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners().Any(p => p.Port == randomPort))
{
randomPort = random.Next(10000, 65535);
}

return randomPort;
}
}

[CollectionDefinition("APITestCollection")]
Expand Down
11 changes: 4 additions & 7 deletions ActivityReservation.API.Test/ActivityReservation.API.Test.csproj
@@ -1,15 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp3.0</TargetFramework>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.AzureKeyVault" Version="2.2.0" />

<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="2.1.11" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
Expand Down
@@ -0,0 +1,24 @@
using System.Threading.Tasks;
using ActivityReservation.Database;
using ActivityReservation.Events;
using WeihanLi.Common;
using WeihanLi.Common.Event;

namespace ActivityReservation.API.Test.MockServices
{
internal class MockNoticeViewEventHandler : IEventHandler<NoticeViewEvent>
{
public async Task Handle(NoticeViewEvent @event)
{
await DependencyResolver.Current.TryInvokeServiceAsync<ReservationDbContext>(async dbContext =>
{
var notice = await dbContext.Notices.FindAsync(@event.NoticeId);
if (null != notice)
{
notice.NoticeVisitCount += 1;
await dbContext.SaveChangesAsync();
}
});
}
}
}
184 changes: 184 additions & 0 deletions ActivityReservation.API.Test/TestDataInitializer.cs
@@ -0,0 +1,184 @@
using System;
using System.Collections.Generic;
using System.Linq;
using ActivityReservation.Database;
using ActivityReservation.Models;
using ActivityReservation.Services;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using WeihanLi.Common.Helpers;

namespace ActivityReservation.API.Test
{
internal class TestDataInitializer
{
public static void Initialize(IServiceProvider serviceProvider)
{
IReadOnlyCollection<SystemSettings> settings;

using (var scope = serviceProvider.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<ReservationDbContext>();
dbContext.Database.EnsureCreated();
if (!dbContext.Users.AsNoTracking().Any())
{
dbContext.Users.Add(new User
{
UserId = Guid.NewGuid(),
UserName = "admin",
UserPassword = SecurityHelper.SHA256("Admin888"),
IsSuper = true
});
dbContext.Users.Add(new User
{
UserId = Guid.NewGuid(),
UserName = "Alice",
UserPassword = SecurityHelper.SHA256("Test1234"),
IsSuper = false
});
dbContext.Users.Add(new User
{
UserId = Guid.NewGuid(),
UserName = "test",
UserPassword = SecurityHelper.SHA256("Test1234"),
IsSuper = false
});

var blockTypes = new List<BlockType>
{
new BlockType {TypeId = Guid.NewGuid(), TypeName = "联系方式"},
new BlockType {TypeId = Guid.NewGuid(), TypeName = "IP地址"},
new BlockType {TypeId = Guid.NewGuid(), TypeName = "预约人姓名"}
};
dbContext.BlockTypes.AddRange(blockTypes);

var placeId = Guid.NewGuid();
var placeId1 = Guid.NewGuid();
//Places init
dbContext.ReservationPlaces.AddRange(new[] {
new ReservationPlace { PlaceId = placeId, PlaceName = "第一多功能厅", UpdateBy = "System", PlaceIndex = 0,MaxReservationPeriodNum = 2 },
new ReservationPlace { PlaceId = placeId1, PlaceName = "第二多功能厅", UpdateBy = "System", PlaceIndex = 1,MaxReservationPeriodNum = 2}}
);

dbContext.ReservationPeriods.AddRange(new[]
{
new ReservationPeriod
{
PeriodId = Guid.NewGuid(),
PeriodIndex = 0,
PeriodTitle = "8:00~10:00",
PeriodDescription = "8:00~10:00",
PlaceId = placeId,
CreateBy = "System",
CreateTime = DateTime.UtcNow,
UpdateBy = "System",
UpdateTime = DateTime.UtcNow
},
new ReservationPeriod
{
PeriodId = Guid.NewGuid(),
PeriodIndex = 1,
PeriodTitle = "10:00~12:00",
PeriodDescription = "10:00~12:00",
PlaceId = placeId,
CreateBy = "System",
CreateTime = DateTime.UtcNow,
UpdateBy = "System",
UpdateTime = DateTime.UtcNow
},
new ReservationPeriod
{
PeriodId = Guid.NewGuid(),
PeriodIndex = 2,
PeriodTitle = "13:00~16:00",
PeriodDescription = "13:00~16:00",
PlaceId = placeId,
CreateBy = "System",
CreateTime = DateTime.UtcNow,
UpdateBy = "System",
UpdateTime = DateTime.UtcNow
},
new ReservationPeriod
{
PeriodId = Guid.NewGuid(),
PeriodIndex = 1,
PeriodTitle = "08:00~18:00",
PeriodDescription = "08:00~18:00",
PlaceId = placeId1,
CreateBy = "System",
CreateTime = DateTime.UtcNow.AddSeconds(3),
UpdateBy = "System",
UpdateTime = DateTime.UtcNow
},
});
var notice = new Notice()
{
NoticeId = Guid.NewGuid(),
CheckStatus = true,
NoticeTitle = "测试公告",
NoticeCustomPath = "test-notice",
NoticePath = "test-notice.html",
NoticeContent = "测试一下",
NoticePublishTime = DateTime.UtcNow,
NoticeDesc = "测试一下",
NoticePublisher = "System"
};
dbContext.Notices.Add(notice);

//sys settings init
settings = new List<SystemSettings>
{
new SystemSettings
{
SettingId = Guid.NewGuid(),
SettingName = "SystemTitle",
DisplayName = "系统标题",
SettingValue = "活动室预约系统"
},
new SystemSettings
{
SettingId = Guid.NewGuid(),
SettingName = "SystemKeywords",
DisplayName = "系统关键词",
SettingValue = "预约,活动室,预定,reservation"
},
new SystemSettings
{
SettingId = Guid.NewGuid(),
SettingName = "SystemDescription",
DisplayName = "系统简介",
SettingValue = "活动室预约系统是一个基于ASP.NET MVC 开发的一个在线预约系统。"
},
new SystemSettings
{
SettingId = Guid.NewGuid(),
SettingName = "SystemContactPhone",
DisplayName = "系统联系人联系电话",
SettingValue = "13245642365"
},
new SystemSettings
{
SettingId = Guid.NewGuid(),
SettingName = "SystemContactEmail",
DisplayName = "系统联系邮箱",
SettingValue = "weihanli@outlook.com"
}
};
dbContext.SystemSettings.AddRange(settings);

dbContext.SaveChanges();
}
else
{
settings = dbContext.SystemSettings.AsNoTracking().ToArray();
}
}

if (settings.Count > 0) // init settings cache
{
var applicationSettingService = serviceProvider.GetRequiredService<IApplicationSettingService>();
applicationSettingService.AddSettings(settings.ToDictionary(s => s.SettingName, s => s.SettingValue));
}
}
}
}
36 changes: 13 additions & 23 deletions ActivityReservation.API.Test/TestStartup.cs
Expand Up @@ -36,8 +36,9 @@ public TestStartup(IConfiguration configuration)
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc()
.AddJsonOptions(options =>
services.AddControllers()
.AddApplicationPart(typeof(API.ApiControllerBase).Assembly)
.AddNewtonsoftJson(options =>
{
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc; // 设置时区为 UTC
Expand All @@ -51,8 +52,6 @@ public void ConfigureServices(IServiceCollection services)
// addDbContext
services.AddDbContextPool<ReservationDbContext>(options => options.UseInMemoryDatabase("Reservation"));

services.TryAddSingleton<ICacheClient, MockRedisCacheClient>();

services.AddHttpClient<TencentCaptchaHelper>(client => client.Timeout = TimeSpan.FromSeconds(3))
.ConfigurePrimaryHttpMessageHandler(() => new NoProxyHttpClientHandler());
services.AddTencentCaptchaHelper(options =>
Expand All @@ -69,14 +68,17 @@ public void ConfigureServices(IServiceCollection services)

// registerApplicationSettingService
services.TryAddSingleton<IApplicationSettingService, ApplicationSettingInMemoryService>();
// register access control service
services.AddAccessControlHelper<Filters.AdminPermissionRequireStrategy, Filters.AdminOnlyControlAccessStrategy>();

services.TryAddSingleton<CaptchaVerifyHelper>();

services.AddSingleton<IEventBus, EventBus>();
services.AddSingleton<IEventStore, EventStoreInMemory>();
//register EventHandlers
services.AddSingleton<OperationLogEventHandler>();
services.AddSingleton<NoticeViewEventHandler>();
services.AddSingleton<MockNoticeViewEventHandler>();

services.TryAddSingleton<ICacheClient, MockRedisCacheClient>();

// SetDependencyResolver
DependencyResolver.SetDependencyResolver(services);
Expand All @@ -85,27 +87,15 @@ public void ConfigureServices(IServiceCollection services)
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IEventBus eventBus)
{
eventBus.Subscribe<NoticeViewEvent, NoticeViewEventHandler>(); // 公告
eventBus.Subscribe<OperationLogEvent, OperationLogEventHandler>(); //操作日志

app.UseMvc(routes =>
app.UseRouting();
app.UseEndpoints(endpoints =>
{
routes.MapRoute("Notice", "/Notice/{path}.html", new
{
controller = "Home",
action = "NoticeDetails"
});

routes.MapRoute(name: "areaRoute",
template: "{area:exists}/{controller=Home}/{action=Index}");

routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}");
endpoints.MapControllers();
});

// initialize
app.ApplicationServices.Initialize();
eventBus.Subscribe<NoticeViewEvent, MockNoticeViewEventHandler>();
TestDataInitializer.Initialize(app.ApplicationServices);
}
}
}
5 changes: 0 additions & 5 deletions ActivityReservation.API.Test/appsettings.json
@@ -1,9 +1,4 @@
{
"KeyVault": {
"Name": "weihanli",
"ClientId": "31e1c36d-5d98-4a45-9553-33b7fc871a66",
"ClientSecret": "4VdVPsvDO+rwzQ6rOWxN2oAA4cgBlvqcWyPoiMcxW3Y="
},
"ConnectionStrings": {
"Redis": "127.0.0.1"
},
Expand Down
2 changes: 1 addition & 1 deletion ActivityReservation.API/APIControllerBase.cs
Expand Up @@ -9,7 +9,7 @@ public abstract class ApiControllerBase : ControllerBase
{
protected readonly ILogger Logger;

public ApiControllerBase(ILogger logger)
protected ApiControllerBase(ILogger logger)
{
Logger = logger;
}
Expand Down
2 changes: 1 addition & 1 deletion ActivityReservation.API/ActivityReservation.API.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netcoreapp3.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>
Expand Down
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ActivityReservation.Helper\ActivityReservation.Helper.csproj" />
Expand Down