Exemple #1
0
        public void TestFileSystemOperationsInvalidateStatusCache()
        {
            Mock <IPlaceholderCollection> mockPlaceholderDb = new Mock <IPlaceholderCollection>(MockBehavior.Strict);

            mockPlaceholderDb.Setup(x => x.GetCount()).Returns(1);
            Mock <ISparseCollection> mockSparseDb = new Mock <ISparseCollection>(MockBehavior.Strict);

            using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner())
                using (MockFileSystemVirtualizer fileSystemVirtualizer = new MockFileSystemVirtualizer(this.Repo.Context, this.Repo.GitObjects))
                    using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { "test.txt" }))
                        using (MockGitStatusCache gitStatusCache = new MockGitStatusCache(this.Repo.Context, TimeSpan.Zero))
                            using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks(
                                       this.Repo.Context,
                                       this.Repo.GitObjects,
                                       RepoMetadata.Instance,
                                       new MockBlobSizes(),
                                       gitIndexProjection: gitIndexProjection,
                                       backgroundFileSystemTaskRunner: backgroundTaskRunner,
                                       fileSystemVirtualizer: fileSystemVirtualizer,
                                       placeholderDatabase: mockPlaceholderDb.Object,
                                       sparseCollection: mockSparseDb.Object,
                                       gitStatusCache: gitStatusCache))
                            {
                                this.ValidateActionInvalidatesStatusCache(backgroundTaskRunner, gitStatusCache, fileSystemCallbacks.OnFileConvertedToFull, "OnFileConvertedToFull.txt", FileSystemTask.OperationType.OnFileConvertedToFull);
                                this.ValidateActionInvalidatesStatusCache(backgroundTaskRunner, gitStatusCache, fileSystemCallbacks.OnFileCreated, "OnFileCreated.txt", FileSystemTask.OperationType.OnFileCreated);
                                this.ValidateActionInvalidatesStatusCache(backgroundTaskRunner, gitStatusCache, fileSystemCallbacks.OnFileDeleted, "OnFileDeleted.txt", FileSystemTask.OperationType.OnFileDeleted);
                                this.ValidateActionInvalidatesStatusCache(backgroundTaskRunner, gitStatusCache, fileSystemCallbacks.OnFileOverwritten, "OnFileDeleted.txt", FileSystemTask.OperationType.OnFileOverwritten);
                                this.ValidateActionInvalidatesStatusCache(backgroundTaskRunner, gitStatusCache, fileSystemCallbacks.OnFileSuperseded, "OnFileSuperseded.txt", FileSystemTask.OperationType.OnFileSuperseded);
                                this.ValidateActionInvalidatesStatusCache(backgroundTaskRunner, gitStatusCache, x => fileSystemCallbacks.OnFolderCreated(x, out _), "OnFileSuperseded.txt", FileSystemTask.OperationType.OnFolderCreated);
                                this.ValidateActionInvalidatesStatusCache(backgroundTaskRunner, gitStatusCache, fileSystemCallbacks.OnFolderDeleted, "OnFileSuperseded.txt", FileSystemTask.OperationType.OnFolderDeleted);
                                this.ValidateActionInvalidatesStatusCache(backgroundTaskRunner, gitStatusCache, fileSystemCallbacks.OnFileConvertedToFull, "OnFileConvertedToFull.txt", FileSystemTask.OperationType.OnFileConvertedToFull);
                            }

            mockPlaceholderDb.VerifyAll();
            mockSparseDb.VerifyAll();
        }
Exemple #2
0
        public void FileAndFolderCallbacksScheduleBackgroundTasks()
        {
            using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner())
                using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks(
                           this.Repo.Context,
                           this.Repo.GitObjects,
                           RepoMetadata.Instance,
                           new MockBlobSizes(),
                           gitIndexProjection: null,
                           backgroundFileSystemTaskRunner: backgroundTaskRunner,
                           fileSystemVirtualizer: null))
                {
                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (path) => fileSystemCallbacks.OnFileConvertedToFull(path),
                        "OnFileConvertedToFull.txt",
                        FileSystemTask.OperationType.OnFileConvertedToFull);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (path) => fileSystemCallbacks.OnFileCreated(path),
                        "OnFileCreated.txt",
                        FileSystemTask.OperationType.OnFileCreated);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (path) => fileSystemCallbacks.OnFileDeleted(path),
                        "OnFileDeleted.txt",
                        FileSystemTask.OperationType.OnFileDeleted);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (path) => fileSystemCallbacks.OnFileOverwritten(path),
                        "OnFileOverwritten.txt",
                        FileSystemTask.OperationType.OnFileOverwritten);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (oldPath, newPath) => fileSystemCallbacks.OnFileRenamed(oldPath, newPath),
                        "OnFileRenamed.txt",
                        "OnFileRenamed2.txt",
                        FileSystemTask.OperationType.OnFileRenamed);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (path) => fileSystemCallbacks.OnFileSuperseded(path),
                        "OnFileSuperseded.txt",
                        FileSystemTask.OperationType.OnFileSuperseded);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (path) => fileSystemCallbacks.OnFolderCreated(path),
                        "OnFolderCreated.txt",
                        FileSystemTask.OperationType.OnFolderCreated);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (path) => fileSystemCallbacks.OnFolderDeleted(path),
                        "OnFolderDeleted.txt",
                        FileSystemTask.OperationType.OnFolderDeleted);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (oldPath, newPath) => fileSystemCallbacks.OnFolderRenamed(oldPath, newPath),
                        "OnFolderRenamed.txt",
                        "OnFolderRenamed2.txt",
                        FileSystemTask.OperationType.OnFolderRenamed);
                }
        }
Exemple #3
0
        public void FileAndFolderCallbacksScheduleBackgroundTasks()
        {
            Mock <IPlaceholderCollection> mockPlaceholderDb = new Mock <IPlaceholderCollection>(MockBehavior.Strict);

            mockPlaceholderDb.Setup(x => x.GetCount()).Returns(1);
            Mock <ISparseCollection> mockSparseDb = new Mock <ISparseCollection>(MockBehavior.Strict);

            mockSparseDb.Setup(x => x.GetAll()).Returns(new HashSet <string>());
            using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner())
                using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks(
                           this.Repo.Context,
                           this.Repo.GitObjects,
                           RepoMetadata.Instance,
                           new MockBlobSizes(),
                           gitIndexProjection: null,
                           backgroundFileSystemTaskRunner: backgroundTaskRunner,
                           fileSystemVirtualizer: null,
                           placeholderDatabase: mockPlaceholderDb.Object,
                           sparseCollection: mockSparseDb.Object))
                {
                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (path) => fileSystemCallbacks.OnFileConvertedToFull(path),
                        "OnFileConvertedToFull.txt",
                        FileSystemTask.OperationType.OnFileConvertedToFull);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (path) => fileSystemCallbacks.OnFileCreated(path),
                        "OnFileCreated.txt",
                        FileSystemTask.OperationType.OnFileCreated);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (path) => fileSystemCallbacks.OnFileDeleted(path),
                        "OnFileDeleted.txt",
                        FileSystemTask.OperationType.OnFileDeleted);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (path) => fileSystemCallbacks.OnFileOverwritten(path),
                        "OnFileOverwritten.txt",
                        FileSystemTask.OperationType.OnFileOverwritten);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (oldPath, newPath) => fileSystemCallbacks.OnFileRenamed(oldPath, newPath),
                        "OnFileRenamed.txt",
                        "OnFileRenamed2.txt",
                        FileSystemTask.OperationType.OnFileRenamed);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (existingPath, newLink) => fileSystemCallbacks.OnFileHardLinkCreated(newLink, existingPath),
                        string.Empty,
                        "OnFileHardLinkCreated.txt",
                        FileSystemTask.OperationType.OnFileHardLinkCreated);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (path) => fileSystemCallbacks.OnFileSuperseded(path),
                        "OnFileSuperseded.txt",
                        FileSystemTask.OperationType.OnFileSuperseded);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (path) => fileSystemCallbacks.OnFolderCreated(path, out _),
                        "OnFolderCreated.txt",
                        FileSystemTask.OperationType.OnFolderCreated);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (path) => fileSystemCallbacks.OnFolderDeleted(path),
                        "OnFolderDeleted.txt",
                        FileSystemTask.OperationType.OnFolderDeleted);

                    this.CallbackSchedulesBackgroundTask(
                        backgroundTaskRunner,
                        (oldPath, newPath) => fileSystemCallbacks.OnFolderRenamed(oldPath, newPath),
                        "OnFolderRenamed.txt",
                        "OnFolderRenamed2.txt",
                        FileSystemTask.OperationType.OnFolderRenamed);
                }

            mockPlaceholderDb.VerifyAll();
            mockSparseDb.VerifyAll();
        }