public void BeforeAll()
        {
            var items = new[] { new SyndicationItem(), new SyndicationItem() };
            var feed  = new SyndicationFeed(items)
            {
                LastUpdatedTime = _lastUpdateTime
            };

            var mapper = MockRepository.GenerateStub <IMapper <SyndicationItem, LibraryItem> >();

            mapper.Stub(m => m.Map(Arg <SyndicationItem> .Is.Anything)).Return(new LibraryItem());

            var reader = MockRepository.GenerateStub <XmlReader>();

            var xmlReaderFactory = MockRepository.GenerateStub <IFactory <string, XmlReader> >();

            xmlReaderFactory.Stub(factory => factory.Create(_feedUrl)).Return(reader);

            var syndicationFeedFactory = MockRepository.GenerateStub <IFactory <XmlReader, SyndicationFeed> >();

            syndicationFeedFactory.Stub(factory => factory.Create(reader)).Return(feed);

            var command = new GetNewLibraryItemsCommand(mapper, xmlReaderFactory, syndicationFeedFactory);

            var request = new Request <string> {
                Parameter = _feedUrl
            };

            _response = command.Execute(request);
        }
Beispiel #2
0
        public GetNewLibraryItemsResponse Execute(Request <string> request)
        {
            var reader = _xmlReaderFactory.Create(request.Parameter);
            var feed   = _syndicationFeedFactory.Create(reader);

            if (feed == null)
            {
                throw new ApplicationException(string.Format("Unable to connect to feed at {0}", request.Parameter));
            }

            var newItems = feed.Items
                           .Select(_itemMapper.Map)
                           .ToList()
            ;

            var response = new GetNewLibraryItemsResponse
            {
                LastUpdatedAt = feed.LastUpdatedTime.DateTime,
                Items         = newItems
            };

            reader.Close();

            return(response);
        }
        private IEnumerable <SearchResult> GetMatchingNewItems(GetNewLibraryItemsResponse newItems, QueryResponse <SearchableItem> searchableItems)
        {
            foreach (var searchableItem in searchableItems.Results)
            {
                var searchTerms    = searchableItem.Title;
                var newItemMatches = newItems
                                     .Items
                                     .Where(item => ItemsMatch(searchTerms, item))
                                     .ToList()
                ;

                if (newItemMatches.Any())
                {
                    yield return new SearchResult {
                               Item = searchableItem, Matches = newItemMatches
                    }
                }
                ;
            }
        }