Esempio n. 1
0
 public void TestFileSystemOperationsInvalidateStatusCache()
 {
     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,
                                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, fileSystemCallbacks.OnFolderCreated, "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);
                     }
 }
        public void TestFileSystemOperationsInvalidateStatusCache()
        {
            Mock <IPlaceholderCollection> mockPlaceholderDb = new Mock <IPlaceholderCollection>(MockBehavior.Strict);

            mockPlaceholderDb.Setup(x => x.GetCount()).Returns(1);
            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,
                                       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, fileSystemCallbacks.OnFolderCreated, "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();
        }
Esempio n. 3
0
        public void StartingAndStoppingSetsMountedState()
        {
            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 (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks(
                                   this.Repo.Context,
                                   this.Repo.GitObjects,
                                   RepoMetadata.Instance,
                                   new MockBlobSizes(),
                                   gitIndexProjection: gitIndexProjection,
                                   backgroundFileSystemTaskRunner: backgroundTaskRunner,
                                   fileSystemVirtualizer: fileSystemVirtualizer))
                        {
                            fileSystemCallbacks.IsMounted.ShouldBeFalse();

                            string error;
                            fileSystemCallbacks.TryStart(out error).ShouldBeTrue();
                            fileSystemCallbacks.IsMounted.ShouldBeTrue();

                            fileSystemCallbacks.Stop();
                            fileSystemCallbacks.IsMounted.ShouldBeFalse();
                        }
        }
Esempio n. 4
0
        public void IsReadyForExternalAcquireLockRequests()
        {
            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 (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks(
                                   this.Repo.Context,
                                   this.Repo.GitObjects,
                                   RepoMetadata.Instance,
                                   new MockBlobSizes(),
                                   gitIndexProjection: gitIndexProjection,
                                   backgroundFileSystemTaskRunner: backgroundTaskRunner,
                                   fileSystemVirtualizer: fileSystemVirtualizer))
                        {
                            string denyMessage;
                            fileSystemCallbacks.IsReadyForExternalAcquireLockRequests(
                                new NamedPipeMessages.LockData(
                                    pid: 0,
                                    isElevated: false,
                                    checkAvailabilityOnly: false,
                                    parsedCommand: "git dummy-command"),
                                out denyMessage).ShouldBeFalse();
                            denyMessage.ShouldEqual("Waiting for mount to complete");

                            string error;
                            fileSystemCallbacks.TryStart(out error).ShouldBeTrue();
                            gitIndexProjection.ProjectionParseComplete = false;
                            fileSystemCallbacks.IsReadyForExternalAcquireLockRequests(
                                new NamedPipeMessages.LockData(
                                    pid: 0,
                                    isElevated: false,
                                    checkAvailabilityOnly: false,
                                    parsedCommand: "git dummy-command"),
                                out denyMessage).ShouldBeFalse();
                            denyMessage.ShouldEqual("Waiting for GVFS to parse index and update placeholder files");

                            // Put something on the background queue
                            fileSystemCallbacks.OnFileCreated("NewFilePath.txt");
                            backgroundTaskRunner.Count.ShouldEqual(1);
                            fileSystemCallbacks.IsReadyForExternalAcquireLockRequests(
                                new NamedPipeMessages.LockData(
                                    pid: 0,
                                    isElevated: false,
                                    checkAvailabilityOnly: false,
                                    parsedCommand: "git dummy-command"),
                                out denyMessage).ShouldBeFalse();
                            denyMessage.ShouldEqual("Waiting for background operations to complete and for GVFS to release the lock");

                            backgroundTaskRunner.BackgroundTasks.Clear();
                            gitIndexProjection.ProjectionParseComplete = true;
                            fileSystemCallbacks.IsReadyForExternalAcquireLockRequests(
                                new NamedPipeMessages.LockData(
                                    pid: 0,
                                    isElevated: false,
                                    checkAvailabilityOnly: false,
                                    parsedCommand: "git dummy-command"),
                                out denyMessage).ShouldBeTrue();
                            denyMessage.ShouldEqual("Waiting for GVFS to release the lock");

                            fileSystemCallbacks.Stop();
                        }
        }
Esempio n. 5
0
        public void IsReadyForExternalAcquireLockRequests()
        {
            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 (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))
                        {
                            string denyMessage;
                            fileSystemCallbacks.IsReadyForExternalAcquireLockRequests(
                                new NamedPipeMessages.LockData(
                                    pid: 0,
                                    isElevated: false,
                                    checkAvailabilityOnly: false,
                                    parsedCommand: "git dummy-command",
                                    gitCommandSessionId: "123"),
                                out denyMessage).ShouldBeFalse();
                            denyMessage.ShouldEqual("Waiting for GVFS to parse index and update placeholder files");

                            string error;
                            fileSystemCallbacks.TryStart(out error).ShouldBeTrue();
                            gitIndexProjection.ProjectionParseComplete = false;
                            fileSystemCallbacks.IsReadyForExternalAcquireLockRequests(
                                new NamedPipeMessages.LockData(
                                    pid: 0,
                                    isElevated: false,
                                    checkAvailabilityOnly: false,
                                    parsedCommand: "git dummy-command",
                                    gitCommandSessionId: "123"),
                                out denyMessage).ShouldBeFalse();
                            denyMessage.ShouldEqual("Waiting for GVFS to parse index and update placeholder files");

                            // Put something on the background queue
                            fileSystemCallbacks.OnFileCreated("NewFilePath.txt");
                            backgroundTaskRunner.Count.ShouldEqual(1);
                            fileSystemCallbacks.IsReadyForExternalAcquireLockRequests(
                                new NamedPipeMessages.LockData(
                                    pid: 0,
                                    isElevated: false,
                                    checkAvailabilityOnly: false,
                                    parsedCommand: "git dummy-command",
                                    gitCommandSessionId: "123"),
                                out denyMessage).ShouldBeFalse();
                            denyMessage.ShouldEqual("Waiting for GVFS to release the lock");

                            backgroundTaskRunner.BackgroundTasks.Clear();
                            gitIndexProjection.ProjectionParseComplete = true;
                            fileSystemCallbacks.IsReadyForExternalAcquireLockRequests(
                                new NamedPipeMessages.LockData(
                                    pid: 0,
                                    isElevated: false,
                                    checkAvailabilityOnly: false,
                                    parsedCommand: "git dummy-command",
                                    gitCommandSessionId: "123"),
                                out denyMessage).ShouldBeTrue();
                            denyMessage.ShouldEqual("Waiting for GVFS to release the lock");

                            fileSystemCallbacks.Stop();
                        }

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