예제 #1
0
        public async Task TestConcurrencyAppending()
        {
            var providers = new ConcurrentBag <ISocialMediaProvider>();

            Append(providers);

            var @operator = new ProvidersOperator();

            Append(providers);

            foreach (ISocialMediaProvider provider in providers)
            {
                @operator.Providers.Add(provider);
            }

            await Task.Run(() => @operator.OperateOnAllAsync(Operation));

            Append(providers);

            await Task.Delay(_delay * 2 * 2);

            Assert.Equal(2 - 1, OperationCounter);
        }
예제 #2
0
        private void AddMediaManagerComponents(IServiceCollection services)
        {
            IPostOperationValidator validator = new PostOperationValidator();

            services.AddSingleton(validator);

            IProvidersOperator @operator = new ProvidersOperator();

            services.AddSingleton(@operator);

            IPostsChecker postsChecker = new PostsChecker(validator, @operator);

            services.AddSingleton(postsChecker);

            var intervalSeconds = Convert.ToDouble(
                Configuration["MediaManager:WatchIntervalSeconds"]);

            IPostsWatcher postsWatcher = new PostsWatcher(
                TimeSpan.FromSeconds(intervalSeconds),
                postsChecker);

            services.AddSingleton(postsWatcher);
        }