本文整理汇总了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");
}