Ejemplo n.º 1
0
            protected override IServiceCollection ConfigureApi(IServiceCollection services)
            {
                var service = new TestRetryModelBuilder();

                services.AddService <IModelBuilder>((sp, next) => service);
                return(services);
            }
        public async Task GetModelAsyncRetriableAfterFailure()
        {
            var services = new ServiceCollection();
            var service  = new TestRetryModelBuilder();

            services.CutoffPrevious <IModelBuilder>(service);
            var configuration = services.BuildApiConfiguration();

            using (var wait = new ManualResetEventSlim(false))
            {
                var tasks = PrepareThreads(6, configuration, wait);
                wait.Set();

                await Task.WhenAll(tasks).ContinueWith(t =>
                {
                    Assert.True(t.IsFaulted);
                    Assert.True(tasks.All(e => e.IsFaulted));
                });

                Assert.Equal(1, service.CalledCount);

                tasks = PrepareThreads(150, configuration, wait);

                var models = await Task.WhenAll(tasks);

                Assert.Equal(2, service.CalledCount);
                Assert.True(models.All(e => object.ReferenceEquals(e, models[42])));
            }
        }
Ejemplo n.º 3
0
            public static new IServiceCollection ConfigureApi(Type apiType, IServiceCollection services)
            {
                ApiBase.ConfigureApi(apiType, services);
                var service = new TestRetryModelBuilder();

                services.AddService <IModelBuilder>((sp, next) => service);

                return(services);
            }
            public static new IServiceCollection ConfigureApi(Type apiType, IServiceCollection services)
            {
                var service = new TestRetryModelBuilder();
                services.AddService<IModelBuilder>((sp, next) => service);

                services.AddScoped(apiType, apiType)
                    .AddScoped(typeof(ApiBase), apiType)
                    .AddScoped<ApiContext>();

                services.TryAddSingleton<ApiConfiguration>();

                return services;
            }
            public static new IServiceCollection ConfigureApi(Type apiType, IServiceCollection services)
            {
                var changeSetPreparer      = new TestChangeSetInitializer();
                var submitExecutor         = new TestSubmitExecutor();
                var queryExpressionSourcer = new TestQueryExpressionSourcer();

                ApiBase.ConfigureApi(apiType, services);
                services.AddService <IChangeSetInitializer>((sp, next) => changeSetPreparer);
                services.AddService <ISubmitExecutor>((sp, next) => submitExecutor);
                services.AddService <IQueryExpressionSourcer>((sp, next) => queryExpressionSourcer);

                var service = new TestRetryModelBuilder();

                services.AddService <IModelBuilder>((sp, next) => service);

                return(services);
            }
Ejemplo n.º 6
0
        public async Task GetModelAsyncRetriableAfterFailure()
        {
            var services = new ServiceCollection();
            var service = new TestRetryModelBuilder();
            services.CutoffPrevious<IModelBuilder>(service);
            var configuration = services.BuildApiConfiguration();

            using (var wait = new ManualResetEventSlim(false))
            {
                var tasks = PrepareThreads(6, configuration, wait);
                wait.Set();

                await Task.WhenAll(tasks).ContinueWith(t =>
                {
                    Assert.True(t.IsFaulted);
                    Assert.True(tasks.All(e => e.IsFaulted));
                });
                Assert.Equal(1, service.CalledCount);

                tasks = PrepareThreads(150, configuration, wait);

                var models = await Task.WhenAll(tasks);
                Assert.Equal(2, service.CalledCount);
                Assert.True(models.All(e => object.ReferenceEquals(e, models[42])));
            }
        }