public async Task QuickEnumeration_SmallBuffer_MultiFile_Successful() { //Arrange const string RootPath = @"D:\"; var functions = new Mock <Functions>(); var nsVirtualizationContext = (IntPtr)4; var instanceGuid = Guid.NewGuid(); var tcsStarted = new TaskCompletionSource <IntPtr>(); var enumerationId = Guid.NewGuid(); var callbackData = new PRJ_CALLBACK_DATA { VersionInfo = new PRJ_PLACEHOLDER_VERSION_INFO() }; var dirBuffer1 = (IntPtr)99; var dirBuffer2 = (IntPtr)713; functions.Setup(f => f.PrjStartVirtualizing(RootPath, It.IsAny <IntPtr>(), IntPtr.Zero, It.IsAny <PRJ_STARTVIRTUALIZING_OPTIONS>(), out It.Ref <IntPtr> .IsAny)) .Callback(new StartVirtualizingCallback((String virtualizationRootPath, IntPtr callbacks, IntPtr instanceContext, PRJ_STARTVIRTUALIZING_OPTIONS options, out IntPtr namespaceVirtualizationContext) => { tcsStarted.SetResult(callbacks); namespaceVirtualizationContext = nsVirtualizationContext; }) ).Returns(() => HRESULT.S_OK); functions.Setup(f => f.PrjFileNameMatch(It.IsAny <string>(), null)).Returns(true); functions.SetupSequence(f => f.PrjFillDirEntryBuffer("Boris.txt", It.IsAny <PRJ_FILE_BASIC_INFO>(), dirBuffer1)) .Returns(HRESULT.S_OK) .Returns(HRESULT.ERROR_INSUFFICIENT_BUFFER) .Returns(HRESULT.S_OK); ConfigureVirtualizationInfo(functions, nsVirtualizationContext, instanceGuid); var runnable = new RunnableInstance("Boris", RootPath, instanceGuid, new InstanceOptions(), functions.Object); var fs = TestableFileSystem.MultiFile(); //Act using (var running = runnable.Start(fs)) { var callbacks = NativeBuffer <PRJ_CALLBACKS> .Recover(await tcsStarted.Task); var hr = callbacks.StartDirectoryEnumerationCallback(callbackData, enumerationId); Assert.Equal(HRESULT.S_OK, hr); hr = callbacks.GetDirectoryEnumerationCallback(callbackData, enumerationId, null, dirBuffer1); Assert.Equal(HRESULT.S_OK, hr); hr = callbacks.GetDirectoryEnumerationCallback(callbackData, enumerationId, null, dirBuffer2); Assert.Equal(HRESULT.S_OK, hr); hr = callbacks.EndDirectoryEnumerationCallback(callbackData, enumerationId); Assert.Equal(HRESULT.S_OK, hr); //Assert functions.VerifyAll(); } }
public void Can_Roundtrip_Simple_Structure() { //Arrange var input = new SimpleClass { First = 1234567, Second = 987654 }; //Act using (var nb = new NativeBuffer <SimpleClass>(input)) { var output = NativeBuffer <SimpleClass> .Recover(nb.Buffer); //Assert Assert.NotSame(input, output); Assert.Equal(input.First, output.First); Assert.Equal(input.Second, output.Second); } }