/// <inheritdoc /> public void Establish(SCardScope scope) { if (_contextPtr != IntPtr.Zero && IsValid()) { Release(); } var rc = _api.EstablishContext( scope, IntPtr.Zero, IntPtr.Zero, out var hContext); switch (rc) { case SCardError.Success: _contextPtr = hContext; _lastScope = scope; break; case SCardError.InvalidValue: throw new InvalidScopeTypeException(rc, "Invalid scope type passed"); 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); }