Example #1
0
        public async Task GetAuthenticationState_WithNullAccount_ReturnsNotAuthenticated()
        {
            var msal = new Mock <IMsal>();

            var provider = new MsalAuthenticationStateProvider(msal.Object);

            var state = await provider.GetAuthenticationStateAsync();

            Assert.False(state.User.Identity.IsAuthenticated);
        }
Example #2
0
        public async Task GetAuthenticationState_WithAccount_ReturnsAuthenticated()
        {
            var account = new MsalAccount()
            {
                Name              = "Des",
                Username          = "******",
                AccountIdentifier = "123"
            };

            var msal = new Mock <IMsal>();

            msal.Setup(x => x.GetAccountAsync())
            .Returns(Task.FromResult(account));

            var provider = new MsalAuthenticationStateProvider(msal.Object);

            var state = await provider.GetAuthenticationStateAsync();

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