Example #1
0
        public void Test()
        {
            var config = new MockProviderConfig();

            var watcher = new UpdatesWatcher(
                NullLogger <UpdatesWatcher> .Instance,
                new MockUpdatesProvider(),
                config);

            Update[] updates = watcher.Updates.Take(10).ToEnumerable().ToArray();

            for (var i = 0; i < updates.Length; i++)
            {
                var watchedUser = config.WatchedUsers.ElementAtOrDefault(i) ?? config.WatchedUsers.LastOrDefault();
                var author      = updates[i].Author;

                Assert.Equal(
                    watchedUser,
                    author);
            }
        }
Example #2
0
        private void RegisterProducers()
        {
            foreach ((IUpdatesProvider provider, ProviderConfig config) in GetProviders())
            {
                try
                {
                    var usersWatcher = new UpdatesWatcher(
                        _loggerFactory.CreateLogger($"{provider.GetType().Name}-{nameof(UpdatesWatcher)}"),
                        provider,
                        config);

                    usersWatcher.Updates
                    .Subscribe(OnProducerUpdate);

                    _logger.LogInformation($"Subscribed to updates of the producer `{provider.GetType() .Name}`");
                }
                catch (Exception e)
                {
                    _logger.LogError(e, "Exception in RegisterProducers()");
                }
            }
        }