Merge pull request #277 from knocte/friendlerAuthTestFailures

Friendlier exceptions for Auth testing
This commit is contained in:
Ilya Pirozhenko 2016-10-31 11:12:36 +03:00 committed by GitHub
commit 24a9ea1ed9
4 changed files with 32 additions and 2 deletions

View file

@ -293,6 +293,10 @@ namespace TLSharp.Core.Network
var dcIdx = int.Parse(resultString); var dcIdx = int.Parse(resultString);
throw new UserMigrationException(dcIdx); throw new UserMigrationException(dcIdx);
} }
else if (errorMessage == "PHONE_CODE_INVALID")
{
throw new InvalidPhoneCodeException("The numeric code used to authenticate does not match the numeric code sent by SMS/Telegram");
}
else else
{ {
throw new InvalidOperationException(errorMessage); throw new InvalidOperationException(errorMessage);

View file

@ -310,4 +310,9 @@ namespace TLSharp.Core
{ {
} }
} }
public class InvalidPhoneCodeException : Exception
{
internal InvalidPhoneCodeException(string msg) : base(msg) { }
}
} }

View file

@ -24,6 +24,8 @@ namespace TLSharp.Tests
private string NumberToAuthenticate { get; set; } private string NumberToAuthenticate { get; set; }
private string CodeToAuthenticate { get; set; }
private string NotRegisteredNumberToSignUp { get; set; } private string NotRegisteredNumberToSignUp { get; set; }
private string UserNameToSendMessage { get; set; } private string UserNameToSendMessage { get; set; }
@ -72,6 +74,10 @@ namespace TLSharp.Tests
if (string.IsNullOrEmpty(NumberToAuthenticate)) if (string.IsNullOrEmpty(NumberToAuthenticate))
Debug.WriteLine("NumberToAuthenticate not configured in app.config! Some tests may fail."); 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)]; NotRegisteredNumberToSignUp = ConfigurationManager.AppSettings[nameof(NotRegisteredNumberToSignUp)];
if (string.IsNullOrEmpty(NotRegisteredNumberToSignUp)) if (string.IsNullOrEmpty(NotRegisteredNumberToSignUp))
Debug.WriteLine("NotRegisteredNumberToSignUp not configured in app.config! Some tests may fail."); Debug.WriteLine("NotRegisteredNumberToSignUp not configured in app.config! Some tests may fail.");
@ -101,9 +107,23 @@ namespace TLSharp.Tests
await client.ConnectAsync(); await client.ConnectAsync();
var hash = await client.SendCodeRequestAsync(NumberToAuthenticate); 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.IsNotNull(user);
Assert.IsTrue(client.IsUserAuthorized()); Assert.IsTrue(client.IsUserAuthorized());

View file

@ -4,6 +4,7 @@
<add key="ApiHash" value="" /> <add key="ApiHash" value="" />
<add key="ApiId" value="" /> <add key="ApiId" value="" />
<add key="NumberToAuthenticate" value="" /> <add key="NumberToAuthenticate" value="" />
<add key="CodeToAuthenticate" value="" />
<add key="NotRegisteredNumberToSignUp" value=""/> <add key="NotRegisteredNumberToSignUp" value=""/>
<add key="NumberToSendMessage" value=""/> <add key="NumberToSendMessage" value=""/>
<add key="UserNameToSendMessage" value=""/> <add key="UserNameToSendMessage" value=""/>