public void Should_fire_getsolroperationinstance()
        {
            Given_a_solr_resolver_that_returns_a_stubbed_solr_instance();
            Given_a_set_of_items_of_length(3);
            var batchedIndexer = new BatchedIndexer<TestClass>(_solrResolver);
            batchedIndexer.GenerateIndex(_itemsToIndex);

            _solrResolver.AssertWasCalled(x=>x.GetSolrOperationInstance());
        }
        public void Should_batch_add_records_to_solr()
        {
            log4net.Config.XmlConfigurator.Configure();
            // work out a batch strategy
            const int batchNumber = 1000;

            // get list of songs
            string pathToItunesLibrary = ConfigSettings.PathToXml;

            IEnumerable<Song> songs = new LibraryBuilder<Song>().BuildLibrary(pathToItunesLibrary);
            songs = songs.Where(x => !string.IsNullOrEmpty(x.Artist) && !string.IsNullOrEmpty(x.Album));
            var indexer = new BatchedIndexer<Song>(new SolrCastleResolver<Song>()) {BatchBy = batchNumber};

            indexer.GenerateIndex(songs);
        }
        public void Should_fire_GetBatch_correct_number_of_times()
        {
            const int batchBy = 10;
            const int numberOfItems = 30;
            const int expectedBatches = numberOfItems / batchBy;
            int expectedRemainder = numberOfItems % batchBy;
            int expectedNumberOfTimes = (expectedRemainder < 1) ? expectedBatches : expectedBatches + 1;

            Given_a_solr_resolver_that_returns_a_stubbed_solr_instance();
            Given_a_set_of_items_of_length(numberOfItems);

            var batcher = MockRepository.GenerateStub<IBatcher<TestClass>>();
            batcher.Stub(x => x.GetBatch(null, 0, 0)).IgnoreArguments().Return(new List<TestClass>());
            batcher.Stub(x => x.NumberOfBatches).Return(expectedBatches);
            batcher.Stub(x => x.Remainder).Return(expectedRemainder);

            var log = MockRepository.GenerateStub<ILog>();
            var batchedIndexer = new BatchedIndexer<TestClass>(_solrResolver, batcher, log);
            batchedIndexer.GenerateIndex(_itemsToIndex);
            batcher.AssertWasCalled(x => x.GetBatch(Arg<IEnumerable<TestClass>>.Is.Anything, Arg<int>.Is.Anything, Arg<int>.Is.Anything),
                o => o.Repeat.Times(expectedNumberOfTimes));
        }