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(); }
private void RunSolveFile(string fileName, string fileId, string parentId, string lastChangeToken, bool extendedAttributes, Mock <IFileInfo> fileInfo, out Mock <IDocument> documentMock, bool returnLastModificationDate = false) { var parentDirInfo = this.SetupParentFolder(parentId); var parents = new List <IFolder>(); parents.Add(Mock.Of <IFolder>(f => f.Id == parentId)); string path = Path.Combine(Path.GetTempPath(), fileName); var futureRemoteDoc = Mock.Of <IDocument>( f => f.Name == fileName && f.Id == fileId && f.Parents == parents && f.ChangeToken == lastChangeToken); var futureRemoteDocId = Mock.Of <IObjectId>( o => o.Id == fileId); this.session.Setup(s => s.CreateDocument( It.Is <IDictionary <string, object> >(p => (string)p["cmis:name"] == fileName), It.Is <IObjectId>(o => o.Id == parentId), It.Is <IContentStream>(stream => SetupFutureRemoteDocStream(Mock.Get(futureRemoteDoc), stream)), null, null, null, null)).Returns(futureRemoteDocId); this.session.Setup(s => s.GetObject(It.Is <IObjectId>(o => o == futureRemoteDocId), It.IsAny <IOperationContext>())).Returns(futureRemoteDoc); Mock.Get(futureRemoteDoc).Setup( doc => doc.SetContentStream(It.IsAny <IContentStream>(), It.IsAny <bool>(), It.IsAny <bool>())) .Callback <IContentStream, bool, bool>( (s, o, r) => { using (var temp = new MemoryStream()) { s.Stream.CopyTo(temp); } }); if (returnLastModificationDate) { Mock.Get(futureRemoteDoc).Setup(doc => doc.LastModificationDate).Returns(new DateTime()); } fileInfo.Setup(d => d.FullName).Returns(path); fileInfo.Setup(d => d.Name).Returns(fileName); fileInfo.Setup(d => d.Exists).Returns(true); fileInfo.Setup(d => d.IsExtendedAttributeAvailable()).Returns(extendedAttributes); fileInfo.Setup(d => d.Directory).Returns(parentDirInfo); var transmissionManager = new ActiveActivitiesManager(); var solver = new LocalObjectAdded(this.session.Object, this.storage.Object, this.queue.Object, transmissionManager); solver.Solve(fileInfo.Object, null); documentMock = Mock.Get(futureRemoteDoc); Assert.That(transmissionManager.ActiveTransmissions, Is.Empty); }
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 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 LocalFolderAddingFailsBecauseUtf8Character() { this.SetUpMocks(); var transmissionManager = new ActiveActivitiesManager(); var solver = new LocalObjectAdded(this.session.Object, this.storage.Object, transmissionManager); var dirInfo = new Mock <IDirectoryInfo>(); dirInfo.Setup(d => d.Name).Returns(@"รค".Normalize(System.Text.NormalizationForm.FormD)); var parentDirInfo = this.SetupParentFolder(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()); }
public void PermissionDeniedLeadsToNoOperation() { string fileName = "fileName"; string parentId = "parentId"; bool extendedAttributes = true; string path = Path.Combine(Path.GetTempPath(), fileName); this.session.Setup(s => s.CreateDocument( It.Is <IDictionary <string, object> >(p => (string)p["cmis:name"] == fileName), It.Is <IObjectId>(o => o.Id == 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(parentId); var parents = new List <IFolder>(); parents.Add(Mock.Of <IFolder>(f => f.Id == parentId)); fileInfo.Setup(d => d.FullName).Returns(path); fileInfo.Setup(d => d.Name).Returns(fileName); fileInfo.Setup(d => d.Exists).Returns(true); fileInfo.Setup(d => d.IsExtendedAttributeAvailable()).Returns(extendedAttributes); fileInfo.Setup(d => d.Directory).Returns(parentDirInfo); var transmissionManager = new ActiveActivitiesManager(); var solver = new LocalObjectAdded(this.session.Object, this.storage.Object, this.queue.Object, transmissionManager); solver.Solve(fileInfo.Object, null); this.storage.Verify(s => s.SaveMappedObject(It.IsAny <IMappedObject>()), Times.Never()); }