public void GetPlaceholderInformationHandlerCancelledDuringAsyncCallback() { using (MockVirtualizationInstance mockGvFlt = new MockVirtualizationInstance()) using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { "test.txt" })) { GVFltCallbacks callbacks = new GVFltCallbacks( this.Repo.Context, this.Repo.GitObjects, RepoMetadata.Instance, new MockBlobSizes(), gvflt: mockGvFlt, gitIndexProjection: gitIndexProjection, reliableBackgroundOperations: new MockReliableBackgroundOperations()); string error; callbacks.TryStart(out error).ShouldEqual(true); gitIndexProjection.BlockGetProjectedFileInfo(willWaitForRequest: true); mockGvFlt.OnGetPlaceholderInformation(1, "test.txt", 0, 0, 0, 0, 1, "UnitTests").ShouldEqual(HResult.Pending); gitIndexProjection.WaitForGetProjectedFileInfo(); mockGvFlt.OnCancelCommand(1); gitIndexProjection.UnblockGetProjectedFileInfo(); // Cancelling in the middle of GetPlaceholderInformation still allows it to create placeholders when the cancellation does not // interrupt network requests mockGvFlt.WaitForPlaceholderCreate(); gitIndexProjection.WaitForPlaceholderCreate(); mockGvFlt.CreatedPlaceholders.ShouldContain(entry => entry == "test.txt"); gitIndexProjection.PlaceholdersCreated.ShouldContain(entry => entry == "test.txt"); callbacks.Stop(); } }
public void OnEnumerateDirectorySetsFileModes() { using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner()) using (MockVirtualizationInstance mockVirtualization = new MockVirtualizationInstance()) using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { "test644.txt", "test664.txt", "test755.txt" })) using (MacFileSystemVirtualizer virtualizer = new MacFileSystemVirtualizer(this.Repo.Context, this.Repo.GitObjects, mockVirtualization)) using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks( this.Repo.Context, this.Repo.GitObjects, RepoMetadata.Instance, new MockBlobSizes(), gitIndexProjection, backgroundFileSystemTaskRunner: backgroundTaskRunner, fileSystemVirtualizer: virtualizer)) { gitIndexProjection.MockFileModes.TryAdd("test" + Path.DirectorySeparatorChar + "test644.txt", FileMode644); gitIndexProjection.MockFileModes.TryAdd("test" + Path.DirectorySeparatorChar + "test664.txt", FileMode664); gitIndexProjection.MockFileModes.TryAdd("test" + Path.DirectorySeparatorChar + "test755.txt", FileMode755); string error; fileSystemCallbacks.TryStart(out error).ShouldEqual(true); Guid enumerationGuid = Guid.NewGuid(); gitIndexProjection.EnumerationInMemory = true; mockVirtualization.OnEnumerateDirectory(1, "test", triggeringProcessId: 1, triggeringProcessName: "UnitTests").ShouldEqual(Result.Success); mockVirtualization.CreatedPlaceholders.ShouldContain( kvp => kvp.Key.Equals(Path.Combine("test", "test644.txt"), StringComparison.OrdinalIgnoreCase) && kvp.Value == FileMode644); mockVirtualization.CreatedPlaceholders.ShouldContain( kvp => kvp.Key.Equals(Path.Combine("test", "test664.txt"), StringComparison.OrdinalIgnoreCase) && kvp.Value == FileMode664); mockVirtualization.CreatedPlaceholders.ShouldContain( kvp => kvp.Key.Equals(Path.Combine("test", "test755.txt"), StringComparison.OrdinalIgnoreCase) && kvp.Value == FileMode755); fileSystemCallbacks.Stop(); } }
public void GetPlaceholderInformationHandlerCancelledDuringNetworkRequest() { using (MockVirtualizationInstance mockGvFlt = new MockVirtualizationInstance()) using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { "test.txt" })) { GVFltCallbacks callbacks = new GVFltCallbacks( this.Repo.Context, this.Repo.GitObjects, RepoMetadata.Instance, new MockBlobSizes(), gvflt: mockGvFlt, gitIndexProjection: gitIndexProjection, reliableBackgroundOperations: new MockReliableBackgroundOperations()); string error; callbacks.TryStart(out error).ShouldEqual(true); MockTracer mockTracker = this.Repo.Context.Tracer as MockTracer; mockTracker.WaitRelatedEventName = "GVFltGetPlaceholderInformationAsyncHandler_GetProjectedGVFltFileInfoAndShaCancelled"; gitIndexProjection.ThrowOperationCanceledExceptionOnProjectionRequest = true; mockGvFlt.OnGetPlaceholderInformation(1, "test.txt", 0, 0, 0, 0, 1, "UnitTests").ShouldEqual(HResult.Pending); // Cancelling in the middle of GetPlaceholderInformation in the middle of a network request should not result in placeholder // getting created mockTracker.WaitForRelatedEvent(); mockGvFlt.CreatedPlaceholders.ShouldNotContain(entry => entry == "test.txt"); gitIndexProjection.PlaceholdersCreated.ShouldNotContain(entry => entry == "test.txt"); callbacks.Stop(); } }
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(); }
public void OnStartDirectoryEnumerationReturnsPendingWhenResultsNotInMemory() { using (MockVirtualizationInstance mockGvFlt = new MockVirtualizationInstance()) using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { "test.txt" })) { GVFltCallbacks callbacks = new GVFltCallbacks( this.Repo.Context, this.Repo.GitObjects, RepoMetadata.Instance, new MockBlobSizes(), gvflt: mockGvFlt, gitIndexProjection: gitIndexProjection, reliableBackgroundOperations: new MockReliableBackgroundOperations()); string error; callbacks.TryStart(out error).ShouldEqual(true); Guid enumerationGuid = Guid.NewGuid(); gitIndexProjection.EnumerationInMemory = false; mockGvFlt.OnStartDirectoryEnumeration(1, enumerationGuid, "test").ShouldEqual(HResult.Pending); mockGvFlt.WaitForCompletionStatus().ShouldEqual(HResult.Ok); mockGvFlt.OnEndDirectoryEnumeration(enumerationGuid).ShouldEqual(HResult.Ok); callbacks.Stop(); } }
public void GetPlaceholderInformationHandlerPathProjected() { using (MockVirtualizationInstance mockGvFlt = new MockVirtualizationInstance()) using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { "test.txt" })) { GVFltCallbacks callbacks = new GVFltCallbacks( this.Repo.Context, this.Repo.GitObjects, RepoMetadata.Instance, new MockBlobSizes(), gvflt: mockGvFlt, gitIndexProjection: gitIndexProjection, reliableBackgroundOperations: new MockReliableBackgroundOperations()); string error; callbacks.TryStart(out error).ShouldEqual(true); mockGvFlt.OnGetPlaceholderInformation(1, "test.txt", 0, 0, 0, 0, 1, "UnitTests").ShouldEqual(HResult.Pending); mockGvFlt.WaitForCompletionStatus().ShouldEqual(HResult.Ok); mockGvFlt.CreatedPlaceholders.ShouldContain(entry => entry == "test.txt"); gitIndexProjection.PlaceholdersCreated.ShouldContain(entry => entry == "test.txt"); callbacks.Stop(); } }
public void OnEnumerateDirectorySetsFileModes() { const string TestFile644Name = "test644.txt"; const string TestFile664Name = "test664.txt"; const string TestFile755Name = "test755.txt"; const string TestFolderName = "testFolder"; string testFile644Path = Path.Combine(TestFolderName, TestFile644Name); string testFile664Path = Path.Combine(TestFolderName, TestFile664Name); string testFile755Path = Path.Combine(TestFolderName, TestFile755Name); 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 (MockVirtualizationInstance mockVirtualization = new MockVirtualizationInstance()) // Don't include TestFolderName as MockGitIndexProjection returns the same list of files regardless of what folder name // it is passed using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { TestFile644Name, TestFile664Name, TestFile755Name })) using (MacFileSystemVirtualizer virtualizer = new MacFileSystemVirtualizer(this.Repo.Context, this.Repo.GitObjects, mockVirtualization)) using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks( this.Repo.Context, this.Repo.GitObjects, RepoMetadata.Instance, new MockBlobSizes(), gitIndexProjection, backgroundTaskRunner, virtualizer, mockPlaceholderDb.Object, mockSparseDb.Object)) { gitIndexProjection.MockFileTypesAndModes.TryAdd( testFile644Path, ConvertFileTypeAndModeToIndexFormat(GitIndexProjection.FileType.Regular, GitIndexProjection.FileMode644)); gitIndexProjection.MockFileTypesAndModes.TryAdd( testFile664Path, ConvertFileTypeAndModeToIndexFormat(GitIndexProjection.FileType.Regular, GitIndexProjection.FileMode664)); gitIndexProjection.MockFileTypesAndModes.TryAdd( testFile755Path, ConvertFileTypeAndModeToIndexFormat(GitIndexProjection.FileType.Regular, GitIndexProjection.FileMode755)); string error; fileSystemCallbacks.TryStart(out error).ShouldEqual(true); Guid enumerationGuid = Guid.NewGuid(); gitIndexProjection.EnumerationInMemory = true; mockVirtualization.OnEnumerateDirectory(1, TestFolderName, triggeringProcessId: 1, triggeringProcessName: "UnitTests").ShouldEqual(Result.Success); mockVirtualization.CreatedPlaceholders.ShouldContain( kvp => kvp.Key.Equals(testFile644Path, StringComparison.OrdinalIgnoreCase) && kvp.Value == GitIndexProjection.FileMode644); mockVirtualization.CreatedPlaceholders.ShouldContain( kvp => kvp.Key.Equals(testFile664Path, StringComparison.OrdinalIgnoreCase) && kvp.Value == GitIndexProjection.FileMode664); mockVirtualization.CreatedPlaceholders.ShouldContain( kvp => kvp.Key.Equals(testFile755Path, StringComparison.OrdinalIgnoreCase) && kvp.Value == GitIndexProjection.FileMode755); fileSystemCallbacks.Stop(); } mockPlaceholderDb.VerifyAll(); mockSparseDb.VerifyAll(); }
public void OnGetFileStreamReturnsInternalErrorWhenPlaceholderVersionDoesNotMatchExpected() { using (MockVirtualizationInstance mockGvFlt = new MockVirtualizationInstance()) using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { "test.txt" })) { GVFltCallbacks callbacks = new GVFltCallbacks( this.Repo.Context, this.Repo.GitObjects, RepoMetadata.Instance, blobSizes: null, gvflt: mockGvFlt, gitIndexProjection: gitIndexProjection, reliableBackgroundOperations: new MockReliableBackgroundOperations()); string error; callbacks.TryStart(out error).ShouldEqual(true); Guid enumerationGuid = Guid.NewGuid(); byte[] contentId = GVFltCallbacks.ConvertShaToContentId("0123456789012345678901234567890123456789"); byte[] epochId = new byte[] { GVFltCallbacks.PlaceholderVersion + 1 }; mockGvFlt.OnGetFileStream( commandId: 1, relativePath: "test.txt", byteOffset: 0, length: 100, streamGuid: Guid.NewGuid(), contentId: contentId, epochId: epochId, triggeringProcessId: 2, triggeringProcessImageFileName: "UnitTest").ShouldEqual(NtStatus.InternalError); } }
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 UpdatePlaceholderToSymLink() { const string PlaceholderToLinkFileName = "testUpdatePlaceholderToLink.txt"; Mock <IPlaceholderCollection> mockPlaceholderDb = new Mock <IPlaceholderCollection>(MockBehavior.Strict); mockPlaceholderDb.Setup(x => x.GetCount()).Returns(1); using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner()) using (MockVirtualizationInstance mockVirtualization = new MockVirtualizationInstance()) using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { PlaceholderToLinkFileName })) using (MacFileSystemVirtualizer virtualizer = new MacFileSystemVirtualizer(this.Repo.Context, this.Repo.GitObjects, mockVirtualization)) using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks( this.Repo.Context, this.Repo.GitObjects, RepoMetadata.Instance, new MockBlobSizes(), gitIndexProjection, backgroundTaskRunner, virtualizer, mockPlaceholderDb.Object)) { gitIndexProjection.MockFileTypesAndModes.TryAdd( PlaceholderToLinkFileName, ConvertFileTypeAndModeToIndexFormat(GitIndexProjection.FileType.SymLink, fileMode: 0)); string error; fileSystemCallbacks.TryStart(out error).ShouldEqual(true); UpdateFailureReason failureReason = UpdateFailureReason.NoFailure; mockVirtualization.UpdatePlaceholderIfNeededResult = Result.Success; mockVirtualization.UpdatePlaceholderIfNeededFailureCause = UpdateFailureCause.NoFailure; virtualizer .UpdatePlaceholderIfNeeded( PlaceholderToLinkFileName, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, 0, 15, string.Empty, UpdatePlaceholderType.AllowReadOnly, out failureReason) .ShouldEqual(new FileSystemResult(FSResult.Ok, (int)mockVirtualization.UpdatePlaceholderIfNeededResult)); failureReason.ShouldEqual((UpdateFailureReason)mockVirtualization.UpdatePlaceholderIfNeededFailureCause); mockVirtualization.UpdatedPlaceholders.Count.ShouldEqual(0, "UpdatePlaceholderIfNeeded should not be called when converting a placeholder to a link"); mockVirtualization.CreatedSymLinks.Count.ShouldEqual(1); mockVirtualization.CreatedSymLinks.ShouldContain(entry => entry.Equals(PlaceholderToLinkFileName)); // Creating a symlink should schedule a background task backgroundTaskRunner.Count.ShouldEqual(1); backgroundTaskRunner.BackgroundTasks[0].Operation.ShouldEqual(GVFS.Virtualization.Background.FileSystemTask.OperationType.OnFileSymLinkCreated); backgroundTaskRunner.BackgroundTasks[0].VirtualPath.ShouldEqual(PlaceholderToLinkFileName); fileSystemCallbacks.Stop(); } mockPlaceholderDb.VerifyAll(); }
public void OnGetFileStreamReturnsSuccessWhenFileStreamAvailable() { const string TestFileName = "test.txt"; 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 (MockVirtualizationInstance mockVirtualization = new MockVirtualizationInstance()) using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { TestFileName })) using (MacFileSystemVirtualizer virtualizer = new MacFileSystemVirtualizer(this.Repo.Context, this.Repo.GitObjects, mockVirtualization)) using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks( this.Repo.Context, this.Repo.GitObjects, RepoMetadata.Instance, new MockBlobSizes(), gitIndexProjection, backgroundTaskRunner, virtualizer, mockPlaceholderDb.Object, mockSparseDb.Object)) { string error; fileSystemCallbacks.TryStart(out error).ShouldEqual(true); byte[] contentId = FileSystemVirtualizer.ConvertShaToContentId("0123456789012345678901234567890123456789"); byte[] placeholderVersion = MacFileSystemVirtualizer.PlaceholderVersionId; uint fileLength = 100; MockGVFSGitObjects mockGVFSGitObjects = this.Repo.GitObjects as MockGVFSGitObjects; mockGVFSGitObjects.FileLength = fileLength; mockVirtualization.WriteFileReturnResult = Result.Success; mockVirtualization.OnGetFileStream( commandId: 1, relativePath: TestFileName, providerId: placeholderVersion, contentId: contentId, triggeringProcessId: 2, triggeringProcessName: "UnitTest", fileHandle: IntPtr.Zero).ShouldEqual(Result.Success); mockVirtualization.BytesWritten.ShouldEqual(fileLength); fileSystemCallbacks.Stop(); } mockPlaceholderDb.VerifyAll(); mockSparseDb.VerifyAll(); }
public void WritePlaceholderForSymLink() { const string WriteSymLinkFileName = "testWriteSymLink.txt"; 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 (MockVirtualizationInstance mockVirtualization = new MockVirtualizationInstance()) using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { WriteSymLinkFileName })) using (MacFileSystemVirtualizer virtualizer = new MacFileSystemVirtualizer(this.Repo.Context, this.Repo.GitObjects, mockVirtualization)) using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks( this.Repo.Context, this.Repo.GitObjects, RepoMetadata.Instance, new MockBlobSizes(), gitIndexProjection, backgroundTaskRunner, virtualizer, mockPlaceholderDb.Object, mockSparseDb.Object)) { gitIndexProjection.MockFileTypesAndModes.TryAdd( WriteSymLinkFileName, ConvertFileTypeAndModeToIndexFormat(GitIndexProjection.FileType.SymLink, fileMode: 0)); string error; fileSystemCallbacks.TryStart(out error).ShouldEqual(true); virtualizer.WritePlaceholderFile( WriteSymLinkFileName, endOfFile: 0, sha: string.Empty).ShouldEqual(new FileSystemResult(FSResult.Ok, (int)Result.Success)); mockVirtualization.CreatedPlaceholders.ShouldBeEmpty(); mockVirtualization.CreatedSymLinks.Count.ShouldEqual(1); mockVirtualization.CreatedSymLinks.ShouldContain(entry => entry.Equals(WriteSymLinkFileName)); // Creating a symlink should schedule a background task backgroundTaskRunner.Count.ShouldEqual(1); backgroundTaskRunner.BackgroundTasks[0].Operation.ShouldEqual(GVFS.Virtualization.Background.FileSystemTask.OperationType.OnFileSymLinkCreated); backgroundTaskRunner.BackgroundTasks[0].VirtualPath.ShouldEqual(WriteSymLinkFileName); fileSystemCallbacks.Stop(); } mockPlaceholderDb.VerifyAll(); mockSparseDb.VerifyAll(); }
public void OnGetFileStreamHandlesCancellationDuringWriteAction() { using (MockVirtualizationInstance mockGvFlt = new MockVirtualizationInstance()) using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { "test.txt" })) { GVFltCallbacks callbacks = new GVFltCallbacks( this.Repo.Context, this.Repo.GitObjects, RepoMetadata.Instance, new MockBlobSizes(), gvflt: mockGvFlt, gitIndexProjection: gitIndexProjection, reliableBackgroundOperations: new MockReliableBackgroundOperations()); string error; callbacks.TryStart(out error).ShouldEqual(true); Guid enumerationGuid = Guid.NewGuid(); byte[] contentId = GVFltCallbacks.ConvertShaToContentId("0123456789012345678901234567890123456789"); byte[] placeholderVersion = GVFltCallbacks.GetPlaceholderVersionId(); uint fileLength = 100; MockGVFSGitObjects mockGVFSGitObjects = this.Repo.GitObjects as MockGVFSGitObjects; mockGVFSGitObjects.FileLength = fileLength; MockTracer mockTracker = this.Repo.Context.Tracer as MockTracer; mockTracker.WaitRelatedEventName = "GVFltGetFileStreamHandlerAsyncHandler_OperationCancelled"; mockGvFlt.BlockCreateWriteBuffer(willWaitForRequest: true); mockGvFlt.OnGetFileStream( commandId: 1, relativePath: "test.txt", byteOffset: 0, length: fileLength, streamGuid: Guid.NewGuid(), contentId: contentId, providerId: placeholderVersion, triggeringProcessId: 2, triggeringProcessImageFileName: "UnitTest").ShouldEqual(HResult.Pending); mockGvFlt.WaitForCreateWriteBuffer(); mockGvFlt.OnCancelCommand(1); mockGvFlt.UnblockCreateWriteBuffer(); mockTracker.WaitForRelatedEvent(); callbacks.Stop(); } }
public void OnGetFileStreamHandlesGvWriteFailure() { using (MockVirtualizationInstance mockGvFlt = new MockVirtualizationInstance()) using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { "test.txt" })) { GVFltCallbacks callbacks = new GVFltCallbacks( this.Repo.Context, this.Repo.GitObjects, RepoMetadata.Instance, blobSizes: null, gvflt: mockGvFlt, gitIndexProjection: gitIndexProjection, reliableBackgroundOperations: new MockReliableBackgroundOperations()); string error; callbacks.TryStart(out error).ShouldEqual(true); Guid enumerationGuid = Guid.NewGuid(); byte[] contentId = GVFltCallbacks.ConvertShaToContentId("0123456789012345678901234567890123456789"); byte[] epochId = GVFltCallbacks.GetEpochId(); uint fileLength = 100; MockGVFSGitObjects mockGVFSGitObjects = this.Repo.GitObjects as MockGVFSGitObjects; mockGVFSGitObjects.FileLength = fileLength; MockTracer mockTracker = this.Repo.Context.Tracer as MockTracer; mockTracker.WaitRelatedEventName = "GVFltGetFileStreamHandlerAsyncHandler_OperationCancelled"; mockGvFlt.WriteFileReturnStatus = NtStatus.InternalError; mockGvFlt.OnGetFileStream( commandId: 1, relativePath: "test.txt", byteOffset: 0, length: fileLength, streamGuid: Guid.NewGuid(), contentId: contentId, epochId: epochId, triggeringProcessId: 2, triggeringProcessImageFileName: "UnitTest").ShouldEqual(NtStatus.Pending); mockGvFlt.WaitForCompletionStatus().ShouldEqual(mockGvFlt.WriteFileReturnStatus); callbacks.Stop(); } }
public void OnGetFileStreamReturnsPendingAndCompletesWithSuccessWhenNoFailures() { using (MockVirtualizationInstance mockGvFlt = new MockVirtualizationInstance()) using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { "test.txt" })) { GVFltCallbacks callbacks = new GVFltCallbacks( this.Repo.Context, this.Repo.GitObjects, RepoMetadata.Instance, new MockBlobSizes(), gvflt: mockGvFlt, gitIndexProjection: gitIndexProjection, reliableBackgroundOperations: new MockReliableBackgroundOperations()); string error; callbacks.TryStart(out error).ShouldEqual(true); Guid enumerationGuid = Guid.NewGuid(); byte[] contentId = GVFltCallbacks.ConvertShaToContentId("0123456789012345678901234567890123456789"); byte[] placeholderVersion = GVFltCallbacks.GetPlaceholderVersionId(); uint fileLength = 100; MockGVFSGitObjects mockGVFSGitObjects = this.Repo.GitObjects as MockGVFSGitObjects; mockGVFSGitObjects.FileLength = fileLength; mockGvFlt.WriteFileReturnResult = HResult.Ok; mockGvFlt.OnGetFileStream( commandId: 1, relativePath: "test.txt", byteOffset: 0, length: fileLength, streamGuid: Guid.NewGuid(), contentId: contentId, providerId: placeholderVersion, triggeringProcessId: 2, triggeringProcessImageFileName: "UnitTest").ShouldEqual(HResult.Pending); mockGvFlt.WaitForCompletionStatus().ShouldEqual(HResult.Ok); callbacks.Stop(); } }
public void GetPlaceholderInformationHandlerPathNotProjected() { using (MockVirtualizationInstance mockGvFlt = new MockVirtualizationInstance()) using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { "test.txt" })) { GVFltCallbacks callbacks = new GVFltCallbacks( this.Repo.Context, this.Repo.GitObjects, RepoMetadata.Instance, blobSizes: null, gvflt: mockGvFlt, gitIndexProjection: gitIndexProjection, reliableBackgroundOperations: new MockReliableBackgroundOperations()); string error; callbacks.TryStart(out error).ShouldEqual(true); mockGvFlt.OnGetPlaceholderInformation(1, "doesNotExist", 0, 0, 0, 0, 1, "UnitTests").ShouldEqual(NtStatus.ObjectNameNotFound); } }
public void OnGetFileStreamReturnsErrorWhenWriteFileContentsFails() { const string TestFileName = "test.txt"; using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner()) using (MockVirtualizationInstance mockVirtualization = new MockVirtualizationInstance()) using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { TestFileName })) using (MacFileSystemVirtualizer virtualizer = new MacFileSystemVirtualizer(this.Repo.Context, this.Repo.GitObjects, mockVirtualization)) using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks( this.Repo.Context, this.Repo.GitObjects, RepoMetadata.Instance, new MockBlobSizes(), gitIndexProjection, backgroundFileSystemTaskRunner: backgroundTaskRunner, fileSystemVirtualizer: virtualizer)) { string error; fileSystemCallbacks.TryStart(out error).ShouldEqual(true); byte[] contentId = FileSystemVirtualizer.ConvertShaToContentId("0123456789012345678901234567890123456789"); byte[] placeholderVersion = MacFileSystemVirtualizer.PlaceholderVersionId; uint fileLength = 100; MockGVFSGitObjects mockGVFSGitObjects = this.Repo.GitObjects as MockGVFSGitObjects; mockGVFSGitObjects.FileLength = fileLength; mockVirtualization.WriteFileReturnResult = Result.EIOError; mockVirtualization.OnGetFileStream( commandId: 1, relativePath: TestFileName, providerId: placeholderVersion, contentId: contentId, triggeringProcessId: 2, triggeringProcessName: "UnitTest", fileHandle: IntPtr.Zero).ShouldEqual(Result.EIOError); fileSystemCallbacks.Stop(); } }
public void GetPlaceholderInformationHandlerCancelledBeforeSchedulingAsync() { using (MockVirtualizationInstance mockGvFlt = new MockVirtualizationInstance()) using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { "test.txt" })) { GVFltCallbacks callbacks = new GVFltCallbacks( this.Repo.Context, this.Repo.GitObjects, RepoMetadata.Instance, new MockBlobSizes(), gvflt: mockGvFlt, gitIndexProjection: gitIndexProjection, reliableBackgroundOperations: new MockReliableBackgroundOperations()); string error; callbacks.TryStart(out error).ShouldEqual(true); gitIndexProjection.BlockIsPathProjected(willWaitForRequest: true); Task.Run(() => { // Wait for OnGetPlaceholderInformation to call IsPathProjected and then while it's blocked there // call OnCancelCommand gitIndexProjection.WaitForIsPathProjected(); mockGvFlt.OnCancelCommand(1); gitIndexProjection.UnblockIsPathProjected(); }); mockGvFlt.OnGetPlaceholderInformation(1, "test.txt", 0, 0, 0, 0, 1, "UnitTests").ShouldEqual(HResult.Pending); // Cancelling before GetPlaceholderInformation has registered the command results in placeholders being created mockGvFlt.WaitForPlaceholderCreate(); gitIndexProjection.WaitForPlaceholderCreate(); mockGvFlt.CreatedPlaceholders.ShouldContain(entry => entry == "test.txt"); gitIndexProjection.PlaceholdersCreated.ShouldContain(entry => entry == "test.txt"); callbacks.Stop(); } }
public void OnEnumerateDirectoryReturnsSuccessWhenResultsInMemory() { const string TestFileName = "test.txt"; const string TestFolderName = "testFolder"; string testFilePath = Path.Combine(TestFolderName, TestFileName); using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner()) using (MockVirtualizationInstance mockVirtualization = new MockVirtualizationInstance()) // Don't include TestFolderName as MockGitIndexProjection returns the same list of files regardless of what folder name // it is passed using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { TestFileName })) using (MacFileSystemVirtualizer virtualizer = new MacFileSystemVirtualizer(this.Repo.Context, this.Repo.GitObjects, mockVirtualization)) using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks( this.Repo.Context, this.Repo.GitObjects, RepoMetadata.Instance, new MockBlobSizes(), gitIndexProjection, backgroundFileSystemTaskRunner: backgroundTaskRunner, fileSystemVirtualizer: virtualizer)) { gitIndexProjection.MockFileTypesAndModes.TryAdd( testFilePath, ConvertFileTypeAndModeToIndexFormat(GitIndexProjection.FileType.Regular, GitIndexProjection.FileMode644)); string error; fileSystemCallbacks.TryStart(out error).ShouldEqual(true); Guid enumerationGuid = Guid.NewGuid(); gitIndexProjection.EnumerationInMemory = true; mockVirtualization.OnEnumerateDirectory(1, TestFolderName, triggeringProcessId: 1, triggeringProcessName: "UnitTests").ShouldEqual(Result.Success); mockVirtualization.CreatedPlaceholders.ShouldContain( kvp => kvp.Key.Equals(testFilePath, StringComparison.OrdinalIgnoreCase) && kvp.Value == GitIndexProjection.FileMode644); gitIndexProjection.ExpandedFolders.ShouldMatchInOrder(TestFolderName); fileSystemCallbacks.Stop(); } }
public void OnStartDirectoryEnumerationReturnsSuccessWhenResultsInMemory() { using (MockVirtualizationInstance mockGvFlt = new MockVirtualizationInstance()) using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { "test" })) { GVFltCallbacks callbacks = new GVFltCallbacks( this.Repo.Context, this.Repo.GitObjects, RepoMetadata.Instance, blobSizes: null, gvflt: mockGvFlt, gitIndexProjection: gitIndexProjection, reliableBackgroundOperations: new MockReliableBackgroundOperations()); string error; callbacks.TryStart(out error).ShouldEqual(true); Guid enumerationGuid = Guid.NewGuid(); gitIndexProjection.EnumerationInMemory = true; mockGvFlt.OnStartDirectoryEnumeration(1, enumerationGuid, "test").ShouldEqual(NtStatus.Success); mockGvFlt.OnEndDirectoryEnumeration(enumerationGuid).ShouldEqual(NtStatus.Success); } }
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(); } }
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(); } }
public void UpdatePlaceholderIfNeeded() { using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner()) using (MockVirtualizationInstance mockVirtualization = new MockVirtualizationInstance()) using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { "test.txt" })) using (MacFileSystemVirtualizer virtualizer = new MacFileSystemVirtualizer(this.Repo.Context, this.Repo.GitObjects, mockVirtualization)) using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks( this.Repo.Context, this.Repo.GitObjects, RepoMetadata.Instance, new MockBlobSizes(), gitIndexProjection, backgroundTaskRunner, virtualizer)) { gitIndexProjection.MockFileModes.TryAdd("test" + Path.DirectorySeparatorChar + "test.txt", FileMode644); string error; fileSystemCallbacks.TryStart(out error).ShouldEqual(true); UpdateFailureReason failureReason = UpdateFailureReason.NoFailure; mockVirtualization.UpdatePlaceholderIfNeededResult = Result.Success; mockVirtualization.UpdatePlaceholderIfNeededFailureCause = UpdateFailureCause.NoFailure; virtualizer .UpdatePlaceholderIfNeeded( "test.txt", DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, 0, 15, string.Empty, UpdatePlaceholderType.AllowReadOnly, out failureReason) .ShouldEqual(new FileSystemResult(FSResult.Ok, (int)mockVirtualization.UpdatePlaceholderIfNeededResult)); failureReason.ShouldEqual((UpdateFailureReason)mockVirtualization.UpdatePlaceholderIfNeededFailureCause); mockVirtualization.UpdatePlaceholderIfNeededResult = Result.EFileNotFound; mockVirtualization.UpdatePlaceholderIfNeededFailureCause = UpdateFailureCause.NoFailure; virtualizer .UpdatePlaceholderIfNeeded( "test.txt", DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, 0, 15, string.Empty, UpdatePlaceholderType.AllowReadOnly, out failureReason) .ShouldEqual(new FileSystemResult(FSResult.FileOrPathNotFound, (int)mockVirtualization.UpdatePlaceholderIfNeededResult)); failureReason.ShouldEqual((UpdateFailureReason)mockVirtualization.UpdatePlaceholderIfNeededFailureCause); // TODO: What will the result be when the UpdateFailureCause is DirtyData mockVirtualization.UpdatePlaceholderIfNeededResult = Result.EInvalidOperation; mockVirtualization.UpdatePlaceholderIfNeededFailureCause = UpdateFailureCause.DirtyData; // TODO: The result should probably be VirtualizationInvalidOperation but for now it's IOError virtualizer .UpdatePlaceholderIfNeeded( "test.txt", DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, 0, 15, string.Empty, UpdatePlaceholderType.AllowReadOnly, out failureReason) .ShouldEqual(new FileSystemResult(FSResult.IOError, (int)mockVirtualization.UpdatePlaceholderIfNeededResult)); failureReason.ShouldEqual((UpdateFailureReason)mockVirtualization.UpdatePlaceholderIfNeededFailureCause); fileSystemCallbacks.Stop(); } }
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(); }
public void UpdatePlaceholderIfNeeded() { const string UpdatePlaceholderFileName = "testUpdatePlaceholder.txt"; using (MockBackgroundFileSystemTaskRunner backgroundTaskRunner = new MockBackgroundFileSystemTaskRunner()) using (MockVirtualizationInstance mockVirtualization = new MockVirtualizationInstance()) using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { UpdatePlaceholderFileName })) using (MacFileSystemVirtualizer virtualizer = new MacFileSystemVirtualizer(this.Repo.Context, this.Repo.GitObjects, mockVirtualization)) using (FileSystemCallbacks fileSystemCallbacks = new FileSystemCallbacks( this.Repo.Context, this.Repo.GitObjects, RepoMetadata.Instance, new MockBlobSizes(), gitIndexProjection, backgroundTaskRunner, virtualizer)) { gitIndexProjection.MockFileTypesAndModes.TryAdd( UpdatePlaceholderFileName, ConvertFileTypeAndModeToIndexFormat(GitIndexProjection.FileType.Regular, GitIndexProjection.FileMode644)); string error; fileSystemCallbacks.TryStart(out error).ShouldEqual(true); UpdateFailureReason failureReason = UpdateFailureReason.NoFailure; mockVirtualization.UpdatePlaceholderIfNeededResult = Result.Success; mockVirtualization.UpdatePlaceholderIfNeededFailureCause = UpdateFailureCause.NoFailure; virtualizer .UpdatePlaceholderIfNeeded( UpdatePlaceholderFileName, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, 0, 15, string.Empty, UpdatePlaceholderType.AllowReadOnly, out failureReason) .ShouldEqual(new FileSystemResult(FSResult.Ok, (int)mockVirtualization.UpdatePlaceholderIfNeededResult)); failureReason.ShouldEqual((UpdateFailureReason)mockVirtualization.UpdatePlaceholderIfNeededFailureCause); mockVirtualization.UpdatedPlaceholders.ShouldContain(path => path.Key.Equals(UpdatePlaceholderFileName) && path.Value == GitIndexProjection.FileMode644); mockVirtualization.UpdatedPlaceholders.Clear(); mockVirtualization.UpdatePlaceholderIfNeededResult = Result.EFileNotFound; mockVirtualization.UpdatePlaceholderIfNeededFailureCause = UpdateFailureCause.NoFailure; virtualizer .UpdatePlaceholderIfNeeded( UpdatePlaceholderFileName, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, 0, 15, string.Empty, UpdatePlaceholderType.AllowReadOnly, out failureReason) .ShouldEqual(new FileSystemResult(FSResult.FileOrPathNotFound, (int)mockVirtualization.UpdatePlaceholderIfNeededResult)); failureReason.ShouldEqual((UpdateFailureReason)mockVirtualization.UpdatePlaceholderIfNeededFailureCause); // TODO: What will the result be when the UpdateFailureCause is DirtyData mockVirtualization.UpdatePlaceholderIfNeededResult = Result.EInvalidOperation; mockVirtualization.UpdatePlaceholderIfNeededFailureCause = UpdateFailureCause.DirtyData; // TODO: The result should probably be VirtualizationInvalidOperation but for now it's IOError virtualizer .UpdatePlaceholderIfNeeded( UpdatePlaceholderFileName, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, 0, 15, string.Empty, UpdatePlaceholderType.AllowReadOnly, out failureReason) .ShouldEqual(new FileSystemResult(FSResult.IOError, (int)mockVirtualization.UpdatePlaceholderIfNeededResult)); failureReason.ShouldEqual((UpdateFailureReason)mockVirtualization.UpdatePlaceholderIfNeededFailureCause); fileSystemCallbacks.Stop(); } }