public void CreatingASingleTransmissionIncreasesListCountByOne() {
            var underTest = new TransmissionManager();

            underTest.CreateTransmission(TransmissionType.DOWNLOAD_NEW_FILE, "path");

            Assert.That(underTest.ActiveTransmissions.Count, Is.EqualTo(1));
        }
        public void CreatingTwoTransmissionProducesTwoEntriesInList() {
            var underTest = new TransmissionManager();
            underTest.CreateTransmission(TransmissionType.DOWNLOAD_NEW_FILE, "path");
            underTest.CreateTransmission(TransmissionType.DOWNLOAD_NEW_FILE, "path2");

            Assert.That(underTest.ActiveTransmissions.Count, Is.EqualTo(2));
        }
        public void ListedTransmissionIsEqualToAdded() {
            var underTest = new TransmissionManager();
            var trans = underTest.CreateTransmission(TransmissionType.DOWNLOAD_NEW_FILE, "path");

            Assert.That(underTest.ActiveTransmissions[0], Is.EqualTo(trans));
            Assert.That(underTest.ActiveTransmissionsAsList()[0], Is.EqualTo(trans));
        }
 public void SetUp() {
     this.manager = new TransmissionManager();
     this.session = new Mock<ISession>();
     this.session.SetupTypeSystem();
     this.storage = new Mock<IMetaDataStorage>();
     this.fsFactory = new Mock<IFileSystemInfoFactory>();
     this.underTest = new RemoteObjectChanged(this.session.Object, this.storage.Object, null, this.manager, this.fsFactory.Object);
 }
 public LocalObjectRenamedOrMovedRemoteObjectDeleted(
     ISession session,
     IMetaDataStorage storage,
     IFileTransmissionStorage transmissionStorage,
     TransmissionManager manager,
     ISolver secondSolver = null) : base(session, storage) {
         this.secondSolver = secondSolver ?? new LocalObjectAdded(session, storage, transmissionStorage, manager);
 }
        public void AnAbortedTransmissionIsRemovedFromList() {
            var underTest = new TransmissionManager();
            var trans = underTest.CreateTransmission(TransmissionType.DOWNLOAD_NEW_FILE, "path");

            trans.Status = TransmissionStatus.ABORTED;

            Assert.That(underTest.ActiveTransmissions, Is.Empty);
        }
 public void SetUp()
 {
     this.session = new Mock<ISession>();
     this.session.SetupTypeSystem();
     this.storage = new Mock<IMetaDataStorage>();
     this.transmissionManager = new TransmissionManager();
     this.changeSolver = new Mock<LocalObjectChangedRemoteObjectChanged>(this.session.Object, this.storage.Object, null, this.transmissionManager, Mock.Of<IFileSystemInfoFactory>());
     this.renameSolver = new Mock<LocalObjectRenamedRemoteObjectRenamed>(this.session.Object, this.storage.Object, this.changeSolver.Object);
 }
 public void SetUp() {
     this.path = Path.Combine(Path.GetTempPath(), this.objectName);
     this.manager = new TransmissionManager();
     this.session = new Mock<ISession>();
     this.session.SetupTypeSystem();
     this.storage = new Mock<IMetaDataStorage>();
     this.transmissionStorage = new Mock<IFileTransmissionStorage>();
     this.fsFactory = new Mock<IFileSystemInfoFactory>(MockBehavior.Strict);
     this.underTest = new RemoteObjectAdded(this.session.Object, this.storage.Object, this.transmissionStorage.Object, this.manager, this.fsFactory.Object);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="CmisSync.Lib.ActivityListenerAggregator"/> class.
        /// </summary>
        /// <param name="overallListener">The activity listener to which aggregated activity will be sent.</param>
        /// <param name="transmissionManager">Transmission manager.</param>
        public ActivityListenerAggregator(IActivityListener overallListener, TransmissionManager transmissionManager) {
            if (overallListener == null) {
                throw new ArgumentNullException("overallListener");
            }

            if (transmissionManager == null) {
                throw new ArgumentNullException("transmissionManager");
            }

            this.overall = overallListener;
            this.TransmissionManager = transmissionManager;
        }
 public void SetUp() {
     this.newLocalName = string.Empty;
     this.newRemoteName = string.Empty;
     this.session = new Mock<ISession>();
     this.session.SetupTypeSystem();
     this.storage = new Mock<IMetaDataStorage>();
     this.InitializeMappedFolderOnStorage();
     this.InitializeMappedFileOnStorage();
     var transmissionManager = new TransmissionManager();
     var fsFactory = Mock.Of<IFileSystemInfoFactory>();
     this.changeSolver = new Mock<LocalObjectChangedRemoteObjectChanged>(this.session.Object, this.storage.Object, null, transmissionManager, fsFactory);
     this.underTest = new LocalObjectRenamedRemoteObjectRenamed(this.session.Object, this.storage.Object, this.changeSolver.Object);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="CmisSync.Lib.Consumer.SituationSolver.RemoteObjectAdded"/> class.
        /// </summary>
        /// <param name="session">Cmis session.</param>
        /// <param name="storage">Meta data storage.</param>
        /// <param name="transmissionStorage">Transmission progress storage.</param>
        /// <param name="transmissionManager">Transmission manager.</param>
        /// <param name="fsFactory">File system factory.</param>
        public RemoteObjectAdded(
            ISession session,
            IMetaDataStorage storage,
            IFileTransmissionStorage transmissionStorage,
            TransmissionManager transmissionManager,
            IFileSystemInfoFactory fsFactory = null) : base(session, storage, transmissionStorage) {
            if (transmissionManager == null) {
                throw new ArgumentNullException("transmissionManager");
            }

            this.fsFactory = fsFactory ?? new FileSystemInfoFactory();
            this.manager = transmissionManager;
        }
        private void Setup(int chunk) {
            this.chunkCount = chunk;

            this.session = new Mock<ISession>();
            this.session.SetupTypeSystem();
            this.fsFactory = new Mock<IFileSystemInfoFactory>(MockBehavior.Strict);
            this.storage = new Mock<IMetaDataStorage>();
            this.transmissionStorage = new Mock<IFileTransmissionStorage>();
            this.transmissionManager = new TransmissionManager();

            this.transmissionStorage.Setup(f => f.SaveObject(It.IsAny<IFileTransmissionObject>())).Callback<IFileTransmissionObject>((o) => {
                this.transmissionStorage.Setup(f => f.GetObjectByRemoteObjectId(It.IsAny<string>())).Returns(o);
            });
            this.transmissionStorage.Setup(f => f.RemoveObjectByRemoteObjectId(It.IsAny<string>())).Callback(() => {
                this.transmissionStorage.Setup(f => f.GetObjectByRemoteObjectId(It.IsAny<string>())).Returns((IFileTransmissionObject)null);
            });

            this.parentPath = Path.GetTempPath();
            this.localPath = Path.Combine(this.parentPath, this.objectName);
            this.fileContentOld = new byte[this.chunkCount * this.chunkSize];
            this.fileContentOld[0] = 0;
            this.fileHashOld = SHA1.Create().ComputeHash(this.fileContentOld);
            this.fileContent = new byte[this.chunkCount * this.chunkSize];
            this.fileContent[0] = 1;
            this.fileHash = SHA1.Create().ComputeHash(this.fileContent);

            var parentDir = Mock.Of<IDirectoryInfo>(d => d.FullName == this.parentPath && d.Name == Path.GetFileName(this.parentPath));
            this.localFile = Mock.Get(Mock.Of<IFileInfo>(
                f =>
                f.FullName == this.localPath &&
                f.Name == this.objectName &&
                f.Directory == parentDir));
            this.localFileLength = 0;

            this.cacheFile = this.fsFactory.SetupDownloadCacheFile();
            this.cacheFile.SetupAllProperties();
            this.cacheFile.Setup(f => f.FullName).Returns(this.localPath + ".sync");
            this.cacheFile.Setup(f => f.Name).Returns(this.objectName + ".sync");
            this.cacheFile.Setup(f => f.Directory).Returns(parentDir);
            this.cacheFile.Setup(f => f.IsExtendedAttributeAvailable()).Returns(true);
            this.fsFactory.AddIFileInfo(this.cacheFile.Object);
            this.cacheFile.Setup(f => f.Length).Returns(() => { return this.localFileLength; });

            this.backupFile = new Mock<IFileInfo>();
        }
        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="CmisSync.Lib.Consumer.SituationSolver.PWC.LocalObjectChangedRemoteObjectChangedWithPWC"/> class.
        /// </summary>
        /// <param name="session">Cmis session.</param>
        /// <param name="storage">Meta data storage.</param>
        /// <param name="transmissionStorage">Transmission storage.</param>
        /// <param name="manager">Transmission manager.</param>
        /// <param name="localObjectChangedRemoteObjectChangedFallbackSolver">Local object changed remote object changed fallback solver.</param>
        public LocalObjectChangedRemoteObjectChangedWithPWC(
            ISession session,
            IMetaDataStorage storage,
            IFileTransmissionStorage transmissionStorage,
            TransmissionManager manager,
            ISolver localObjectChangedRemoteObjectChangedFallbackSolver) : base(session, storage, transmissionStorage)
        {
            if (localObjectChangedRemoteObjectChangedFallbackSolver == null) {
                throw new ArgumentNullException("localObjectChangedRemoteObjectChangedFallbackSolver", "Given fallback solver is null");
            }

            if (!session.ArePrivateWorkingCopySupported()) {
                throw new ArgumentException("Given session does not support pwc updates", "session");
            }

            this.fallbackSolver = localObjectChangedRemoteObjectChangedFallbackSolver;
            this.transmissionManager = manager;
        }
        public void ParentFolderDoesNotExistsOnServerDueToPastErrorThrowsException() {
            this.SetUpMocks(true);

            string path = Path.Combine(Path.GetTempPath(), this.localObjectName);
            this.session.Setup(s => s.CreateDocument(
                It.Is<IDictionary<string, object>>(p => (string)p["cmis:name"] == this.localObjectName),
                It.Is<IObjectId>(o => o.Id == this.parentId),
                It.IsAny<IContentStream>(),
                null,
                null,
                null,
                null)).Throws(new CmisPermissionDeniedException());

            Mock<IFileInfo> fileInfo = new Mock<IFileInfo>();
            fileInfo.Setup(f => f.Length).Returns(0);

            var parentDirInfo = new Mock<IDirectoryInfo>();

            fileInfo.Setup(d => d.FullName).Returns(path);
            fileInfo.Setup(d => d.Name).Returns(this.localObjectName);
            fileInfo.Setup(d => d.Exists).Returns(true);
            fileInfo.Setup(d => d.IsExtendedAttributeAvailable()).Returns(this.withExtendedAttributes);

            fileInfo.Setup(d => d.Directory).Returns(parentDirInfo.Object);
            var transmissionManager = new TransmissionManager();
            var solver = new LocalObjectAdded(this.session.Object, this.storage.Object, this.transmissionStorage.Object, transmissionManager);
            Assert.Throws<ArgumentException>(() => solver.Solve(fileInfo.Object, null));
            this.storage.VerifyThatNoObjectIsManipulated();
        }
Example #15
0
        /// <summary>
        /// The entry point of the program, where the program control starts and ends.
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        static void Main(string[] args)
        {
            // Only allow one instance of DataSpace Sync (on Windows)
            if (!programMutex.WaitOne(0, false)) {
                System.Console.WriteLine("DataSpaceSync is already running.");
                Environment.Exit(-1);
            }

            if (File.Exists(ConfigManager.CurrentConfigFile)) {
                ConfigMigration.Migrate();
            }

            log4net.Config.XmlConfigurator.Configure(ConfigManager.CurrentConfig.GetLog4NetConfig());
            CmisSync.Lib.Utils.EnsureNeededDependenciesAreAvailable();
            if (args.Length != 0) {
                foreach (string arg in args) {
                    // Check, if the user would like to read console logs
                    if (arg.Equals("-v") || arg.Equals("--verbose")) {
                        verbose = true;
                    }
                }
            }

            // Add Console Logging if user wants to
            if (verbose) {
                BasicConfigurator.Configure();
            }

            Logger.Info("Starting.");

            List<Repository> repositories = new List<Repository>();
            var transmissionManager = new TransmissionManager();
            foreach (RepoInfo repoInfo in ConfigManager.CurrentConfig.Folders) {
                string path = repoInfo.LocalPath;
                if (!Directory.Exists(path)) {
                    Directory.CreateDirectory(path);
                }

                Repository repo = new Repository(repoInfo, new ActivityListenerAggregator(new ActivityListener(), transmissionManager));
                repositories.Add(repo);
                repo.Initialize();
            }

            while (true) {
                System.Threading.Thread.Sleep(100);
            }
        }
 private void SetUpMocks() {
     this.manager = new TransmissionManager();
     this.session = new Mock<ISession>();
     this.session.SetupTypeSystem();
     this.storage = new Mock<IMetaDataStorage>();
     this.fsFactory = new Mock<IFileSystemInfoFactory>();
     this.changeSolver = new Mock<LocalObjectChangedRemoteObjectChanged>(
         this.session.Object,
         this.storage.Object,
         null,
         this.manager,
         this.fsFactory.Object);
     var changeSolverForRenameSolver = new Mock<LocalObjectChangedRemoteObjectChanged>(
         this.session.Object,
         this.storage.Object,
         null,
         this.manager,
         this.fsFactory.Object);
     this.renameSolver = new Mock<LocalObjectRenamedRemoteObjectChanged>(
         this.session.Object,
         this.storage.Object,
         changeSolverForRenameSolver.Object) { CallBase = true };
     this.underTest = new LocalObjectMovedRemoteObjectChanged(this.session.Object, this.storage.Object, this.renameSolver.Object, this.changeSolver.Object);
     var srcRemoteParent = Mock.Of<ICmisObject>(
         o =>
         o.Name == this.oldParentsName &&
         o.Id == this.oldParentsId);
     var targetRemoteParent = Mock.Of<ICmisObject>(
         o =>
         o.Name == this.newParentsName &&
         o.Id == this.newParentsId);
     this.session.AddRemoteObjects(srcRemoteParent, targetRemoteParent);
     this.parentUuid = Guid.NewGuid();
     var mappedParent = new MappedObject(this.newParentsName, this.newParentsId, MappedObjectType.Folder, "grandParentId", this.changeToken) { Guid = this.parentUuid };
     this.storage.AddMappedFolder(mappedParent);
 }
 public void ConstructorTakesTransmissionManager() {
     var manager = new TransmissionManager();
     var agg = new ActivityListenerAggregator(Mock.Of<IActivityListener>(), manager);
     Assert.That(agg.TransmissionManager, Is.EqualTo(manager));
 }
        public void PermissionDeniedLeadsToNoOperation() {
            this.SetUpMocks(true);

            string path = Path.Combine(Path.GetTempPath(), this.localObjectName);
            this.session.Setup(s => s.CreateDocument(
                It.Is<IDictionary<string, object>>(p => (string)p["cmis:name"] == this.localObjectName),
                It.Is<IObjectId>(o => o.Id == this.parentId),
                It.IsAny<IContentStream>(),
                null,
                null,
                null,
                null)).Throws(new CmisPermissionDeniedException());

            Mock<IFileInfo> fileInfo = new Mock<IFileInfo>();
            fileInfo.Setup(f => f.Length).Returns(0);

            var parentDirInfo = this.SetupParentFolder(this.parentId);

            var parents = new List<IFolder>();
            parents.Add(Mock.Of<IFolder>(f => f.Id == this.parentId));
            fileInfo.Setup(d => d.FullName).Returns(path);
            fileInfo.Setup(d => d.Name).Returns(this.localObjectName);
            fileInfo.Setup(d => d.Exists).Returns(true);
            fileInfo.Setup(d => d.IsExtendedAttributeAvailable()).Returns(this.withExtendedAttributes);

            fileInfo.Setup(d => d.Directory).Returns(parentDirInfo);
            var transmissionManager = new TransmissionManager();
            var solver = new LocalObjectAdded(this.session.Object, this.storage.Object, this.transmissionStorage.Object, transmissionManager);
            solver.Solve(fileInfo.Object, null);
            this.storage.Verify(s => s.SaveMappedObject(It.IsAny<IMappedObject>()), Times.Never());
        }
        public void CreatingATransmissionFiresEvent() {
            var underTest = new TransmissionManager();

            int eventCounter = 0;
            string path = "path";
            underTest.ActiveTransmissions.CollectionChanged += delegate(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) {
                eventCounter++;
                Assert.That(e.NewItems.Count, Is.EqualTo(1));
                Assert.That((e.NewItems[0] as Transmission).Type, Is.EqualTo(TransmissionType.DOWNLOAD_NEW_FILE));
                Assert.That((e.NewItems[0] as Transmission).Path, Is.EqualTo(path));
            };

            underTest.CreateTransmission(TransmissionType.DOWNLOAD_NEW_FILE, path);

            Assert.That(eventCounter, Is.EqualTo(1));
        }
        public void ParentFolderDoesNotExistsOnServerDueToMissingAllowedActions() {
            this.SetUpMocks(true);

            string path = Path.Combine(Path.GetTempPath(), this.localObjectName);
            this.session.Setup(s => s.CreateDocument(
                It.Is<IDictionary<string, object>>(p => (string)p["cmis:name"] == this.localObjectName),
                It.Is<IObjectId>(o => o.Id == this.parentId),
                It.IsAny<IContentStream>(),
                null,
                null,
                null,
                null)).Throws(new CmisPermissionDeniedException());

            Mock<IFileInfo> fileInfo = new Mock<IFileInfo>();
            fileInfo.Setup(f => f.Length).Returns(0);

            var parentDirInfo = new Mock<IDirectoryInfo>();
            var parentsParentDirInfo = new Mock<IDirectoryInfo>();
            Guid parentsParentGuid = Guid.NewGuid();
            string remoteParentsParentId = Guid.NewGuid().ToString();
            parentsParentDirInfo.Setup(d => d.Uuid).Returns(parentsParentGuid);
            parentDirInfo.Setup(d => d.Parent).Returns(parentsParentDirInfo.Object);
            parentDirInfo.Setup(d => d.Exists).Returns(true);
            parentsParentDirInfo.Setup(d => d.Exists).Returns(true);
            var mappedFolder = Mock.Of<IMappedObject>(o => o.Guid == parentsParentGuid && o.RemoteObjectId == remoteParentsParentId);
            var remoteParentsParentFolder = Mock.Of<IFolder>(f => f.Id == remoteParentsParentId);
            Mock.Get(remoteParentsParentFolder).SetupReadOnly();
            this.session.AddRemoteObject(remoteParentsParentFolder);
            this.storage.Setup(s => s.GetObjectByLocalPath(parentsParentDirInfo.Object)).Returns(mappedFolder);

            fileInfo.Setup(d => d.FullName).Returns(path);
            fileInfo.Setup(d => d.Name).Returns(this.localObjectName);
            fileInfo.Setup(d => d.Exists).Returns(true);
            fileInfo.Setup(d => d.IsExtendedAttributeAvailable()).Returns(this.withExtendedAttributes);

            fileInfo.Setup(d => d.Directory).Returns(parentDirInfo.Object);
            var transmissionManager = new TransmissionManager();
            var solver = new LocalObjectAdded(this.session.Object, this.storage.Object, this.transmissionStorage.Object, transmissionManager);
            solver.Solve(fileInfo.Object, null);
            this.storage.VerifyThatNoObjectIsManipulated();
        }
        private void RunSolveFileChanged(Mock<IFileInfo> fileInfo, Mock<IDocument> document, TransmissionManager transmissionManager = null)
        {
            if (transmissionManager == null) {
                transmissionManager = new TransmissionManager();
            }

            var solver = new LocalObjectChanged(this.session.Object, this.storage.Object, this.transmissionStorage.Object, transmissionManager);

            solver.Solve(fileInfo.Object, document.Object);
            Assert.That(transmissionManager.ActiveTransmissions, Is.Empty);
        }
 private void SetUpMocks() {
     this.newParentPath = Path.Combine(Path.GetTempPath(), this.newParentName);
     this.newPath = Path.Combine(this.newParentPath, this.newName);
     this.manager = new TransmissionManager();
     this.session = new Mock<ISession>();
     this.session.SetupTypeSystem();
     this.storage = new Mock<IMetaDataStorage>();
     var newParentObj = new MappedObject(
         this.newParentName,
         this.newParentId,
         MappedObjectType.Folder,
         null,
         this.changeToken)
     {
         Guid = this.newParentUuid
     };
     this.storage.AddMappedFolder(newParentObj);
     this.fsFactory = new Mock<IFileSystemInfoFactory>();
     this.changeSolver = new Mock<LocalObjectChangedRemoteObjectChanged>(
         this.session.Object,
         this.storage.Object,
         null,
         this.manager,
         this.fsFactory.Object);
     this.renameSolver = new Mock<LocalObjectRenamedRemoteObjectRenamed>(
         this.session.Object,
         this.storage.Object,
         this.changeSolver.Object);
     this.session.AddRemoteObjects(Mock.Of<IFolder>(o => o.Id == this.oldParentId), Mock.Of<IFolder>(o => o.Id == this.newParentId));
     this.underTest = new LocalObjectMovedRemoteObjectRenamed(this.session.Object, this.storage.Object, this.changeSolver.Object, this.renameSolver.Object);
 }
        public void AFinishedTransmissionFiresEvent() {
            var underTest = new TransmissionManager();
            var trans = underTest.CreateTransmission(TransmissionType.DOWNLOAD_NEW_FILE, "path");
            int eventCounter = 0;

            underTest.ActiveTransmissions.CollectionChanged += delegate(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) {
                eventCounter++;
                Assert.That(e.NewItems, Is.Null);
                Assert.That(e.OldItems.Count, Is.EqualTo(1));
                Assert.That(e.OldItems[0], Is.EqualTo(trans));
            };
            trans.Status = TransmissionStatus.FINISHED;

            Assert.That(eventCounter, Is.EqualTo(1));
        }
        private Mock<IDirectoryInfo> RunSolveFolder(
            string folderName,
            string id,
            string parentId,
            string lastChangeToken,
            bool extendedAttributes,
            out Mock<IFolder> folderMock,
            Guid? existingGuid = null,
                TransmissionManager transmissionManager = null)
        {
            string path = Path.Combine(Path.GetTempPath(), folderName);
            var futureRemoteFolder = Mock.Of<IFolder>(
                f =>
                f.Name == folderName &&
                f.Id == id &&
                f.ParentId == parentId &&
                f.ChangeToken == lastChangeToken);
            var futureRemoteFolderId = Mock.Of<IObjectId>(
                o =>
                o.Id == id);

            this.session.Setup(s => s.CreateFolder(It.Is<IDictionary<string, object>>(p => (string)p["cmis:name"] == folderName), It.Is<IObjectId>(o => o.Id == parentId))).Returns(futureRemoteFolderId);
            this.session.Setup(s => s.GetObject(It.Is<IObjectId>(o => o == futureRemoteFolderId), It.IsAny<IOperationContext>())).Returns(futureRemoteFolder);

            var dirInfo = new Mock<IDirectoryInfo>();
            dirInfo.Setup(d => d.FullName).Returns(path);
            dirInfo.Setup(d => d.Name).Returns(folderName);
            dirInfo.Setup(d => d.Exists).Returns(true);
            dirInfo.Setup(d => d.IsExtendedAttributeAvailable()).Returns(extendedAttributes);
            if (existingGuid != null) {
                dirInfo.SetupGuid((Guid)existingGuid);
            }

            var parentDirInfo = this.SetupParentFolder(parentId);
            dirInfo.Setup(d => d.Parent).Returns(parentDirInfo);
            if (transmissionManager == null) {
                transmissionManager = new TransmissionManager();
            }

            var solver = new LocalObjectAdded(this.session.Object, this.storage.Object, this.transmissionStorage.Object, transmissionManager);

            solver.Solve(dirInfo.Object, null);

            folderMock = Mock.Get(futureRemoteFolder);
            return dirInfo;
        }
        public void Setup() {
            this.session = new Mock<ISession>();
            this.session.SetupTypeSystem();

            // this.session.SetupCreateOperationContext();
            this.storage = new Mock<IMetaDataStorage>();
            this.storage.Setup(f => f.SaveMappedObject(It.IsAny<IMappedObject>())).Callback<IMappedObject>((o) => {
                this.storage.Setup(f => f.GetObjectByLocalPath(It.IsAny<IFileSystemInfo>())).Returns(o);
            });

            this.transmissionStorage = new Mock<IFileTransmissionStorage>();
            this.transmissionStorage.Setup(f => f.SaveObject(It.IsAny<IFileTransmissionObject>())).Callback<IFileTransmissionObject>((o) => {
                this.transmissionStorage.Setup(f => f.GetObjectByRemoteObjectId(o.RemoteObjectId)).Returns(o);
                this.transmissionStorage.Setup(f => f.GetObjectByLocalPath(o.LocalPath)).Returns(o);
            });

            this.session.Setup(f => f.RepositoryInfo.Capabilities.IsPwcUpdatableSupported).Returns(true);
            this.transmissionStorage.Setup(f => f.ChunkSize).Returns(this.chunkSize);

            this.transmissionManager = new TransmissionManager();
        }
Example #26
0
        private SingleStepEventQueue CreateQueue(Mock<ISession> session, IMetaDataStorage storage, ObservableHandler observer, IFileSystemInfoFactory fsFactory = null) {
            var manager = new SyncEventManager();
            SingleStepEventQueue queue = new SingleStepEventQueue(manager);

            manager.AddEventHandler(observer);

            var connectionScheduler = new ConnectionScheduler(new RepoInfo(), queue, Mock.Of<ISessionFactory>(), Mock.Of<IAuthenticationProvider>());
            manager.AddEventHandler(connectionScheduler);

            var changes = new ContentChanges(session.Object, storage, queue, this.maxNumberOfContentChanges, this.isPropertyChangesSupported);
            manager.AddEventHandler(changes);

            var transformer = new ContentChangeEventTransformer(queue, storage, fsFactory);
            manager.AddEventHandler(transformer);

            var ccaccumulator = new ContentChangeEventAccumulator(session.Object, queue);
            manager.AddEventHandler(ccaccumulator);

            var remoteFetcher = new RemoteObjectFetcher(session.Object, storage);
            manager.AddEventHandler(remoteFetcher);

            var localFetcher = new LocalObjectFetcher(storage.Matcher, fsFactory);
            manager.AddEventHandler(localFetcher);

            var watcher = new Strategy.WatcherConsumer(queue);
            manager.AddEventHandler(watcher);

            var localDetection = new LocalSituationDetection();
            var remoteDetection = new RemoteSituationDetection();
            var transmissionManager = new TransmissionManager();
            var activityAggregator = new ActivityListenerAggregator(Mock.Of<IActivityListener>(), transmissionManager);

            var ignoreFolderFilter = new IgnoredFoldersFilter();
            var ignoreFolderNameFilter = new IgnoredFolderNameFilter();
            var ignoreFileNamesFilter = new IgnoredFileNamesFilter();
            var invalidFolderNameFilter = new InvalidFolderNameFilter();
            var filterAggregator = new FilterAggregator(ignoreFileNamesFilter, ignoreFolderNameFilter, invalidFolderNameFilter, ignoreFolderFilter);

            var syncMechanism = new SyncMechanism(localDetection, remoteDetection, queue, session.Object, storage, Mock.Of<IFileTransmissionStorage>(), activityAggregator, filterAggregator);
            manager.AddEventHandler(syncMechanism);

            var remoteFolder = MockSessionUtil.CreateCmisFolder();
            remoteFolder.Setup(r => r.Path).Returns(this.remoteRoot);
            var localFolder = new Mock<IDirectoryInfo>();
            localFolder.Setup(f => f.FullName).Returns(this.localRoot);
            var generator = new CrawlEventGenerator(storage, fsFactory);
            var ignoreStorage = new IgnoredEntitiesStorage(new IgnoredEntitiesCollection(), storage);
            var treeBuilder = new DescendantsTreeBuilder(storage, remoteFolder.Object, localFolder.Object, filterAggregator, ignoreStorage);
            var notifier = new CrawlEventNotifier(queue);
            var crawler = new DescendantsCrawler(queue, treeBuilder, generator, notifier, Mock.Of<IActivityListener>());
            manager.AddEventHandler(crawler);

            var permissionDenied = new GenericHandleDublicatedEventsFilter<PermissionDeniedEvent, ConfigChangedEvent>();
            manager.AddEventHandler(permissionDenied);

            var alreadyAddedFilter = new IgnoreAlreadyHandledFsEventsFilter(storage, fsFactory);
            manager.AddEventHandler(alreadyAddedFilter);

            var ignoreContentChangesFilter = new IgnoreAlreadyHandledContentChangeEventsFilter(storage, session.Object);
            manager.AddEventHandler(ignoreContentChangesFilter);

            var delayRetryAndNextSyncEventHandler = new DelayRetryAndNextSyncEventHandler(queue);
            manager.AddEventHandler(delayRetryAndNextSyncEventHandler);

            /* This is not implemented yet
            var failedOperationsFilder = new FailedOperationsFilter(queue);
            manager.AddEventHandler(failedOperationsFilder);
            */

            var reportingFilter = new ReportingFilter(queue, ignoreFolderFilter, ignoreFileNamesFilter, ignoreFolderNameFilter, invalidFolderNameFilter, new SymlinkFilter());
            manager.AddEventHandler(reportingFilter);

            var debugHandler = new DebugLoggingHandler();
            manager.AddEventHandler(debugHandler);

            var movedOrRenamed = new RemoteObjectMovedOrRenamedAccumulator(queue, storage, fsFactory);
            manager.AddEventHandler(movedOrRenamed);

            return queue;
        }
 public byte[] Upload(IFileInfo localFile, IDocument doc, TransmissionManager transmissionManager) {
     var transmission = transmissionManager.CreateTransmission(TransmissionType.UPLOAD_MODIFIED_FILE, localFile.FullName);
     return this.UploadFile(localFile, doc, transmission);
 }
        public void Init() {
            string testName = this.GetType().Name;
            object[] attributes = this.GetType().GetCustomAttributes(true);
            foreach (var attr in attributes) {
                if (attr is TestNameAttribute) {
                    testName = (attr as TestNameAttribute).Name;
                }
            }

            this.subfolder = testName + "_" + Guid.NewGuid().ToString();
            Console.WriteLine("Working on " + this.subfolder);

            // RepoInfo
            this.repoInfo = new RepoInfo {
                AuthenticationType = AuthenticationType.BASIC,
                LocalPath = Path.Combine(config[1].ToString(), this.subfolder),
                RemotePath = config[2].ToString() + "/" + this.subfolder,
                Address = new XmlUri(new Uri(config[3].ToString())),
                User = config[4].ToString(),
                RepositoryId = config[6].ToString(),
                Binding = config[7] != null ? config[7].ToString() : BindingType.AtomPub
            };
            this.repoInfo.RemotePath = this.repoInfo.RemotePath.Replace("//", "/");
            this.repoInfo.SetPassword(config[5].ToString());

            // FileSystemDir
            this.localRootDir = new DirectoryInfo(this.repoInfo.LocalPath);
            this.localRootDir.Create();
            if (!new DirectoryInfoWrapper(this.localRootDir).IsExtendedAttributeAvailable()) {
                Assert.Fail(string.Format("The local path {0} does not support extended attributes", this.localRootDir.FullName));
            }

            // Repo
            var activityListener = new Mock<IActivityListener>();
            this.transmissionManager = new TransmissionManager();
            var activityAggregator = new ActivityListenerAggregator(activityListener.Object, this.transmissionManager);
            var queue = new SingleStepEventQueue(new SyncEventManager());

            this.repo = new FullRepoTests.CmisRepoMock(this.repoInfo, activityAggregator, queue);

            // Session
            var cmisParameters = new Dictionary<string, string>();
            cmisParameters[SessionParameter.BindingType] = repoInfo.Binding;
            switch (repoInfo.Binding) {
            case BindingType.AtomPub:
                cmisParameters[SessionParameter.AtomPubUrl] = this.repoInfo.Address.ToString();
                break;
            case BindingType.Browser:
                cmisParameters[SessionParameter.BrowserUrl] = this.repoInfo.Address.ToString();
                break;
            default:
                Assert.Fail(string.Format("Unknown binding type {0}", repoInfo.Binding));
                break;
            }

            cmisParameters[SessionParameter.User] = this.repoInfo.User;
            cmisParameters[SessionParameter.Password] = this.repoInfo.GetPassword().ToString();
            cmisParameters[SessionParameter.RepositoryId] = this.repoInfo.RepositoryId;
            cmisParameters[SessionParameter.UserAgent] = Utils.CreateUserAgent();

            SessionFactory factory = SessionFactory.NewInstance();
            this.session = factory.CreateSession(cmisParameters);
            this.ContentChangesActive = this.session.AreChangeEventsSupported();
            IFolder root = (IFolder)this.session.GetObjectByPath(config[2].ToString());
            this.remoteRootDir = root.CreateFolder(this.subfolder);
        }
 private void SetUpMocks() {
     this.manager = new TransmissionManager();
     this.session = new Mock<ISession>();
     this.session.SetupTypeSystem();
     this.storage = new Mock<IMetaDataStorage>();
     this.fsFactory = new Mock<IFileSystemInfoFactory>();
     this.changeSolver = new Mock<LocalObjectChangedRemoteObjectChanged>(
         this.session.Object,
         this.storage.Object,
         null,
         this.manager,
         this.fsFactory.Object);
     this.underTest = new LocalObjectRenamedRemoteObjectChanged(this.session.Object, this.storage.Object, this.changeSolver.Object);
 }
        public void LocalFolderAddingFailsBecauseUtf8Character() {
            this.SetUpMocks();
            var transmissionManager = new TransmissionManager();
            var solver = new LocalObjectAdded(this.session.Object, this.storage.Object, this.transmissionStorage.Object, transmissionManager);
            var dirInfo = new Mock<IDirectoryInfo>();
            dirInfo.Setup(d => d.Exists).Returns(true);
            dirInfo.Setup(d => d.Name).Returns(@"รค".Normalize(System.Text.NormalizationForm.FormD));
            var parentDirInfo = this.SetupParentFolder(this.parentId);
            dirInfo.Setup(d => d.Parent).Returns(parentDirInfo);
            this.session.Setup(s => s.CreateFolder(It.IsAny<IDictionary<string, object>>(), It.IsAny<IObjectId>())).Throws(new CmisConstraintException("Conflict"));
            Assert.Throws<InteractionNeededException>(() => solver.Solve(dirInfo.Object, null));

            this.storage.VerifyThatNoObjectIsManipulated();
            this.session.Verify(s => s.CreateFolder(It.Is<IDictionary<string, object>>(p => p.ContainsKey("cmis:name")), It.Is<IObjectId>(o => o.Id == this.parentId)), Times.Once());
            dirInfo.VerifyThatLocalFileObjectLastWriteTimeUtcIsNeverModified();
            dirInfo.VerifySet(d => d.Uuid = It.IsAny<Guid?>(), Times.Never());
        }