當前位置: 首頁>>代碼示例>>C#>>正文


C# AuthenticationService.LogoutAsync方法代碼示例

本文整理匯總了C#中AuthenticationService.LogoutAsync方法的典型用法代碼示例。如果您正苦於以下問題:C# AuthenticationService.LogoutAsync方法的具體用法?C# AuthenticationService.LogoutAsync怎麽用?C# AuthenticationService.LogoutAsync使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在AuthenticationService的用法示例。


在下文中一共展示了AuthenticationService.LogoutAsync方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ShouldLoginLogout

        public async Task ShouldLoginLogout()
        {
            bool principalChangedFired = false;
            bool loggedInFired = false;
            bool loggedOutFired = false;
            bool managerCreatedFired = false;

            var auth = new AuthenticationService();
            CompositionContext contextWithAuthService = CompositionContext.Fake
                .WithGenerator(typeof(IAuthenticationService), () => auth)
                .WithName("ShouldLoginLogout");
            CompositionContextResolver.Add(contextWithAuthService);
            var connectionOptions =
                ConnectionOptions.Default.WithCompositionContext("ShouldLoginLogout").WithName("ShouldLoginLogout");
            ConnectionOptionsResolver.Add(connectionOptions);
            var emp = new EntityManagerProvider<NorthwindIBEntities>()
                .Configure(provider => provider.WithConnectionOptions("ShouldLoginLogout"));

            auth.PrincipalChanged += (s, e) => principalChangedFired = true;
            auth.LoggedIn += (s, e) => loggedInFired = true;
            auth.LoggedOut += (s, e) => loggedOutFired = true;

            emp.ManagerCreated += (s, e) => managerCreatedFired = true;
            NorthwindIBEntities manager = null;

            await InitFakeBackingStoreAsync("ShouldLoginLogout");
            await auth.LoginAsync(new LoginCredential("test", "test", null));

            Assert.IsTrue(principalChangedFired, "PrincipalChanged should have been fired");
            Assert.IsTrue(loggedInFired, "LoggedIn should have been fired");
            Assert.IsFalse(loggedOutFired, "LoggedOut shouldn't have been fired");
            Assert.IsTrue(auth.IsLoggedIn, "Should be logged in");
            Assert.IsTrue(auth.Principal.Identity.Name == "test", "Username should be test");

            manager = emp.Manager;

            Assert.IsTrue(managerCreatedFired, "ManagerCreated should have been fired");
            Assert.IsNotNull(manager.AuthenticationContext.Principal,
                            "The principal should not be null on the EntitiyManager");
            Assert.IsTrue(manager.AuthenticationContext.Principal.Identity.Name == "test",
                            "Principal should have the same username");

            principalChangedFired = false;
            loggedInFired = false;
            managerCreatedFired = false;

            await auth.LogoutAsync();

            Assert.IsTrue(principalChangedFired,
                          "PrincipalChanged should have been fired");
            Assert.IsFalse(loggedInFired,
                           "LoggedIn shouldn't have been fired");
            Assert.IsTrue(loggedOutFired, "LoggedOut should have been fired");
            Assert.IsFalse(auth.IsLoggedIn, "Should be logged out");
            Assert.IsNull(auth.Principal, "Principal should be null");

            Assert.IsFalse(manager.IsConnected,
                           "Old EntityManager should be disconnected");

            bool exceptionThrown = false;
            try
            {
                await manager.Customers.ExecuteAsync();
            }
            catch (InvalidOperationException)
            {
                exceptionThrown = true;
            }
            Assert.IsTrue(exceptionThrown, "Should have thrown an error");

            manager = emp.Manager;
            Assert.IsTrue(managerCreatedFired,
                          "ManagerCreated should have been fired");
            Assert.IsNull(manager.AuthenticationContext.Principal,
                          "The principal should be null on the EntitiyManager");

        }
開發者ID:IdeaBlade,項目名稱:Punch,代碼行數:77,代碼來源:OnlineUnitTests.cs


注:本文中的AuthenticationService.LogoutAsync方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。