internal Auth GetAuthAsync()
        {
            var storage   = DataVault.GetConfigurationStorage();
            var mEndpoint = new Mock <IKeeperEndpoint>();

            mEndpoint.SetupGet(e => e.ClientVersion)
            .Returns(DataVault.TestClientVersion);
            mEndpoint.SetupGet(e => e.DeviceName)
            .Returns(".NET Unit Tests");
            mEndpoint.SetupProperty(e => e.Server);
            mEndpoint.Object.Server = DataVault.DefaultEnvironment;

            var webSocket = new TestWebSocket();

            mEndpoint.Setup(x => x.ConnectToPushServer(It.IsAny <WssConnectionRequest>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <IFanOut <NotificationEvent> >(webSocket));

            var mUi = new Mock <IAuthUI>();

            var mAuth = new Mock <Auth>(mUi.Object, storage, mEndpoint.Object)
            {
                CallBase = true
            };

            mAuth.Setup(m => m.PingKeeperServer(It.IsAny <Uri>(), It.IsAny <IWebProxy>()))
            .Returns(Task.FromResult(true));

            var auth = mAuth.Object;

            mEndpoint.Setup(e => e.ExecuteRest(
                                It.IsAny <string>(),
                                It.IsAny <ApiRequestPayload>()))
            .Returns((string endpoint, ApiRequestPayload payload) => MockExecuteRest(endpoint, payload, auth));

            mUi.Setup(x => x.WaitForDeviceApproval(It.IsAny <IDeviceApprovalChannelInfo[]>(), It.IsAny <CancellationToken>()))
            .Returns((IDeviceApprovalChannelInfo[] x, CancellationToken y) => Task.FromResult(false));

            mUi.Setup(x => x.WaitForUserPassword(It.IsAny <IPasswordInfo>(), It.IsAny <CancellationToken>()))
            .Returns((IPasswordInfo info, CancellationToken token) => Task.FromResult(false));

            mUi.Setup(x => x.WaitForTwoFactorCode(It.IsAny <ITwoFactorChannelInfo[]>(), It.IsAny <CancellationToken>()))
            .Callback((ITwoFactorChannelInfo[] info, CancellationToken token) => Task.FromResult(false));
            return(auth);
        }
Exemplo n.º 2
0
        private AuthSync GetAuthSync()
        {
            var storage   = DataVault.GetConfigurationStorage();
            var mEndpoint = new Mock <IKeeperEndpoint>();

            mEndpoint.SetupGet(e => e.ClientVersion)
            .Returns(DataVault.TestClientVersion);
            mEndpoint.SetupGet(e => e.DeviceName)
            .Returns(".NET Unit Tests");
            mEndpoint.SetupGet(e => e.ServerKeyId)
            .Returns(1);
            mEndpoint.SetupProperty(e => e.Server);
            mEndpoint.Object.Server = DataVault.DefaultEnvironment;

            var webSocket = new TestWebSocket();

            mEndpoint.Setup(x => x.ConnectToPushServer(It.IsAny <WssConnectionRequest>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <IFanOut <NotificationEvent> >(webSocket));

            var mFlow = new Mock <AuthSync>(storage, mEndpoint.Object)
            {
                CallBase = true
            };

            mFlow.Setup(m => m.PingKeeperServer(It.IsAny <Uri>(), It.IsAny <IWebProxy>()))
            .Returns(Task.FromResult(true));
            var flow = mFlow.Object;

            mEndpoint.Setup(e => e.ExecuteRest(
                                It.IsAny <string>(),
                                It.IsAny <ApiRequestPayload>()))
            .Returns((string endpoint, ApiRequestPayload payload) => MockExecuteRest(endpoint, payload, flow));

            flow.UiCallback = new AuthSyncCallback();
            return(flow);
        }