当前位置: 首页>>代码示例>>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;未经允许,请勿转载。