get apiHash and apiId in the constructor

This commit is contained in:
ahmadali shafiee 2016-04-18 15:35:30 +04:30
parent 504b63a6d7
commit 4a44709150
2 changed files with 18 additions and 12 deletions

View file

@ -18,13 +18,15 @@ namespace TLSharp.Core
private MtProtoSender _sender;
private AuthKey _key;
private TcpTransport _transport;
private string _apiHash = "a2514f96431a228e4b9ee473f6c51945";
private int _apiId = 19474;
private string _apiHash = "";
private int _apiId = 0;
private Session _session;
private List<DcOption> dcOptions;
public TelegramClient(ISessionStore store, string sessionUserId)
public TelegramClient(ISessionStore store, string sessionUserId, string apiHash, int apiId)
{
_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");

View file

@ -19,6 +19,10 @@ namespace TLSharp.Tests
private string UserNameToSendMessage { get; set; }
private string apiHash = "";
private int apiId = 0;
[TestInitialize]
public void Init()
{
@ -41,7 +45,7 @@ namespace TLSharp.Tests
public async Task AuthUser()
{
var store = new FileSessionStore();
var client = new TelegramClient(store, "session");
var client = new TelegramClient(store, "session", apiHash, apiId);
await client.Connect();
@ -57,7 +61,7 @@ namespace TLSharp.Tests
public async Task CheckPhones()
{
var store = new FileSessionStore();
var client = new TelegramClient(store, "session");
var client = new TelegramClient(store, "session", apiHash, apiId);
await client.Connect();
var result = await client.IsPhoneRegistered(NumberToAuthenticate);
@ -70,7 +74,7 @@ namespace TLSharp.Tests
// User should be already authenticated!
var store = new FileSessionStore();
var client = new TelegramClient(store, "session");
var client = new TelegramClient(store, "session", apiHash, apiId);
await client.Connect();
@ -85,7 +89,7 @@ namespace TLSharp.Tests
public async Task ImportByUserName()
{
var store = new FileSessionStore();
var client = new TelegramClient(store, "session");
var client = new TelegramClient(store, "session", apiHash, apiId);
await client.Connect();
@ -100,7 +104,7 @@ namespace TLSharp.Tests
public async Task ImportByUserNameAndSendMessage()
{
var store = new FileSessionStore();
var client = new TelegramClient(store, "session");
var client = new TelegramClient(store, "session", apiHash, apiId);
await client.Connect();
@ -119,7 +123,7 @@ namespace TLSharp.Tests
// User should be already authenticated!
var store = new FileSessionStore();
var client = new TelegramClient(store, "session");
var client = new TelegramClient(store, "session", apiHash, apiId);
await client.Connect();
Assert.IsTrue(client.IsUserAuthorized());
@ -135,7 +139,7 @@ namespace TLSharp.Tests
public async Task GetHistory()
{
var store = new FileSessionStore();
var client = new TelegramClient(store, "session");
var client = new TelegramClient(store, "session", apiHash, apiId);
await client.Connect();
Assert.IsTrue(client.IsUserAuthorized());
@ -153,7 +157,7 @@ namespace TLSharp.Tests
public async Task UploadAndSendMedia()
{
var store = new FileSessionStore();
var client = new TelegramClient(store, "session");
var client = new TelegramClient(store, "session", apiHash, apiId);
await client.Connect();
Assert.IsTrue(client.IsUserAuthorized());
@ -178,7 +182,7 @@ namespace TLSharp.Tests
public async Task TestConnection()
{
var store = new FakeSessionStore();
var client = new TelegramClient(store, "");
var client = new TelegramClient(store, "", apiHash, apiId);
Assert.IsTrue(await client.Connect());
}