Exemple #1
0
        public void OnGetFileStreamReturnsInvalidParameterWhenOffsetNonZero()
        {
            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();

                    mockGvFlt.OnGetFileStream(
                        commandId: 1,
                        relativePath: "test.txt",
                        byteOffset: 10,
                        length: 100,
                        streamGuid: Guid.NewGuid(),
                        contentId: contentId,
                        epochId: epochId,
                        triggeringProcessId: 2,
                        triggeringProcessImageFileName: "UnitTest").ShouldEqual(NtStatus.InvalidParameter);
                }
        }
        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,
                        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.BlockCreateWriteBuffer(willWaitForRequest: true);
                    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.WaitForCreateWriteBuffer();
                    mockGvFlt.OnCancelCommand(1);
                    mockGvFlt.UnblockCreateWriteBuffer();
                    mockTracker.WaitForRelatedEvent();

                    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,
                        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;
                    mockGvFlt.WriteFileReturnStatus = NtStatus.Success;

                    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(NtStatus.Success);

                    callbacks.Stop();
                }
        }