示例#1
0
        public async Task Initilize(int parallelTasks)
        {
            _collection = new ModuleCollection();

            ModelsRegistration.RegisterModules(_collection);
            PostModelsRegistration.RegisterModules(_collection);
            _collection.RegisterModule <EsentInstanceProvider, IEsentInstanceProvider>(new EsentInstanceProvider(true));
            _collection.RegisterModule <PostModelStore, IBoardPostStore>(new PostModelStore("makaba", parallelTasks));
            _collection.RegisterModule <MakabaBoardReferenceDtoParsers, INetworkDtoParsers>();
            _collection.RegisterModule <MakabaBoardReferenceDtoParsers, INetworkDtoParsers>();
            _collection.RegisterModule <YoutubeIdService, IYoutubeIdService>();
            _collection.RegisterModule <MakabaLinkParser, IEngineLinkParser>();
            _collection.RegisterModule <AgilityHtmlDocumentFactory, IHtmlDocumentFactory>();
            _collection.RegisterModule <MakabaHtmlParser, IHtmlParser>();
            _collection.RegisterModule <MakabaPostDtoParsers, INetworkDtoParsers>();
            MakabaModelsRegistration.RegisterModules(_collection);

            TableVersionStatusForTests.ClearInstance();
            await _collection.Seal();

            _provider = _collection.GetModuleProvider();
            var module = _provider.QueryModule(typeof(IBoardPostStore), "makaba") ?? throw new ModuleNotFoundException();

            _store = module.QueryView <IBoardPostStore>() ?? throw new ModuleNotFoundException();
        }
示例#2
0
        public async Task Initialize()
        {
            _collection = new ModuleCollection();
            LinkModelsRegistration.RegisterModules(_collection);
            await _collection.Seal();

            _modules = _collection.GetModuleProvider();
        }
示例#3
0
        public async Task Initialize()
        {
            _collection = new ModuleCollection();
            _collection.RegisterModule <MakabaNetworkConfig, IMakabaNetworkConfig>();
            _collection.RegisterModule <CommonUriGetter, INetworkUriGetter>();
            _collection.RegisterModule <MakabaUriGetter, INetworkUriGetter>();

            await _collection.Seal();

            _provider = _collection.GetModuleProvider();
        }
示例#4
0
        public async Task Initialize()
        {
            _collection = new ModuleCollection();
            _collection.RegisterModule <ObjectSerializationService, IObjectSerializationService>();
            PostModelsRegistration.RegisterModules(_collection);
            LinkModelsRegistration.RegisterModules(_collection);
            _collection.RegisterModule <FakeExternalPostMediaSerializer, IObjectSerializer>();
            _collection.RegisterModule <FakePostAttributeSerializer, IObjectSerializer>();
            _collection.RegisterModule <FakePostNodeSerializer, IObjectSerializer>();
            await _collection.Seal();

            _modules = _collection.GetModuleProvider();
        }
示例#5
0
        public async Task Initialize()
        {
            _collection = new ModuleCollection();

            LinkModelsRegistration.RegisterModules(_collection);
            CommonSerializationRegistration.RegisterModules(_collection);
            _collection.RegisterModule <EsentInstanceProvider, IEsentInstanceProvider>(new EsentInstanceProvider(true));
            _collection.RegisterModule <BlobsModelStore, IBlobsModelStore>();
            _collection.RegisterModule <MakabaBoardReferenceDtoParsers, INetworkDtoParsers>();

            TableVersionStatusForTests.ClearInstance();
            await _collection.Seal();

            _provider = _collection.GetModuleProvider();
            var module = _provider.QueryModule <object>(typeof(IBlobsModelStore), null) ?? throw new ModuleNotFoundException();

            _store = module.QueryView <IBlobsModelStore>() ?? throw new ModuleNotFoundException();
        }
示例#6
0
        public async Task MakabaNetworkConfig()
        {
            var config = _provider.QueryModule <IMakabaNetworkConfig>();

            Assert.AreEqual(new Uri("https://2ch.hk/"), config.BaseUri, "Значение по умолчанию не совпадает");
            config.BaseUri = new Uri("http://2ch.so/");
            await config.Save();

            await _collection.Dispose();

            _collection = new ModuleCollection();
            _collection.RegisterModule <MakabaNetworkConfig, IMakabaNetworkConfig>();
            _collection.RegisterModule <CommonUriGetter, INetworkUriGetter>();
            _collection.RegisterModule <MakabaUriGetter, INetworkUriGetter>();

            await _collection.Seal();

            _provider = _collection.GetModuleProvider();

            Assert.AreEqual(new Uri("http://2ch.so/"), config.BaseUri, "Значение не совпадает");
        }
示例#7
0
        public async Task TestAttachedLifetime()
        {
            var collection = new ModuleCollection();
            await collection.Seal();

            var provider = collection.GetModuleProvider();

            var modules = new SuspensionAwareModule[]
            {
                new SuspensionAwareModule(true, true),
                new SuspensionAwareModule(true, true),
                new SuspensionAwareModule(true, true),
                new SuspensionAwareModule(true, true),
            };

            var suspendTasks = new List <Task>();
            var resumeTasks  = new List <Task>();
            var disposeTasks = new List <Task>();

            foreach (var m in modules)
            {
                var lt  = m.QueryView <IModuleLifetime>();
                var lte = m.QueryView <IModuleLifetimeEvents>();
                Assert.IsNotNull(lt, "Модуль должен поддерживать управление временем жизни");
                Assert.IsNotNull(lte, "Модуль должен поддерживать события времени жизни");
                await lt.InitializeModule(provider);

                var tcsd  = new TaskCompletionSource <bool>();
                var tcss  = new TaskCompletionSource <bool>();
                var tcsr  = new TaskCompletionSource <bool>();
                var tcsar = new TaskCompletionSource <bool>();
                lte.Disposed += _ =>
                {
                    tcsd.SetResult(true);
                };
                lte.Suspended += _ =>
                {
                    tcss.SetResult(true);
                };
                lte.Resumed += _ =>
                {
                    tcsr.SetResult(true);
                };
                lte.AllResumed += _ =>
                {
                    tcsar.SetResult(true);
                };
                disposeTasks.Add(tcsd.Task);
                suspendTasks.Add(tcss.Task);
                resumeTasks.Add(tcsr.Task);
                resumeTasks.Add(tcsar.Task);
            }

            foreach (var m in modules)
            {
                var lt = m.QueryView <IModuleLifetime>();
                await lt.AllModulesInitialized();
            }

            foreach (var m in modules)
            {
                Assert.IsFalse(m.IsSuspended, "Модуль не должен быть приостановлен");
            }

            await collection.Suspend();

            var suspendWaiter = new Task[]
            {
                Task.WhenAll(suspendTasks.ToArray()),
                Task.Delay(TimeSpan.FromSeconds(10))
            };
            var suspendResult = await Task.WhenAny(suspendWaiter);

            Assert.AreSame(suspendWaiter[0], suspendResult, "Сработал таймаут по событию Suspended");
            foreach (var m in modules)
            {
                Assert.IsTrue(m.IsSuspended, "Модуль должен быть приостановлен");
            }
            await collection.Resume();

            var resumeWaiter = new Task[]
            {
                Task.WhenAll(resumeTasks.ToArray()),
                Task.Delay(TimeSpan.FromSeconds(10))
            };
            var resumeResult = await Task.WhenAny(resumeWaiter);

            Assert.AreSame(resumeWaiter[0], resumeResult, "Сработал таймаут по событию Resumed");
            foreach (var m in modules)
            {
                Assert.IsFalse(m.IsSuspended, "Модуль не должен быть приостановлен после Resume");
                Assert.IsTrue(m.IsAllResumed, "Должен быть вызван метод AllResumed()");
                Assert.AreEqual(1, m.AllResumedCount, "Метод AllResumed() должен быть вызван один раз");
            }
            await collection.Dispose();

            var disposeWaiter = new Task[]
            {
                Task.WhenAll(disposeTasks.ToArray()),
                Task.Delay(TimeSpan.FromSeconds(10))
            };
            var disposeResult = await Task.WhenAny(disposeWaiter);

            Assert.AreSame(disposeWaiter[0], disposeResult, "Сработал таймаут по событию Disposed");
            foreach (var m in modules)
            {
                Assert.IsTrue(m.IsDisposed, "Модуль должен быть завершён");
            }
        }