Пример #1
0
        protected override void OnStart(string[] args)
        {
            IKernel appKernel = new StandardKernel(new CrawlerNinjectModule());

            appKernel.Bind<IDictionary<Type, IStatistics>>()
                .To<StatisticsContainer>()
                .WithConstructorArgument("args", StatisticsTypes);

             _crawler = appKernel.Get<Crawler>();

            _worker = new Thread(DoWork);
            _worker.Start();
        }
Пример #2
0
        public void CrawlerScanningWithNotExistingOrPrivateGroup_ThrowsArgumentException()
        {
            // arrange
            _vkClientMock.Setup(m => m.GetGroup(It.IsAny<IEnumerable<string>>())).Returns(new List<VkGroup>
            {
                new VkGroup {PrivacySettings = (int) PrivacySettings.Closed}
            });
            var totalCount = 3;
            _vkClientMock.Setup(
                m => m.GetWallPosts(It.IsAny<string>(), It.Is<int>(i => i == 0), out totalCount, It.IsAny<int>()))
                .Returns(_firstPostsList);
            _vkClientMock.Setup(m => m.GetWallPosts(It.IsAny<string>(), It.Is<int>(i => i == 2), out totalCount,
                It.IsAny<int>())).Returns(_secondPostsList);

            _crawler = new Crawler(_postsRepositoryMock.Object, _statisticsRepositoryMock.Object,
                _collectionsRepositoryMock.Object, _statisticsContainer, _vkClientMock.Object) {Name = "test"};
            // act

            // assert
            Assert.Throws<ArgumentException>(_crawler.Scanning);
        }
Пример #3
0
        public void CrawlerScanningSavesAllPostsToRepository()
        {
            // arrange
            _vkClientMock.Setup(m => m.GetGroup(It.IsAny<IEnumerable<string>>())).Returns(new List<VkGroup>
            {
                new VkGroup {PrivacySettings = (int) PrivacySettings.Public}
            });
            var totalCount = 3;
            _vkClientMock.Setup(
                m => m.GetWallPosts(It.IsAny<string>(), It.Is<int>(i => i == 0), out totalCount, It.IsAny<int>()))
                .Returns(_firstPostsList);
            _vkClientMock.Setup(
                m => m.GetWallPosts(It.IsAny<string>(), It.Is<int>(i => i == 2), out totalCount, It.IsAny<int>()))
                .Returns(_secondPostsList);
            _crawler = new Crawler(_postsRepositoryMock.Object, _statisticsRepositoryMock.Object,
                _collectionsRepositoryMock.Object, _statisticsContainer, _vkClientMock.Object)
            { Name = "test" };

            // act
            _crawler.Scanning();

            // assert
            _postsRepositoryMock.Verify(m => m.SaveAsync(It.IsAny<VkPost>()), Times.Exactly(_firstPostsList.Count + _secondPostsList.Count));
        }