コード例 #1
0
        /// <summary>
        /// Ctor using given <see cref="Configuration"/>, <see cref="Serializer"/>
        /// <see cref="PageGetter"/> and <see cref="UrlBuilder"/> classes
        /// </summary>
        /// <param name="config"><see cref="Configuration"/> class for News Service</param>
        /// <param name="serializer"><see cref="Serializer"/> class for serializing last reports DateTime check</param>
        /// <param name="pageGetter"><see cref="PageGetter"/></param>
        /// <param name="urlBuilder"><see cref="UrlBuilder"/></param>
        public NewsService(IConfiguration config, ISerializer serializer, IPageGetter pageGetter, IUrlBuilder urlBuilder)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            if (serializer == null)
            {
                throw new ArgumentNullException("serializer");
            }
            if (pageGetter == null)
            {
                throw new ArgumentNullException("pageGetter");
            }
            if (urlBuilder == null)
            {
                throw new ArgumentNullException("urlBuilder");
            }

            _config     = config;
            _serializer = serializer;
            _urlBuilder = urlBuilder;
            _pageGetter = pageGetter;
            //TODO: remove LastReportsCheckDateTime from NewsService, use this one from Configuration class, read(deserialize) in GetReportsFromLastCheckTime()
            LastReportsCheckDateTime = _config.LastReportsCheckDateTime == default(DateTime)
                ? _serializer.Deserialize <DateTime>(_config.Path)
                : default(DateTime);
            Log.Info("News service ctor called");
        }
コード例 #2
0
        public NewsServiceTests()
        {
            _config      = MockRepository.GenerateMock <IConfiguration>();
            _config.Path = "LastReportsCheckDateTime.json";
            var serializer = MockRepository.GenerateMock <ISerializer>();

            serializer.Stub(e => e.Deserialize <DateTime>(_config.Path)).Return(default(DateTime));
            _pageGetter = MockRepository.GenerateMock <IPageGetter>();
            _urlBuilder = MockRepository.GenerateMock <IUrlBuilder>();
            _urlBuilder.Stub(e => e.GetUrlFromDate(Arg <DateTime> .Is.Anything, Arg <int> .Is.Equal(1)))
            .Return(SampleUrl);
            _urlBuilder.Stub(e => e.GetServerAddress()).Return("http");

            _sut = new NewsService.NewsService(_config, serializer, _pageGetter, _urlBuilder);

            _config.AssertWasCalled(e => e.Path);
            _config.AssertWasCalled(e => e.LastReportsCheckDateTime);
            serializer.AssertWasCalled(e => e.Deserialize <DateTime>(_config.Path));
            Assert.IsType <NewsService.NewsService>(_sut);
        }
コード例 #3
0
 public VantageCrawler(IPageGetter getter, IPageHandler pageHandler, IDocHandler docHandler = null)
 {
     this.getter      = getter ?? throw new ArgumentNullException(nameof(getter));
     this.docHandler  = docHandler;
     this.pageHandler = pageHandler;
 }