예제 #1
0
        public async Task SignIn_WithScopes_CallsMsalSignIn()
        {
            var msal = new Mock <IMsal>();

            var provider = new MsalAuthenticationStateProvider(msal.Object);

            var scopes = new string[0];
            await provider.SignInAsync(scopes);

            msal.Verify(x => x.SignInAsync(scopes));
        }
예제 #2
0
        public async Task SignIn_WithoutSuccess_DoesntRaiseAuthenticationChanged()
        {
            var msal = new Mock <IMsal>();

            var provider = new MsalAuthenticationStateProvider(msal.Object);

            bool eventRaised = false;

            provider.AuthenticationStateChanged += s =>
            {
                eventRaised = true;
            };

            await provider.SignInAsync();

            Assert.False(eventRaised);
        }
예제 #3
0
        public async Task SignIn_WithSuccess_RaisesAuthenticationChanged()
        {
            var account = new MsalAccount()
            {
                Name              = "Des",
                Username          = "******",
                AccountIdentifier = "123"
            };

            var msal = new Mock <IMsal>();

            msal.SetupSequence(x => x.GetAccountAsync())
            // first call returns null
            .Returns(Task.FromResult <MsalAccount>(null))
            // second and third calls returns account
            .Returns(Task.FromResult(account))
            .Returns(Task.FromResult(account));

            var provider = new MsalAuthenticationStateProvider(msal.Object);

            bool eventRaised = false;
            Task <AuthenticationState> stateAwaiter = null;

            provider.AuthenticationStateChanged += s =>
            {
                eventRaised  = true;
                stateAwaiter = s;
            };

            await provider.SignInAsync();

            Assert.True(eventRaised);
            Assert.NotNull(stateAwaiter);
            var state = await stateAwaiter;

            Assert.Equal(account.Username, state.User.Identity.Name);
        }