Tests: show a more meaningful exception when running for 1st time

Instead of throwing a System.FormatException, capture the URL
thrown by the library itself so that the developer configures
the API_ID and API_HASH and places them in the app.config file.
This commit is contained in:
Andres G. Aragoneses 2016-10-23 23:23:10 +08:00
parent 96c63b3f66
commit 0e32291d11
2 changed files with 40 additions and 13 deletions

View file

@ -35,11 +35,11 @@ namespace TLSharp.Core
TLContext.Init();
_apiHash = apiHash;
_apiId = apiId;
if (_apiId == 0)
throw new InvalidOperationException("Your API_ID is invalid. Do a configuration first https://github.com/sochix/TLSharp#quick-configuration");
if (_apiId == default(int))
throw new MissingApiConfigurationException("API_ID");
if (string.IsNullOrEmpty(_apiHash))
throw new InvalidOperationException("Your API_ID is invalid. Do a configuration first https://github.com/sochix/TLSharp#quick-configuration");
throw new MissingApiConfigurationException("API_HASH");
_session = Session.TryLoadOrCreateNew(store, sessionUserId);
_transport = new TcpTransport(_session.ServerAddress, _session.Port);
}
@ -250,6 +250,15 @@ namespace TLSharp.Core
_session.Save();
}
}
public class MissingApiConfigurationException : Exception
{
public const string InfoUrl = "https://github.com/sochix/TLSharp#quick-configuration";
internal MissingApiConfigurationException(string invalidParamName):
base($"Your {invalidParamName} setting is missing. Adjust the configuration first, see {InfoUrl}")
{
}
}
}