public void DeleteFile()
        {
            using (MockVirtualizationInstance mockVirtualization = new MockVirtualizationInstance())
                using (MacFileSystemVirtualizer virtualizer = new MacFileSystemVirtualizer(this.Repo.Context, this.Repo.GitObjects, mockVirtualization))
                {
                    const string        DeleteTestFileName = "deleteMe.txt";
                    UpdateFailureReason failureReason      = UpdateFailureReason.NoFailure;

                    mockVirtualization.DeleteFileResult             = Result.Success;
                    mockVirtualization.DeleteFileUpdateFailureCause = UpdateFailureCause.NoFailure;
                    virtualizer
                    .DeleteFile(DeleteTestFileName, UpdatePlaceholderType.AllowReadOnly, out failureReason)
                    .ShouldEqual(new FileSystemResult(FSResult.Ok, (int)mockVirtualization.DeleteFileResult));
                    failureReason.ShouldEqual((UpdateFailureReason)mockVirtualization.DeleteFileUpdateFailureCause);

                    mockVirtualization.DeleteFileResult             = Result.EFileNotFound;
                    mockVirtualization.DeleteFileUpdateFailureCause = UpdateFailureCause.NoFailure;
                    virtualizer
                    .DeleteFile(DeleteTestFileName, UpdatePlaceholderType.AllowReadOnly, out failureReason)
                    .ShouldEqual(new FileSystemResult(FSResult.FileOrPathNotFound, (int)mockVirtualization.DeleteFileResult));
                    failureReason.ShouldEqual((UpdateFailureReason)mockVirtualization.DeleteFileUpdateFailureCause);

                    // TODO: What will the result be when the UpdateFailureCause is DirtyData
                    mockVirtualization.DeleteFileResult = Result.EInvalidOperation;

                    // TODO: The result should probably be VirtualizationInvalidOperation but for now it's IOError
                    mockVirtualization.DeleteFileUpdateFailureCause = UpdateFailureCause.DirtyData;
                    virtualizer
                    .DeleteFile(DeleteTestFileName, UpdatePlaceholderType.AllowReadOnly, out failureReason)
                    .ShouldEqual(new FileSystemResult(FSResult.IOError, (int)mockVirtualization.DeleteFileResult));
                    failureReason.ShouldEqual((UpdateFailureReason)mockVirtualization.DeleteFileUpdateFailureCause);
                }
        }
        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();
                            }
        }
Esempio n. 3
0
        public void DeleteFile()
        {
            using (MockVirtualizationInstance mockVirtualization = new MockVirtualizationInstance())
                using (WindowsFileSystemVirtualizer virtualizer = new WindowsFileSystemVirtualizer(this.Repo.Context, this.Repo.GitObjects, mockVirtualization, numWorkThreads))
                {
                    UpdateFailureReason failureReason = UpdateFailureReason.NoFailure;

                    mockVirtualization.DeleteFileResult             = HResult.Ok;
                    mockVirtualization.DeleteFileUpdateFailureCause = UpdateFailureCause.NoFailure;
                    virtualizer
                    .DeleteFile("test.txt", UpdatePlaceholderType.AllowReadOnly, out failureReason)
                    .ShouldEqual(new FileSystemResult(FSResult.Ok, (int)mockVirtualization.DeleteFileResult));
                    failureReason.ShouldEqual((UpdateFailureReason)mockVirtualization.DeleteFileUpdateFailureCause);

                    mockVirtualization.DeleteFileResult             = HResult.FileNotFound;
                    mockVirtualization.DeleteFileUpdateFailureCause = UpdateFailureCause.NoFailure;
                    virtualizer
                    .DeleteFile("test.txt", UpdatePlaceholderType.AllowReadOnly, out failureReason)
                    .ShouldEqual(new FileSystemResult(FSResult.FileOrPathNotFound, (int)mockVirtualization.DeleteFileResult));
                    failureReason.ShouldEqual((UpdateFailureReason)mockVirtualization.DeleteFileUpdateFailureCause);

                    mockVirtualization.DeleteFileResult             = HResult.VirtualizationInvalidOp;
                    mockVirtualization.DeleteFileUpdateFailureCause = UpdateFailureCause.DirtyData;
                    virtualizer
                    .DeleteFile("test.txt", UpdatePlaceholderType.AllowReadOnly, out failureReason)
                    .ShouldEqual(new FileSystemResult(FSResult.VirtualizationInvalidOperation, (int)mockVirtualization.DeleteFileResult));
                    failureReason.ShouldEqual((UpdateFailureReason)mockVirtualization.DeleteFileUpdateFailureCause);
                }
        }
Esempio n. 4
0
        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();
                }
        }
Esempio n. 5
0
        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();
                }
        }
Esempio n. 6
0
        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 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();
        }
Esempio n. 8
0
        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);
                }
        }
Esempio n. 9
0
        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 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 ClearNegativePathCacheIsNoOp()
 {
     using (MockVirtualizationInstance mockVirtualization = new MockVirtualizationInstance())
         using (MacFileSystemVirtualizer virtualizer = new MacFileSystemVirtualizer(this.Repo.Context, this.Repo.GitObjects, mockVirtualization))
         {
             uint totalEntryCount = 0;
             virtualizer.ClearNegativePathCache(out totalEntryCount).ShouldEqual(new FileSystemResult(FSResult.Ok, (int)Result.Success));
             totalEntryCount.ShouldEqual(0U);
         }
 }
        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();
        }
Esempio n. 13
0
        public void ClearNegativePathCache()
        {
            const uint InitialNegativePathCacheCount = 7;

            using (MockVirtualizationInstance mockVirtualization = new MockVirtualizationInstance())
                using (WindowsFileSystemVirtualizer virtualizer = new WindowsFileSystemVirtualizer(this.Repo.Context, this.Repo.GitObjects, mockVirtualization, numWorkThreads))
                {
                    mockVirtualization.NegativePathCacheCount = InitialNegativePathCacheCount;

                    uint totalEntryCount;
                    virtualizer.ClearNegativePathCache(out totalEntryCount).ShouldEqual(new FileSystemResult(FSResult.Ok, (int)HResult.Ok));
                    totalEntryCount.ShouldEqual(InitialNegativePathCacheCount);
                }
        }
        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();
        }
Esempio n. 15
0
        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();
                }
        }
Esempio n. 17
0
        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();
                }
        }
Esempio n. 18
0
        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);
                }
        }
Esempio n. 19
0
        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();
                            }
        }
Esempio n. 20
0
        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();
                }
        }
Esempio n. 21
0
        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();
                            }
        }
Esempio n. 22
0
        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);
                }
        }
Esempio n. 23
0
        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();
                            }
        }
        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 UpdatePlaceholderIfNeeded()
        {
            using (MockVirtualizationInstance mockVirtualization = new MockVirtualizationInstance())
                using (MacFileSystemVirtualizer virtualizer = new MacFileSystemVirtualizer(this.Repo.Context, this.Repo.GitObjects, mockVirtualization))
                {
                    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);
                }
        }