本文整理汇总了C#中Session.LogOn方法的典型用法代码示例。如果您正苦于以下问题:C# Session.LogOn方法的具体用法?C# Session.LogOn怎么用?C# Session.LogOn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Session
的用法示例。
在下文中一共展示了Session.LogOn方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestAlreadyLoggedOn
public async void TestAlreadyLoggedOn()
{
var session = new Session(BasicServerConnectionMock);
await session.LogOn(BasicAuthenticationMock);
Assert.IsNotNull(session.UserInfo);
await AssertEx.ThrowsAsync<InvalidOperationException>(async () => await session.LogOn(BasicAuthenticationMock));
}
示例2: TestLogOffSuccess
public async void TestLogOffSuccess()
{
var session = new Session(BasicServerConnectionMock);
Assert.IsNull(session.UserInfo);
await session.LogOn(BasicAuthenticationMock);
Assert.IsNotNull(session.UserInfo);
session.LogOff();
Assert.IsNull(session.UserInfo);
}
示例3: TestLogOnFailure_Exception
public async void TestLogOnFailure_Exception()
{
var authenticationMock = new Mock<IAuthentication>();
authenticationMock.Setup(a => a.Authenticate()).Throws(new Exception("Test failure."));
var session = new Session(BasicServerConnectionMock);
Assert.IsNull(session.UserInfo);
var ex = await AssertEx.ThrowsAsync<Exception>(async () => await session.LogOn(authenticationMock.Object));
Assert.AreEqual("Test failure.", ex.Message);
Assert.IsNull(session.UserInfo);
}
示例4: TestLogOnSuccess
public async void TestLogOnSuccess()
{
var session = new Session(BasicServerConnectionMock);
Assert.IsNull(session.UserInfo);
await session.LogOn(BasicAuthenticationMock);
Assert.IsNotNull(session.UserInfo);
Assert.IsNotEmpty(session.UserInfo.AccessToken);
Assert.IsNotEmpty(session.UserInfo.RefreshToken);
Assert.IsNotEmpty(session.UserInfo.Username);
Assert.AreNotEqual(0, session.UserInfo.ExpiresIn);
Assert.AreNotEqual(0, session.UserInfo.UserId);
}
示例5: TestChangeSessionStateWhenLoggingOn
public async void TestChangeSessionStateWhenLoggingOn()
{
var authenticationMock = new Mock<IAuthentication>();
var signal = new ManualResetEvent(false);
authenticationMock.Setup(a => a.Authenticate()).Returns(Task.Run(() =>
{
signal.WaitOne();
return Task.FromResult(UserInfoExample);
}));
var session = new Session(BasicServerConnectionMock);
Assert.IsNull(session.UserInfo);
var task = session.LogOn(authenticationMock.Object);
await AssertEx.ThrowsAsync<InvalidOperationException>(async () => await session.LogOn(authenticationMock.Object));
Assert.Throws<InvalidOperationException>(() => session.LogOff());
Assert.IsNull(session.UserInfo);
signal.Set();
await task;
Assert.IsNotNull(session.UserInfo);
}
示例6: TestNullUserInfoNotAllowed
public async void TestNullUserInfoNotAllowed()
{
var session = new Session(new Mock<IServerConnection>().Object);
var ex = await AssertEx.ThrowsAsync<Exception>(async () => await session.LogOn(new Mock<IAuthentication>().Object));
Assert.IsTrue(ex.Message.Contains("not allowed"));
}