private async Task RunPluginSelectionTestAsync(string inputAuthority, bool expectMsaPlugin) { // Arrange using (var harness = CreateTestHarness()) { _webAccountProviderFactory.ClearReceivedCalls(); var acc = new WebAccountProvider("id", "*****@*****.**", null); var requestParams = harness.CreateAuthenticationRequestParameters(inputAuthority); requestParams.Account = new Account( $"{TestConstants.Uid}.{TestConstants.Utid}", TestConstants.DisplayableId, null); var atsParams = new AcquireTokenSilentParameters(); _webAccountProviderFactory.GetAccountProviderAsync(null).ReturnsForAnyArgs(Task.FromResult(acc)); // Act var ex = await AssertException.TaskThrowsAsync <MsalUiRequiredException>( () => _wamBroker.AcquireTokenSilentAsync(requestParams, atsParams)).ConfigureAwait(false); // Assert Assert.AreEqual(MsalError.InteractionRequired, ex.ErrorCode); if (expectMsaPlugin) { await _webAccountProviderFactory.Received(1).GetAccountProviderAsync("consumers").ConfigureAwait(false); } else { await _webAccountProviderFactory.Received(1).GetAccountProviderAsync(inputAuthority).ConfigureAwait(false); } } }
public void TestDefaultAccountPluginSelection() { _webAccountProviderFactory.IsDefaultAccountMsaAsync().Returns(true); Assert.IsTrue( _wamBroker.IsMsaRequestAsync(Authority.CreateAuthority(TestConstants.AuthorityCommonTenant), null, false).Result, "Common authority with no account - use Windows default account"); _webAccountProviderFactory.Received(1).IsDefaultAccountMsaAsync(); _webAccountProviderFactory.IsDefaultAccountMsaAsync().Returns(false); Assert.IsFalse( _wamBroker.IsMsaRequestAsync(Authority.CreateAuthority(TestConstants.AuthorityCommonTenant), null, false).Result, "Common authority with no account - use Windows default account"); _webAccountProviderFactory.Received(2).IsDefaultAccountMsaAsync(); }