mirror of
https://github.com/sochix/TLSharp.git
synced 2026-04-05 14:37:04 +00:00
Friendlier exceptions for Auth testing
This change also lets you write the auth code in the app.config file without the need to recompile/debug.
This commit is contained in:
parent
b0b58be25e
commit
f062c0a7a1
4 changed files with 32 additions and 2 deletions
|
|
@ -24,6 +24,8 @@ namespace TLSharp.Tests
|
|||
|
||||
private string NumberToAuthenticate { get; set; }
|
||||
|
||||
private string CodeToAuthenticate { get; set; }
|
||||
|
||||
private string NotRegisteredNumberToSignUp { get; set; }
|
||||
|
||||
private string UserNameToSendMessage { get; set; }
|
||||
|
|
@ -72,6 +74,10 @@ namespace TLSharp.Tests
|
|||
if (string.IsNullOrEmpty(NumberToAuthenticate))
|
||||
Debug.WriteLine("NumberToAuthenticate not configured in app.config! Some tests may fail.");
|
||||
|
||||
CodeToAuthenticate = ConfigurationManager.AppSettings[nameof(CodeToAuthenticate)];
|
||||
if (string.IsNullOrEmpty(CodeToAuthenticate))
|
||||
Debug.WriteLine("CpdeToAuthenticate not configured in app.config! Some tests may fail.");
|
||||
|
||||
NotRegisteredNumberToSignUp = ConfigurationManager.AppSettings[nameof(NotRegisteredNumberToSignUp)];
|
||||
if (string.IsNullOrEmpty(NotRegisteredNumberToSignUp))
|
||||
Debug.WriteLine("NotRegisteredNumberToSignUp not configured in app.config! Some tests may fail.");
|
||||
|
|
@ -101,9 +107,23 @@ namespace TLSharp.Tests
|
|||
await client.ConnectAsync();
|
||||
|
||||
var hash = await client.SendCodeRequestAsync(NumberToAuthenticate);
|
||||
var code = "93463"; // you can change code in debugger
|
||||
var code = CodeToAuthenticate; // you can change code in debugger too
|
||||
|
||||
var user = await client.MakeAuthAsync(NumberToAuthenticate, hash, code);
|
||||
if (String.IsNullOrWhiteSpace(code))
|
||||
{
|
||||
throw new Exception("CodeToAuthenticate is empty in the app.config file, fill it with the code you just got now by SMS/Telegram");
|
||||
}
|
||||
|
||||
TLUser user = null;
|
||||
try
|
||||
{
|
||||
user = await client.MakeAuthAsync(NumberToAuthenticate, hash, code);
|
||||
}
|
||||
catch (InvalidPhoneCodeException ex)
|
||||
{
|
||||
throw new Exception("CodeToAuthenticate is wrong in the app.config file, fill it with the code you just got now by SMS/Telegram",
|
||||
ex);
|
||||
}
|
||||
|
||||
Assert.IsNotNull(user);
|
||||
Assert.IsTrue(client.IsUserAuthorized());
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
<add key="ApiHash" value="" />
|
||||
<add key="ApiId" value="" />
|
||||
<add key="NumberToAuthenticate" value="" />
|
||||
<add key="CodeToAuthenticate" value="" />
|
||||
<add key="NotRegisteredNumberToSignUp" value=""/>
|
||||
<add key="NumberToSendMessage" value=""/>
|
||||
<add key="UserNameToSendMessage" value=""/>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue