Solver to handle the situation of a locally added file/folderobject.
Inheritance: AbstractEnhancedSolver
Exemplo n.º 1
0
        private ISolver[,] CreateSolver() {
            int dim = Enum.GetNames(typeof(SituationType)).Length;
            ISolver[,] solver = new ISolver[dim, dim];
            ISolver changeChangeSolver = new LocalObjectChangedRemoteObjectChanged(this.session, this.storage, this.transmissionStorage, this.activityListener.TransmissionManager);
            ISolver addedNochangeSolver = new LocalObjectAdded(this.session, this.storage, this.transmissionStorage, this.activityListener.TransmissionManager);
            ISolver changedNoChangeSolver = new LocalObjectChanged(this.session, this.storage, this.transmissionStorage, this.activityListener.TransmissionManager);
            if (this.session.ArePrivateWorkingCopySupported()) {
                addedNochangeSolver = new LocalObjectAddedWithPWC(this.session, this.storage, this.transmissionStorage, this.activityListener.TransmissionManager, addedNochangeSolver);
                changedNoChangeSolver = new LocalObjectChangedWithPWC(this.session, this.storage, this.transmissionStorage, this.activityListener.TransmissionManager, changedNoChangeSolver);
                changeChangeSolver = new LocalObjectChangedRemoteObjectChangedWithPWC(this.session, this.storage, this.transmissionStorage, this.activityListener.TransmissionManager, changeChangeSolver);
            }

            ISolver renameRenameSolver = new LocalObjectRenamedRemoteObjectRenamed(this.session, this.storage, changeChangeSolver);
            ISolver renameChangeSolver = new LocalObjectRenamedRemoteObjectChanged(this.session, this.storage, changeChangeSolver);

            solver[(int)SituationType.NOCHANGE, (int)SituationType.NOCHANGE] = new NothingToDoSolver();
            solver[(int)SituationType.ADDED, (int)SituationType.NOCHANGE] = addedNochangeSolver;
            solver[(int)SituationType.CHANGED, (int)SituationType.NOCHANGE] = changedNoChangeSolver;
            solver[(int)SituationType.MOVED, (int)SituationType.NOCHANGE] = new LocalObjectMoved(this.session, this.storage);
            solver[(int)SituationType.RENAMED, (int)SituationType.NOCHANGE] = new LocalObjectRenamed(this.session, this.storage);
            solver[(int)SituationType.REMOVED, (int)SituationType.NOCHANGE] = new LocalObjectDeleted(this.session, this.storage);

            solver[(int)SituationType.NOCHANGE, (int)SituationType.ADDED] = new RemoteObjectAdded(this.session, this.storage, this.transmissionStorage, this.activityListener.TransmissionManager);

            solver[(int)SituationType.NOCHANGE, (int)SituationType.CHANGED] = new RemoteObjectChanged(this.session, this.storage, this.transmissionStorage, this.activityListener.TransmissionManager);
            solver[(int)SituationType.CHANGED, (int)SituationType.CHANGED] = changeChangeSolver;
            solver[(int)SituationType.MOVED, (int)SituationType.CHANGED] = new LocalObjectMovedRemoteObjectChanged(this.session, this.storage, renameChangeSolver, changeChangeSolver);
            solver[(int)SituationType.RENAMED, (int)SituationType.CHANGED] = renameChangeSolver;
            solver[(int)SituationType.REMOVED, (int)SituationType.CHANGED] = new LocalObjectDeletedRemoteObjectChanged(this.session, this.storage);

            solver[(int)SituationType.NOCHANGE, (int)SituationType.MOVED] = new RemoteObjectMoved(this.session, this.storage);
            solver[(int)SituationType.CHANGED, (int)SituationType.MOVED] = new LocalObjectChangedRemoteObjectMoved(this.session, this.storage, changeChangeSolver);
            solver[(int)SituationType.MOVED, (int)SituationType.MOVED] = new LocalObjectMovedRemoteObjectMoved(this.session, this.storage);
            solver[(int)SituationType.RENAMED, (int)SituationType.MOVED] = new LocalObjectRenamedRemoteObjectMoved(this.session, this.storage, renameRenameSolver, changeChangeSolver);
            solver[(int)SituationType.REMOVED, (int)SituationType.MOVED] = new LocalObjectDeletedRemoteObjectRenamedOrMoved(this.session, this.storage);

            solver[(int)SituationType.NOCHANGE, (int)SituationType.RENAMED] = new RemoteObjectRenamed(this.session, this.storage);
            solver[(int)SituationType.CHANGED, (int)SituationType.RENAMED] = new LocalObjectChangedRemoteObjectRenamed(this.session, this.storage, changeChangeSolver);
            solver[(int)SituationType.MOVED, (int)SituationType.RENAMED] = new LocalObjectMovedRemoteObjectRenamed(this.session, this.storage, changeChangeSolver, renameRenameSolver);
            solver[(int)SituationType.RENAMED, (int)SituationType.RENAMED] = renameRenameSolver;
            solver[(int)SituationType.REMOVED, (int)SituationType.RENAMED] = new LocalObjectDeletedRemoteObjectRenamedOrMoved(this.session, this.storage);

            solver[(int)SituationType.NOCHANGE, (int)SituationType.REMOVED] = new RemoteObjectDeleted(this.session, this.storage, this.filters);
            solver[(int)SituationType.CHANGED, (int)SituationType.REMOVED] = new RemoteObjectDeleted(this.session, this.storage, this.filters);
            solver[(int)SituationType.MOVED, (int)SituationType.REMOVED] = new LocalObjectRenamedOrMovedRemoteObjectDeleted(this.session, this.storage, this.transmissionStorage, this.activityListener.TransmissionManager);
            solver[(int)SituationType.RENAMED, (int)SituationType.REMOVED] = new LocalObjectRenamedOrMovedRemoteObjectDeleted(this.session, this.storage, this.transmissionStorage, this.activityListener.TransmissionManager);
            solver[(int)SituationType.REMOVED, (int)SituationType.REMOVED] = new LocalObjectDeletedRemoteObjectDeleted(this.session, this.storage);

            return solver;
        }
        private void RunSolveFile(Mock<IFileInfo> fileInfo, TransmissionManager transmissionManager = null) {
            if (transmissionManager == null) {
                transmissionManager = new TransmissionManager();
            }

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

            solver.Solve(fileInfo.Object, null);
            Assert.That(transmissionManager.ActiveTransmissions, Is.Empty);
        }
        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 SolverFailsIfLocalFileOrFolderDoesNotExistsAnymore() {
            this.SetUpMocks();
            string path = Path.Combine(Path.GetTempPath(), this.localObjectName);

            var fileSystemInfo = new Mock<IFileSystemInfo>(MockBehavior.Strict);
            fileSystemInfo.Setup(f => f.Refresh());
            fileSystemInfo.Setup(f => f.Exists).Returns(false);
            fileSystemInfo.Setup(f => f.FullName).Returns(path);
            var solver = new LocalObjectAdded(this.session.Object, this.storage.Object, Mock.Of<IFileTransmissionStorage>(), new TransmissionManager());

            Assert.Throws<FileNotFoundException>(() => solver.Solve(fileSystemInfo.Object, null));
        }
        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();
        }
        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();
        }
        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 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());
        }