Exemple #1
0
    private async Task <IServiceProvider> setup(AppVersionKey versionKey, string domain = "www.xartogg.com")
    {
        var host = Host.CreateDefaultBuilder()
                   .ConfigureServices
                   (
            (hostContext, services) =>
        {
            services.AddMemoryCache();
            services.AddFakesForXtiWebApp(hostContext.Configuration);
            services.AddSingleton <FakeAppOptions>();
            services.AddSingleton(sp => FakeInfo.AppKey);
            services.AddScoped <FakeAppApiFactory>();
            services.AddScoped <AppApiFactory>(sp => sp.GetRequiredService <FakeAppApiFactory>());
            services.AddScoped <FakeAppSetup>();
            services.AddSingleton(_ => new FakeAppClientDomain(domain));
            services.AddSingleton(sp =>
            {
                var cache      = sp.GetRequiredService <IMemoryCache>();
                var appClients = new AppClients(cache);
                appClients.AddAppVersion("Fake", "Current");
                appClients.AddAppClientDomain(sp.GetRequiredService <FakeAppClientDomain>());
                return(appClients);
            });
        }
                   )
                   .Build();
        var scope        = host.Services.CreateScope();
        var sp           = scope.ServiceProvider;
        var pathAccessor = (FakeXtiPathAccessor)sp.GetRequiredService <IXtiPathAccessor>();

        pathAccessor.SetPath
        (
            new XtiPath
            (
                FakeInfo.AppKey.Name.DisplayText,
                versionKey.DisplayText,
                "",
                "",
                ModifierKey.Default
            )
        );
        var setup = sp.GetRequiredService <FakeAppSetup>();
        await setup.Run(AppVersionKey.Current);

        var userContext = sp.GetRequiredService <FakeUserContext>();

        userContext.AddUser(new AppUserName("someone"));
        return(sp);
    }
    public static void ConfigureAppClients(this IServiceCollection services, Action <AppClients> configure)
    {
        var existing = services.FirstOrDefault(s => s.ImplementationType == typeof(AppClients));

        if (existing != null)
        {
            services.Remove(existing);
        }
        services.AddScoped
        (
            sp =>
        {
            var cache      = sp.GetRequiredService <IMemoryCache>();
            var appClients = new AppClients(cache);
            var appKey     = sp.GetRequiredService <AppKey>();
            var versionKey = sp.GetRequiredService <AppVersionKey>();
            appClients.AddAppVersion(appKey.Name.DisplayText, versionKey.DisplayText);
            appClients.AddAppClientDomain(sp.GetRequiredService <SelfAppClientDomain>());
            configure(appClients);
            return(appClients);
        }
        );
    }