1
This commit is contained in:
1 parent
3135189ea3
commit
a003d90b0e
21 files changed
+754
-145
No files matched your search
@@ -1,3 +1,4 @@
|
||||
using Autofac;
|
||||
using System.Windows;
|
||||
using System.Windows.Threading;
|
||||
using Store.Management;
|
||||
@@ -19,7 +20,46 @@ class Program
|
||||
var handler = new LoginHandler();
|
||||
using var httpClient = new HttpClient(handler);
|
||||
using var client = new StoreApiClient(new ApiClientOptions { BaseUrl = new Uri("http://localhost:14312/api/") }, httpClient);
|
||||
var app = new App(client);
|
||||
if (args.Contains("--login-service"))
|
||||
{
|
||||
var extension = new Prism.Autofac.AutofacContainerExtension();
|
||||
extension.FinalizeExtension();
|
||||
using (var productionContainer = extension.Instance)
|
||||
{
|
||||
var productionClient = productionContainer.Resolve<StoreApiClient>();
|
||||
Check(ReferenceEquals(productionClient, productionContainer.Resolve<StoreApiClient>()), "自动注册 API 单例");
|
||||
Check(productionContainer.Resolve<Store.Management.Framework.Services.ILoginService>() != null, "自动注册登录服务");
|
||||
}
|
||||
var builder = new ContainerBuilder();
|
||||
builder.RegisterInstance(client);
|
||||
new Store.Management.Framework.DependencyInjection.ApiClientRegistration().Register(builder);
|
||||
builder.RegisterAssemblyTypes(typeof(Store.Management.Framework.Services.ILoginService).Assembly)
|
||||
.Where(type => typeof(MAX.Core.DependencyInjection.ISingletonDependency).IsAssignableFrom(type))
|
||||
.AsImplementedInterfaces().SingleInstance();
|
||||
using var container = builder.Build();
|
||||
Check(ReferenceEquals(client, container.Resolve<StoreApiClient>()), "保留测试客户端注册");
|
||||
var service = container.Resolve<Store.Management.Framework.Services.ILoginService>();
|
||||
using var vm = new LoginViewModel(service);
|
||||
vm.UserName = " admin ";
|
||||
vm.UpdatePassword("wrong");
|
||||
vm.LoginCommand.Execute().GetAwaiter().GetResult();
|
||||
Check(!client.Session.IsAuthenticated && vm.CanEdit, "登录失败后可以重试");
|
||||
ButtonResult? result = null;
|
||||
vm.RequestClose += response => result = response.Result;
|
||||
vm.UpdatePassword(" secret ");
|
||||
vm.LoginCommand.Execute().GetAwaiter().GetResult();
|
||||
Check(client.Session.IsAuthenticated && result == ButtonResult.OK, "Service 登录成功并通知关闭");
|
||||
using var closingVm = new LoginViewModel(service);
|
||||
closingVm.UserName = "admin";
|
||||
closingVm.UpdatePassword(" secret ");
|
||||
Task pending = closingVm.LoginCommand.Execute();
|
||||
closingVm.Dispose();
|
||||
pending.GetAwaiter().GetResult();
|
||||
Check(!closingVm.CanEdit && handler.RequestCount == 3, "关闭取消请求");
|
||||
Console.WriteLine("PASS: LoginViewModel -> ILoginService -> AuthApi, retry, password contract and cancellation.");
|
||||
return 0;
|
||||
}
|
||||
var app = new TestApp(client);
|
||||
app.InitializeComponent();
|
||||
int exitCode = 0;
|
||||
app.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(async () =>
|
||||
@@ -165,3 +205,12 @@ sealed class LoginHandler : HttpMessageHandler
|
||||
}
|
||||
|
||||
|
||||
|
||||
sealed class TestApp(StoreApiClient client) : App
|
||||
{
|
||||
protected override void RegisterTypes(IContainerRegistry containerRegistry)
|
||||
{
|
||||
base.RegisterTypes(containerRegistry);
|
||||
containerRegistry.RegisterInstance(client);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user