Generates ChangeEvents from the local tree and a list of all stored objects.
/// The exception that is thrown when a null /// reference (Nothing in Visual Basic) is passed to a method that does not accept it as a valid argument. ///
        public void RenameOnSubFolder() {
            var storage = new Mock<IMetaDataStorage>();
            var fsFactory = new Mock<IFileSystemInfoFactory>();
            var underTest = new LocalEventGenerator(storage.Object, fsFactory.Object);
            Dictionary<string, Tuple<AbstractFolderEvent, AbstractFolderEvent>> eventMap = new Dictionary<string, Tuple<AbstractFolderEvent, AbstractFolderEvent>>();

            Guid rootGuid = Guid.NewGuid();
            var rootName = "root";
            var rootPath = Path.Combine(Path.GetTempPath(), rootName);
            var rootObjectId = "rootId";
            ObjectTree<IFileSystemInfo> rootTree = this.CreateTreeFromPathAndGuid(rootName, rootPath, rootGuid);

            Guid subFolderGuid = Guid.NewGuid();
            var subName = "A";
            var subPath = Path.Combine(rootPath, subName);
            var subFolderId = "subId";
            ObjectTree<IFileSystemInfo> subFolder = this.CreateTreeFromPathAndGuid(subName, subPath, subFolderGuid);
            rootTree.Children.Add(subFolder);

            Guid subSubFolderGuid = Guid.NewGuid();
            var subSubName = "B";
            var subSubPath = Path.Combine(subPath, subSubName);
            var subSubFolderId = "subId";
            ObjectTree<IFileSystemInfo> subSubFolder = this.CreateTreeFromPathAndGuid(subSubName, subSubPath, subSubFolderGuid);
            subFolder.Children.Add(subSubFolder);

            List<IMappedObject> storedObjectsForLocal = new List<IMappedObject>();
            var rootMappedObject = this.CreateStoredObjectMock(rootGuid, rootObjectId, rootName, null);
            storedObjectsForLocal.Add(rootMappedObject);
            var subMappedObject = this.CreateStoredObjectMock(subFolderGuid, subFolderId, subName, rootObjectId);
            storedObjectsForLocal.Add(subMappedObject);
            var subSubMappedObject = this.CreateStoredObjectMock(subSubFolderGuid, subSubFolderId, "oldsubsubName", subSubFolderId);
            storedObjectsForLocal.Add(subSubMappedObject);

            storage.Setup(s => s.GetLocalPath(rootMappedObject)).Returns(rootPath);
            storage.Setup(s => s.GetLocalPath(subMappedObject)).Returns(subPath);
            storage.Setup(s => s.GetLocalPath(subSubMappedObject)).Returns(subSubPath);

            ISet<IMappedObject> handledLocalStoredObjects = new HashSet<IMappedObject>();
            List<AbstractFolderEvent> creationEvents = underTest.CreateEvents(storedObjectsForLocal, rootTree, eventMap, handledLocalStoredObjects);
            foreach (var handledObjects in handledLocalStoredObjects) {
                storedObjectsForLocal.Remove(handledObjects);
            }

            storedObjectsForLocal.Remove(rootMappedObject);
            Assert.That(creationEvents, Is.Empty);
            Assert.That(storedObjectsForLocal, Is.Empty);
            Assert.That(eventMap.Count, Is.EqualTo(1));
            Assert.That(eventMap[subSubFolderId], Is.Not.Null);
            Assert.That(eventMap[subSubFolderId].Item1.Local, Is.EqualTo(MetaDataChangeType.CHANGED));
        }
        public CrawlEventGenerator(IMetaDataStorage storage, IFileSystemInfoFactory fsFactory = null) {
            if (storage == null) {
                throw new ArgumentNullException("storage");
            }

            this.storage = storage;
            if (fsFactory == null) {
                this.fsFactory = new FileSystemInfoFactory();
            } else {
                this.fsFactory = fsFactory;
            }

            this.localEventGenerator = new LocalEventGenerator(this.storage, this.fsFactory);
            this.remoteEventGenerator = new RemoteEventGenerator(this.storage);
        }
Beispiel #3
0
        public CrawlEventGenerator(IMetaDataStorage storage, IFileSystemInfoFactory fsFactory = null)
        {
            if (storage == null)
            {
                throw new ArgumentNullException("Given storage is null");
            }

            this.storage = storage;
            if (fsFactory == null)
            {
                this.fsFactory = new FileSystemInfoFactory();
            }
            else
            {
                this.fsFactory = fsFactory;
            }

            this.localEventGenerator  = new LocalEventGenerator(this.storage, this.fsFactory);
            this.remoteEventGenerator = new RemoteEventGenerator(this.storage);
        }