Solve() public method

Solve the specified situation by using localFile and remote object.
public Solve ( IFileSystemInfo localFileSystemInfo, IObjectId remoteId, ContentChangeType localContent = ContentChangeType.NONE, ContentChangeType remoteContent = ContentChangeType.NONE ) : void
localFileSystemInfo IFileSystemInfo Local filesystem info instance.
remoteId IObjectId Remote identifier or object.
localContent ContentChangeType Hint if the local content has been changed.
remoteContent ContentChangeType Information if the remote content has been changed.
return void
        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());
        }