private async Task SignIn(ClientType clientType)
        {
            if (this.oneDriveClient == null)
            {
                this.oneDriveClient = clientType == ClientType.Consumer
                    ? OneDriveClient.GetMicrosoftAccountClient(
                    FormBrowser.MsaClientId,
                    FormBrowser.MsaReturnUrl,
                    FormBrowser.Scopes,
                    webAuthenticationUi: new FormsWebAuthenticationUi())
                    : BusinessClientExtensions.GetClient(
                    new BusinessAppConfig
                {
                    ActiveDirectoryAppId     = FormBrowser.AadClientId,
                    ActiveDirectoryReturnUrl = FormBrowser.AadReturnUrl,
                });
            }

            try
            {
                if (!this.oneDriveClient.IsAuthenticated)
                {
                    await this.oneDriveClient.AuthenticateAsync();
                }

                await LoadFolderFromPath();

                UpdateConnectedStateUx(true);
            }
            catch (OneDriveException exception)
            {
                // Swallow authentication cancelled exceptions, but reset the client
                if (!exception.IsMatch(OneDriveErrorCode.AuthenticationCancelled.ToString()))
                {
                    if (exception.IsMatch(OneDriveErrorCode.AuthenticationFailure.ToString()))
                    {
                        MessageBox.Show(
                            "Authentication failed",
                            "Authentication failed",
                            MessageBoxButtons.OK);

                        ((OneDriveClient)this.oneDriveClient).Dispose();
                        this.oneDriveClient = null;
                    }
                    else
                    {
                        PresentOneDriveException(exception);
                    }
                }
                else
                {
                    ((OneDriveClient)this.oneDriveClient).Dispose();
                    this.oneDriveClient = null;
                }
            }
        }
        public void GetClient()
        {
            var appId     = "appId";
            var returnUrl = "returnUrl";
            var userId    = "userId";

            var client = BusinessClientExtensions.GetClient(
                new BusinessAppConfig
            {
                ActiveDirectoryAppId           = appId,
                ActiveDirectoryReturnUrl       = returnUrl,
                ActiveDirectoryServiceResource = serviceResourceId,
            },
                userId,
                this.credentialCache.Object,
                this.httpProvider.Object) as OneDriveClient;

            var clientServiceInfoProvider = client.serviceInfoProvider as ServiceInfoProvider;

            Assert.IsNotNull(clientServiceInfoProvider, "Unexpected service info provider initialized for client.");
            Assert.AreEqual(userId, clientServiceInfoProvider.UserSignInName, "Unexpected user sign-in name set.");
            Assert.AreEqual(this.httpProvider.Object, client.HttpProvider, "Unexpected HTTP provider set.");
            Assert.AreEqual(this.credentialCache.Object, client.credentialCache, "Unexpected credential cache set.");
        }