public async Task TestAcquireTokenInteractiveBuilderAsync()
        {
            await AcquireTokenInteractiveParameterBuilder.Create(_harness.Executor, MsalTestConstants.Scope)
            .ExecuteAsync()
            .ConfigureAwait(false);

            _harness.ValidateCommonParameters(ApiEvent.ApiIds.AcquireTokenInteractive);
            _harness.ValidateInteractiveParameters();
        }
        public async Task TestAcquireTokenInteractiveBuilderWithLoginHintAsync()
        {
            await AcquireTokenInteractiveParameterBuilder.Create(_harness.Executor, MsalTestConstants.Scope)
            .WithLoginHint(MsalTestConstants.DisplayableId)
            .ExecuteAsync()
            .ConfigureAwait(false);

            _harness.ValidateCommonParameters(ApiEvent.ApiIds.AcquireTokenInteractive);
            _harness.ValidateInteractiveParameters(expectedLoginHint: MsalTestConstants.DisplayableId);
        }
        public async Task TestAcquireTokenInteractive_Embedded_Async()
        {
            await AcquireTokenInteractiveParameterBuilder.Create(_harness.Executor, MsalTestConstants.Scope)
            .WithUseEmbeddedWebView(true)
            .ExecuteAsync()
            .ConfigureAwait(false);

            _harness.ValidateCommonParameters(ApiEvent.ApiIds.AcquireTokenInteractive);
            _harness.ValidateInteractiveParameters(expectedEmbeddedWebView: WebViewPreference.Embedded);
        }
        public async Task TestAcquireTokenInteractive_EmbeddedNetCore_Async()
        {
            var ex = await AssertException.TaskThrowsAsync <MsalClientException>(() =>
                                                                                 AcquireTokenInteractiveParameterBuilder.Create(_harness.Executor, TestConstants.s_scope)
                                                                                 .WithUseEmbeddedWebView(true)
                                                                                 .ExecuteAsync()
                                                                                 ).ConfigureAwait(false);

            Assert.AreEqual(MsalError.WebviewUnavailable, ex.ErrorCode);
        }
        public async Task TestAcquireTokenInteractive_ParentWindow_WithCallbackFunc_Async()
        {
            IntPtr parentWindowIntPtr = new IntPtr(12345);

            await AcquireTokenInteractiveParameterBuilder.Create(_harness.Executor, MsalTestConstants.Scope)
            .WithParentActivityOrWindowFunc(() => parentWindowIntPtr)
            .ExecuteAsync()
            .ConfigureAwait(false);

            Assert.AreEqual(parentWindowIntPtr, _harness.InteractiveParametersReceived.UiParent.OwnerWindow);
        }
        public async Task TestAcquireTokenInteractive_SystemWebview_Async()
        {
            var customWebUi = Substitute.For <ICustomWebUi>();

            await AcquireTokenInteractiveParameterBuilder.Create(_harness.Executor, MsalTestConstants.Scope)
            .WithUseEmbeddedWebView(false)
            .ExecuteAsync()
            .ConfigureAwait(false);

            _harness.ValidateCommonParameters(ApiEvent.ApiIds.AcquireTokenInteractive);
            _harness.ValidateInteractiveParameters(expectedEmbeddedWebView: WebViewPreference.System);
        }
        public async Task TestAcquireTokenInteractiveBuilderWithCustomWebUiAsync()
        {
            var customWebUi = Substitute.For <ICustomWebUi>();

            await AcquireTokenInteractiveParameterBuilder.Create(_harness.Executor, MsalTestConstants.Scope)
            .WithCustomWebUi(customWebUi)
            .ExecuteAsync()
            .ConfigureAwait(false);

            _harness.ValidateCommonParameters(ApiEvent.ApiIds.AcquireTokenInteractive);
            _harness.ValidateInteractiveParameters(expectedCustomWebUi: customWebUi);
        }
        public async Task TestAcquireTokenInteractive_Options_Async()
        {
            var options = new SystemWebViewOptions();
            await AcquireTokenInteractiveParameterBuilder.Create(_harness.Executor, MsalTestConstants.Scope)
            .WithSystemWebViewOptions(options)
            .ExecuteAsync()
            .ConfigureAwait(false);

            _harness.ValidateCommonParameters(ApiEvent.ApiIds.AcquireTokenInteractive);
            _harness.ValidateInteractiveParameters(
                expectedEmbeddedWebView: WebViewPreference.System, // If system webview options are set, force usage of system webview
                browserOptions: options);
        }
        public async Task TestAcquireTokenInteractive_ParentWindow_WithCallbackFuncAndAcquireTokenBuilder_Async()
        {
            IntPtr parentWindowIntPtrFromCallback = new IntPtr(12345);
            IntPtr parentWindowIntPtrSpecific     = new IntPtr(98765);

            await AcquireTokenInteractiveParameterBuilder.Create(_harness.Executor, TestConstants.s_scope)
            .WithParentActivityOrWindowFunc(() => parentWindowIntPtrFromCallback)
            .WithParentActivityOrWindow(parentWindowIntPtrSpecific)
            .ExecuteAsync()
            .ConfigureAwait(false);

            Assert.AreEqual(parentWindowIntPtrSpecific, _harness.InteractiveParametersReceived.UiParent.OwnerWindow);
        }
        public async Task TestAcquireTokenInteractiveBuilderWithAccountAsync()
        {
            var account = Substitute.For <IAccount>();

            account.Username.Returns(MsalTestConstants.DisplayableId);

            await AcquireTokenInteractiveParameterBuilder.Create(_harness.Executor, MsalTestConstants.Scope)
            .WithAccount(account)
            .ExecuteAsync()
            .ConfigureAwait(false);

            _harness.ValidateCommonParameters(ApiEvent.ApiIds.AcquireTokenInteractive);
            _harness.ValidateInteractiveParameters(account, expectedLoginHint: MsalTestConstants.DisplayableId);
        }
        public async Task TestAcquireTokenInteractiveBuilderWithPromptAndExtraQueryParametersAsync()
        {
            await AcquireTokenInteractiveParameterBuilder.Create(_harness.Executor, MsalTestConstants.Scope)
            .WithLoginHint(MsalTestConstants.DisplayableId)
            .WithExtraQueryParameters("domain_hint=mydomain.com")
            .ExecuteAsync()
            .ConfigureAwait(false);

            _harness.ValidateCommonParameters(
                ApiEvent.ApiIds.AcquireTokenInteractive,
                expectedExtraQueryParameters: new Dictionary <string, string> {
                { "domain_hint", "mydomain.com" }
            });
            _harness.ValidateInteractiveParameters(
                expectedLoginHint: MsalTestConstants.DisplayableId);
        }
        public async Task TestAcquireTokenInteractive_EmbeddedAndSystemOptions_Async()
        {
            var options = new SystemWebViewOptions();
            var ex      = await AssertException.TaskThrowsAsync <MsalClientException>(() =>

                                                                                      AcquireTokenInteractiveParameterBuilder.Create(_harness.Executor, MsalTestConstants.Scope)
                                                                                      .WithSystemWebViewOptions(options)
                                                                                      .WithUseEmbeddedWebView(true)
                                                                                      .ExecuteAsync()
                                                                                      ).ConfigureAwait(false);

            Assert.AreEqual(MsalError.SystemWebviewOptionsNotApplicable, ex.ErrorCode);
        }