Exemplo n.º 1
0
        public void PermissionDeniedOnModificationDateSavesTheLocalDate()
        {
            Guid uuid             = Guid.NewGuid();
            var  modificationDate = DateTime.UtcNow;

            var localFolder = new Mock <IDirectoryInfo>();

            localFolder.SetupProperty(f => f.LastWriteTimeUtc, modificationDate.AddMinutes(1));
            localFolder.Setup(f => f.FullName).Returns("path");
            localFolder.SetupGuid(uuid);
            localFolder.Setup(f => f.Exists).Returns(true);

            var mappedObject = new MappedObject(
                "name",
                "remoteId",
                MappedObjectType.Folder,
                "parentId",
                "changeToken")
            {
                Guid = uuid,
                LastRemoteWriteTimeUtc = modificationDate.AddMinutes(1),
                LastLocalWriteTimeUtc  = modificationDate,
            };

            this.storage.AddMappedFolder(mappedObject, "path");
            var remoteFolder = MockOfIFolderUtil.CreateRemoteFolderMock("remoteId", "name", "path", "parentId");

            remoteFolder.Setup(r => r.UpdateProperties(It.IsAny <IDictionary <string, object> >(), true)).Throws(new CmisPermissionDeniedException());

            this.underTest.Solve(localFolder.Object, remoteFolder.Object);

            this.storage.VerifySavedMappedObject(MappedObjectType.Folder, "remoteId", "name", "parentId", "changeToken", true, localFolder.Object.LastWriteTimeUtc, remoteFolder.Object.LastModificationDate);
            remoteFolder.Verify(r => r.UpdateProperties(It.IsAny <IDictionary <string, object> >(), true));
        }
Exemplo n.º 2
0
        public void LocalEmptyFileAddedWithExtAttrAndAlreadySetUUID()
        {
            string fileName           = "fileName";
            string fileId             = "fileId";
            string parentId           = "parentId";
            string lastChangeToken    = "token";
            bool   extendedAttributes = true;
            Guid   uuid = Guid.NewGuid();

            Mock <IFileInfo> fileInfo = new Mock <IFileInfo>();

            fileInfo.Setup(f => f.Length).Returns(0);
            fileInfo.SetupGuid(uuid);

            Mock <IDocument> document;

            this.RunSolveFile(fileName, fileId, parentId, lastChangeToken, extendedAttributes, fileInfo, out document);
            this.storage.VerifySavedMappedObject(MappedObjectType.File, fileId, fileName, parentId, lastChangeToken, extendedAttributes, checksum: this.emptyhash, contentSize: 0);
            this.storage.Verify(s => s.SaveMappedObject(It.Is <IMappedObject>(o => o.Guid == uuid)));
            this.session.Verify(
                s => s.CreateDocument(
                    It.Is <IDictionary <string, object> >(p => p.ContainsKey("cmis:name")),
                    It.Is <IObjectId>(o => o.Id == parentId),
                    It.Is <IContentStream>(st => this.VerifyEmptyStream(st)),
                    null,
                    null,
                    null,
                    null),
                Times.Once());
            fileInfo.Verify(d => d.SetExtendedAttribute(It.IsAny <string>(), It.IsAny <string>(), true), Times.Never());
            fileInfo.VerifyThatLocalFileObjectLastWriteTimeUtcIsNeverModified();
            document.Verify(d => d.AppendContentStream(It.IsAny <IContentStream>(), It.IsAny <bool>(), It.IsAny <bool>()), Times.Never());
        }
Exemplo n.º 3
0
        private Mock <IDirectoryInfo> CreateLocalDirectory(DateTime modificationDate)
        {
            var localDirectory = new Mock <IDirectoryInfo>();

            localDirectory.Setup(f => f.LastWriteTimeUtc).Returns(modificationDate.AddMinutes(1));
            localDirectory.Setup(f => f.Exists).Returns(true);
            localDirectory.SetupGuid(this.uuid);
            return(localDirectory);
        }
Exemplo n.º 4
0
        private Mock <IFileInfo> CreateLocalFile(long?fileLength = 20, DateTime?lastModification = null, bool exists = true)
        {
            var localFile = new Mock <IFileInfo>();

            localFile.SetupProperty(f => f.LastWriteTimeUtc, lastModification ?? DateTime.UtcNow);
            localFile.Setup(f => f.Length).Returns(fileLength ?? 20);
            localFile.Setup(f => f.FullName).Returns(this.localPath);
            localFile.SetupGuid(this.uuid);
            localFile.Setup(f => f.Exists).Returns(exists);
            return(localFile);
        }
        private ObjectTree <IFileSystemInfo> CreateTreeFromPathAndGuid(string name, string path, Guid guid)
        {
            var localTree = new ObjectTree <IFileSystemInfo>();
            var fsInfo    = new Mock <IDirectoryInfo>();

            fsInfo.SetupGuid(guid);
            fsInfo.Setup(f => f.FullName).Returns(path);
            fsInfo.Setup(f => f.Name).Returns(name);
            fsInfo.Setup(f => f.LastWriteTimeUtc).Returns(zeroDate);
            localTree.Item     = fsInfo.Object;
            localTree.Children = new List <IObjectTree <IFileSystemInfo> >();
            return(localTree);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        public void PermissionDeniedTriggersNoOperation()
        {
            Guid uuid             = Guid.NewGuid();
            var  modificationDate = DateTime.UtcNow;
            int  fileLength       = 20;

            byte[] content = new byte[fileLength];

            var localFile = new Mock <IFileInfo>();

            localFile.SetupProperty(f => f.LastWriteTimeUtc, modificationDate.AddMinutes(1));
            localFile.Setup(f => f.Length).Returns(fileLength);
            localFile.Setup(f => f.FullName).Returns("path");
            localFile.SetupGuid(uuid);
            localFile.Setup(f => f.Exists).Returns(true);
            using (var uploadedContent = new MemoryStream()) {
                localFile.Setup(
                    f =>
                    f.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete)).Returns(() => { return(new MemoryStream(content)); });

                var mappedObject = new MappedObject(
                    "name",
                    "remoteId",
                    MappedObjectType.File,
                    "parentId",
                    "changeToken",
                    fileLength)
                {
                    Guid = uuid,
                    LastRemoteWriteTimeUtc = modificationDate.AddMinutes(1),
                    LastLocalWriteTimeUtc  = modificationDate,
                    LastChecksum           = new byte[20],
                    ChecksumAlgorithmName  = "SHA-1"
                };
                this.storage.AddMappedFile(mappedObject, "path");
                var remoteFile = MockOfIDocumentUtil.CreateRemoteDocumentMock(null, "remoteId", "name", "parentId", fileLength, new byte[20]);

                remoteFile.Setup(r => r.SetContentStream(It.IsAny <IContentStream>(), true, true)).Throws(new CmisPermissionDeniedException());

                this.underTest.Solve(localFile.Object, remoteFile.Object);

                this.storage.Verify(s => s.SaveMappedObject(It.IsAny <IMappedObject>()), Times.Never());
                remoteFile.VerifySetContentStream();
            }
        }
Exemplo n.º 8
0
        public void LocalEmptyFileAddedWithExtAttrAndAlreadySetUUID()
        {
            this.SetUpMocks(true);
            Guid uuid = Guid.NewGuid();

            Mock <IFileInfo> fileInfo = new Mock <IFileInfo>();

            fileInfo.Setup(f => f.Length).Returns(0);
            fileInfo.SetupGuid(uuid);

            Mock <IDocument> document;

            this.RunSolveFile(this.localObjectName, this.remoteObjectId, this.parentId, lastChangeToken, this.withExtendedAttributes, fileInfo, out document);
            this.storage.VerifySavedMappedObject(MappedObjectType.File, this.remoteObjectId, this.localObjectName, this.parentId, lastChangeToken, this.withExtendedAttributes, checksum: this.emptyhash, contentSize: 0);
            this.storage.Verify(s => s.SaveMappedObject(It.Is <IMappedObject>(o => o.Guid == uuid)));
            this.VerifyCreateDocument(true);
            fileInfo.VerifySet(f => f.Uuid = It.IsAny <Guid?>(), Times.Never());
            fileInfo.VerifyThatLocalFileObjectLastWriteTimeUtcIsNeverModified();
            document.Verify(d => d.AppendContentStream(It.IsAny <IContentStream>(), It.IsAny <bool>(), It.IsAny <bool>()), Times.Never());
        }
        public void RemoteFolderDeletedButNotAllContainingFilesAreSyncedYet()
        {
            this.SetUpTestMocks();
            string               fileName       = "fileName";
            string               filePath       = Path.Combine(this.path, fileName);
            string               syncedFileName = "syncedFileName";
            string               syncedFilePath = Path.Combine(this.path, syncedFileName);
            DateTime             lastModified   = DateTime.UtcNow;
            Guid                 syncedFileGuid = Guid.NewGuid();
            Mock <IMappedObject> folder         = this.storage.AddLocalFolder(this.path, "id");
            var dirInfo = new Mock <IDirectoryInfo>();

            dirInfo.Setup(d => d.FullName).Returns(this.path);
            var fileInfo = new Mock <IFileInfo>();

            fileInfo.Setup(f => f.FullName).Returns(filePath);
            fileInfo.Setup(f => f.Name).Returns(fileName);
            var syncedFileInfo = new Mock <IFileInfo>();

            syncedFileInfo.Setup(s => s.FullName).Returns(syncedFilePath);
            syncedFileInfo.Setup(s => s.Name).Returns(syncedFileName);
            syncedFileInfo.SetupGuid(syncedFileGuid);
            syncedFileInfo.Setup(s => s.LastWriteTimeUtc).Returns(lastModified);
            dirInfo.SetupFiles(fileInfo.Object, syncedFileInfo.Object);
            var mappedSyncedFile = new MappedObject(syncedFileName, "id", MappedObjectType.File, "parentId", "changeToken", 0)
            {
                Guid = syncedFileGuid, LastLocalWriteTimeUtc = lastModified
            };

            this.storage.AddMappedFile(mappedSyncedFile, syncedFilePath);

            Assert.Throws <IOException>(() => this.underTest.Solve(dirInfo.Object, null));

            dirInfo.Verify(d => d.Delete(true), Times.Never());
            syncedFileInfo.Verify(s => s.Delete(), Times.Once());
            fileInfo.Verify(f => f.Delete(), Times.Never());
            this.storage.Verify(s => s.RemoveObject(It.Is <IMappedObject>(o => o == folder.Object)), Times.Once());
        }
Exemplo n.º 10
0
        public void LocalFileContentChanged()
        {
            Guid uuid                = Guid.NewGuid();
            var  modificationDate    = DateTime.UtcNow;
            var  newModificationDate = modificationDate.AddHours(1);
            var  newChangeToken      = "newChangeToken";
            int  fileLength          = 20;

            byte[] content      = new byte[fileLength];
            byte[] expectedHash = SHA1Managed.Create().ComputeHash(content);

            var localFile = new Mock <IFileInfo>();

            localFile.SetupProperty(f => f.LastWriteTimeUtc, modificationDate.AddMinutes(1));
            localFile.Setup(f => f.Length).Returns(fileLength);
            localFile.Setup(f => f.FullName).Returns("path");
            localFile.SetupGuid(uuid);
            localFile.Setup(f => f.Exists).Returns(true);
            using (var uploadedContent = new MemoryStream()) {
                localFile.Setup(
                    f =>
                    f.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete)).Returns(() => { return(new MemoryStream(content)); });

                var mappedObject = new MappedObject(
                    "name",
                    "remoteId",
                    MappedObjectType.File,
                    "parentId",
                    "changeToken",
                    fileLength)
                {
                    Guid = uuid,
                    LastRemoteWriteTimeUtc = modificationDate.AddMinutes(1),
                    LastLocalWriteTimeUtc  = modificationDate,
                    LastChecksum           = new byte[20],
                    ChecksumAlgorithmName  = "SHA-1"
                };
                this.storage.AddMappedFile(mappedObject, "path");
                var remoteFile = MockOfIDocumentUtil.CreateRemoteDocumentMock(null, "remoteId", "name", "parentId", fileLength, new byte[20]);
                remoteFile.Setup(r => r.SetContentStream(It.IsAny <IContentStream>(), true, true)).Callback <IContentStream, bool, bool>(
                    (s, o, r) =>
                    { s.Stream.CopyTo(uploadedContent);
                      remoteFile.Setup(f => f.LastModificationDate).Returns(newModificationDate);
                      remoteFile.Setup(f => f.ChangeToken).Returns(newChangeToken); });

                this.underTest.Solve(localFile.Object, remoteFile.Object);

                this.storage.VerifySavedMappedObject(
                    MappedObjectType.File,
                    "remoteId",
                    mappedObject.Name,
                    mappedObject.ParentId,
                    newChangeToken,
                    true,
                    localFile.Object.LastWriteTimeUtc,
                    localFile.Object.LastWriteTimeUtc,
                    expectedHash,
                    fileLength);
                remoteFile.VerifySetContentStream();
                Assert.That(uploadedContent.ToArray(), Is.EqualTo(content));
                localFile.VerifyThatLocalFileObjectLastWriteTimeUtcIsNeverModified();
                this.manager.Verify(m => m.AddTransmission(It.IsAny <FileTransmissionEvent>()), Times.Once());
            }
        }
        public void RemoteFolderDeletedButNotAllContainingFilesAreSyncedYet() {
            this.SetUpTestMocks();
            string fileName = "fileName";
            string filePath = Path.Combine(this.path, fileName);
            string syncedFileName = "syncedFileName";
            string syncedFilePath = Path.Combine(this.path, syncedFileName);
            DateTime lastModified = DateTime.UtcNow;
            Guid syncedFileGuid = Guid.NewGuid();
            Mock<IMappedObject> folder = this.storage.AddLocalFolder(this.path, "id");
            var dirInfo = new Mock<IDirectoryInfo>();
            dirInfo.Setup(d => d.FullName).Returns(this.path);
            var fileInfo = new Mock<IFileInfo>();
            fileInfo.Setup(f => f.FullName).Returns(filePath);
            fileInfo.Setup(f => f.Name).Returns(fileName);
            var syncedFileInfo = new Mock<IFileInfo>();
            syncedFileInfo.Setup(s => s.FullName).Returns(syncedFilePath);
            syncedFileInfo.Setup(s => s.Name).Returns(syncedFileName);
            syncedFileInfo.SetupGuid(syncedFileGuid);
            syncedFileInfo.Setup(s => s.LastWriteTimeUtc).Returns(lastModified);
            dirInfo.SetupFiles(fileInfo.Object, syncedFileInfo.Object);
            var mappedSyncedFile = new MappedObject(syncedFileName, "id", MappedObjectType.File, "parentId", "changeToken", 0) { Guid = syncedFileGuid, LastLocalWriteTimeUtc = lastModified };
            this.storage.AddMappedFile(mappedSyncedFile, syncedFilePath);

            Assert.Throws<IOException>(() => this.underTest.Solve(dirInfo.Object, null));

            dirInfo.Verify(d => d.Delete(true), Times.Never());
            syncedFileInfo.Verify(s => s.Delete(), Times.Once());
            fileInfo.Verify(f => f.Delete(), Times.Never());
            this.storage.Verify(s => s.RemoveObject(It.Is<IMappedObject>(o => o == folder.Object)), Times.Once());
        }
Exemplo n.º 12
0
        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;
        }
Exemplo n.º 13
0
        public void LocalEmptyFileAdded(bool withExtendedAttributes, bool withAlreadySetUuid) {
            this.SetUpMocks(withExtendedAttributes);
            Guid uuid = Guid.NewGuid();
            Mock<IFileInfo> fileInfo = new Mock<IFileInfo>();
            fileInfo.Setup(f => f.Length).Returns(0);
            if (withAlreadySetUuid) {
                fileInfo.SetupGuid(uuid);
            }

            Mock<IDocument> document;

            this.SetupSolveFile(this.localObjectName, this.remoteObjectId, this.parentId, this.lastChangeToken, this.withExtendedAttributes, fileInfo, out document);
            this.RunSolveFile(fileInfo);

            this.storage.VerifySavedMappedObject(MappedObjectType.File, this.remoteObjectId, this.localObjectName, this.parentId, this.lastChangeToken, this.withExtendedAttributes, checksum: this.emptyhash, contentSize: 0);
            if (withAlreadySetUuid) {
                this.storage.Verify(s => s.SaveMappedObject(It.Is<IMappedObject>(o => o.Guid == uuid)));
            }

            this.VerifyCreateDocument(isEmpty: true);
            if (this.withExtendedAttributes && !withAlreadySetUuid) {
                fileInfo.VerifySet(f => f.Uuid = It.Is<Guid?>(u => u != null), Times.Once());
            } else {
                fileInfo.VerifySet(f => f.Uuid = It.IsAny<Guid?>(), Times.Never());
            }

            fileInfo.VerifyThatLocalFileObjectLastWriteTimeUtcIsNeverModified();
            document.Verify(d => d.AppendContentStream(It.IsAny<IContentStream>(), It.IsAny<bool>(), It.IsAny<bool>()), Times.Never());
        }
 private ObjectTree<IFileSystemInfo> CreateTreeFromPathAndGuid(string name, string path, Guid guid) {
     var localTree = new ObjectTree<IFileSystemInfo>();
     var fsInfo = new Mock<IDirectoryInfo>();
     fsInfo.SetupGuid(guid);
     fsInfo.Setup(f => f.FullName).Returns(path);
     fsInfo.Setup(f => f.Name).Returns(name);
     fsInfo.Setup(f => f.LastWriteTimeUtc).Returns(zeroDate);
     localTree.Item = fsInfo.Object;
     localTree.Children = new List<IObjectTree<IFileSystemInfo>>();
     return localTree;
 }
 private Mock<IFileInfo> CreateLocalFile(long? fileLength = 20, DateTime? lastModification = null, bool exists = true) {
     var localFile = new Mock<IFileInfo>();
     localFile.SetupProperty(f => f.LastWriteTimeUtc, lastModification ?? DateTime.UtcNow);
     localFile.Setup(f => f.Length).Returns(fileLength ?? 20);
     localFile.Setup(f => f.FullName).Returns(this.localPath);
     localFile.SetupGuid(this.uuid);
     localFile.Setup(f => f.Exists).Returns(exists);
     return localFile;
 }
 private Mock<IDirectoryInfo> CreateLocalDirectory(DateTime modificationDate) {
     var localDirectory = new Mock<IDirectoryInfo>();
     localDirectory.Setup(f => f.LastWriteTimeUtc).Returns(modificationDate.AddMinutes(1));
     localDirectory.Setup(f => f.Exists).Returns(true);
     localDirectory.SetupGuid(this.uuid);
     return localDirectory;
 }