/// <inheritdoc /> public void Release() { if (_contextPtr == IntPtr.Zero) { throw new InvalidContextException(SCardError.UnknownError, "Context was not established"); } var rc = _api.ReleaseContext(_contextPtr); switch (rc) { case SCardError.Success: _contextPtr = IntPtr.Zero; break; case SCardError.InvalidHandle: throw new InvalidContextException(rc, "Invalid Context handle"); case SCardError.InvalidHandleWindows: throw new InvalidContextException(rc, "Invalid Context handle"); default: rc.Throw(); break; } }
protected SCardContextSpec() { IntPtr handle; // allow SCardContext.Establish() for all tests A.CallTo(() => Api.EstablishContext( A <SCardScope> .Ignored, A <IntPtr> .Ignored, A <IntPtr> .Ignored, out handle)) .WithAnyArguments() .Returns(SCardError.Success) .AssignsOutAndRefParametersLazily(_ => new object[] { ContextHandle }); // allow SCardContext.Release() for all tests A.CallTo(() => Api.ReleaseContext(ContextHandle)) .Returns(SCardError.Success); Sut = new SCardContext(Api); }