// ========================================================================== // Squidex Headless CMS // ========================================================================== // Copyright (c) Squidex UG (haftungsbeschraenkt) // All rights reserved. Licensed under the MIT license. // ========================================================================== using Microsoft.Extensions.Configuration; using Squidex.ClientLibrary; using Squidex.ClientLibrary.Configuration; using Squidex.ClientLibrary.Management; using TestSuite.Utils; namespace TestSuite { public sealed class ClientManagerWrapper { private readonly Lazy apps; private readonly Lazy assets; private readonly Lazy backups; private readonly Lazy languages; private readonly Lazy ping; private readonly Lazy rules; private readonly Lazy schemas; private readonly Lazy templates; public SquidexClientManager ClientManager { get; } public IAppsClient Apps { get => apps.Value; } public IAssetsClient Assets { get => assets.Value; } public IBackupsClient Backups { get => backups.Value; } public ILanguagesClient Languages { get => languages.Value; } public IPingClient Ping { get => ping.Value; } public IRulesClient Rules { get => rules.Value; } public ISchemasClient Schemas { get => schemas.Value; } public ITemplatesClient Templates { get => templates.Value; } public ClientManagerWrapper() { var appName = TestHelpers.GetValue("config:app:name", "integration-tests"); var clientId = TestHelpers.GetValue("config:client:id", "root"); var clientSecret = TestHelpers.GetValue("config:client:secret", "xeLd6jFxqbXJrfmNLlO2j1apagGGGSyZJhFnIuHp4I0="); var serverUrl = TestHelpers.GetValue("config:server:url", "https://localhost:5001"); ClientManager = new SquidexClientManager(new SquidexOptions { AppName = appName, ClientId = clientId, ClientSecret = clientSecret, ClientFactory = null, Configurator = AcceptAllCertificatesConfigurator.Instance, ReadResponseAsString = true, Url = serverUrl }); apps = new Lazy(() => { return ClientManager.CreateAppsClient(); }); assets = new Lazy(() => { return ClientManager.CreateAssetsClient(); }); backups = new Lazy(() => { return ClientManager.CreateBackupsClient(); }); languages = new Lazy(() => { return ClientManager.CreateLanguagesClient(); }); ping = new Lazy(() => { return ClientManager.CreatePingClient(); }); rules = new Lazy(() => { return ClientManager.CreateRulesClient(); }); schemas = new Lazy(() => { return ClientManager.CreateSchemasClient(); }); templates = new Lazy(() => { return ClientManager.CreateTemplatesClient(); }); } public async Task ConnectAsync() { var waitSeconds = TestHelpers.Configuration.GetValue("config:wait"); if (waitSeconds > 10) { Console.WriteLine("Waiting {0} seconds to access server", waitSeconds); var pingClient = ClientManager.CreatePingClient(); using (var cts = new CancellationTokenSource(waitSeconds * 1000)) { while (!cts.IsCancellationRequested) { try { await pingClient.GetPingAsync(cts.Token); break; } catch { await Task.Delay(100); } } } Console.WriteLine("Connected to server."); } else { Console.WriteLine("Waiting for server is skipped."); } return this; } } }