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());
        }
        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 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;
 }