public void VerifyStatusCallbackWrapperConvertsArguments() { var wrapper = new StatusCallbackWrapper( (session, snp, snt, obj) => { Assert.IsInstanceOfType(obj, typeof(JET_SNPROG)); var snprog = obj as JET_SNPROG; Assert.AreEqual(this.sesid, session); Assert.AreEqual(JET_SNP.Restore, snp); Assert.AreEqual(JET_SNT.Progress, snt); Assert.IsNotNull(snprog); Assert.AreEqual(1, snprog.cunitDone); Assert.AreEqual(100, snprog.cunitTotal); return(JET_err.Success); }); var native = new NATIVE_SNPROG { cbStruct = checked ((uint)NATIVE_SNPROG.Size), cunitDone = 1, cunitTotal = 100, }; unsafe { wrapper.NativeCallback( this.sesid.Value, (uint)JET_SNP.Restore, (uint)JET_SNT.Progress, new IntPtr(&native)); } wrapper.ThrowSavedException(); }
public void VerifyStatusCallbackWrapperCatchesExceptions() { var wrapper = new StatusCallbackWrapper( (session, snp, snt, snprog) => { throw new ArgumentException(); }); Assert.AreEqual(JET_err.CallbackFailed, wrapper.NativeCallback(this.sesid.Value, 0, 0, IntPtr.Zero)); try { wrapper.ThrowSavedException(); Assert.Fail("Expected an ArgumentException to be thrown"); } catch (ArgumentException) { // expected } }
public void VerifyStatusCallbackWrapperCatchesThreadAbort() { var wrapper = new StatusCallbackWrapper( (session, snp, snt, snprog) => { Thread.CurrentThread.Abort(); return(JET_err.Success); }); Assert.AreEqual(JET_err.CallbackFailed, wrapper.NativeCallback(this.sesid.Value, 0, 0, IntPtr.Zero)); try { wrapper.ThrowSavedException(); Assert.Fail("Expected a ThreadAbortException to be thrown"); } catch (ThreadAbortException) { // expected LibraryHelpers.ThreadResetAbort(); } }